mistermprah commited on
Commit
926c2a5
1 Parent(s): 1b108a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -36
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  import numpy as np
3
  import pandas as pd
4
  import yfinance as yf
5
- from datetime import datetime, timedelta
6
  from tensorflow.keras.models import load_model
7
  from joblib import load
8
 
@@ -109,40 +109,28 @@ def display_historical_data(ticker):
109
  return str(e)
110
 
111
  # Set up Gradio interface
112
- ticker_input = gr.Dropdown(choices=stock_list, label="Stock Ticker")
113
-
114
- iface = gr.Interface(
115
- fn=predict_stock_price,
116
- inputs=[
117
- ticker_input,
118
- gr.Number(label="Open"),
119
- gr.Number(label="Close")
120
- ],
121
- outputs=gr.Textbox(),
122
- title="Stock Price Predictor",
123
- description="Select the stock ticker and input the last recorded values to predict the closing price using the LSTM model."
124
- )
125
-
126
- next_month_iface = gr.Interface(
127
- fn=predict_next_month_price,
128
- inputs=[ticker_input],
129
- outputs=gr.Textbox(),
130
- title="Next Month Stock Price Predictor",
131
- description="Select the stock ticker to predict the closing price for the next month using the LSTM model."
132
- )
133
-
134
- historical_data_iface = gr.Interface(
135
- fn=display_historical_data,
136
- inputs=[ticker_input],
137
- outputs=gr.Dataframe(),
138
- title="Historical Data Viewer",
139
- description="Select the stock ticker to view the historical data."
140
- )
141
-
142
- # Combine interfaces
143
- app = gr.TabbedInterface(
144
- interface_list=[iface, next_month_iface, historical_data_iface],
145
- tab_names=["Predict Today's Price", "Predict Next Month's Price", "View Historical Data"]
146
- )
147
 
148
  app.launch()
 
2
  import numpy as np
3
  import pandas as pd
4
  import yfinance as yf
5
+ from datetime import datetime
6
  from tensorflow.keras.models import load_model
7
  from joblib import load
8
 
 
109
  return str(e)
110
 
111
  # Set up Gradio interface
112
+ with gr.Blocks() as app:
113
+ with gr.Tab("Predict Today's Price"):
114
+ gr.Markdown("## Predict Today's Price")
115
+ ticker_input = gr.Dropdown(choices=stock_list, label="Stock Ticker")
116
+ open_price = gr.Number(label="Open")
117
+ close_price = gr.Number(label="Close")
118
+ predict_button = gr.Button("Predict")
119
+ predict_output = gr.Textbox()
120
+ predict_button.click(predict_stock_price, inputs=[ticker_input, open_price, close_price], outputs=predict_output)
121
+
122
+ with gr.Tab("Predict Next Month's Price"):
123
+ gr.Markdown("## Predict Next Month's Price")
124
+ next_month_ticker_input = gr.Dropdown(choices=stock_list, label="Stock Ticker")
125
+ next_month_predict_button = gr.Button("Predict")
126
+ next_month_predict_output = gr.Textbox()
127
+ next_month_predict_button.click(predict_next_month_price, inputs=[next_month_ticker_input], outputs=next_month_predict_output)
128
+
129
+ with gr.Tab("View Historical Data"):
130
+ gr.Markdown("## View Historical Data")
131
+ historical_ticker_input = gr.Dropdown(choices=stock_list, label="Stock Ticker")
132
+ historical_view_button = gr.Button("View Data")
133
+ historical_data_output = gr.Dataframe()
134
+ historical_view_button.click(display_historical_data, inputs=[historical_ticker_input], outputs=historical_data_output)
 
 
 
 
 
 
 
 
 
 
 
 
135
 
136
  app.launch()