Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,15 @@
|
|
1 |
import gradio as gr
|
2 |
-
from datetime import date, timedelta
|
3 |
from config import index_options, time_intervals, START_DATE, END_DATE, FORECAST_PERIOD
|
4 |
from data_fetcher import get_stocks_from_index
|
5 |
from stock_analysis import get_stock_graph_and_info
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
demo = gr.Blocks()
|
8 |
|
9 |
with demo:
|
@@ -13,9 +19,9 @@ with demo:
|
|
13 |
d4 = gr.Radio(['Line Graph', 'Candlestick Graph'], label='Select Graph Type', value='Line Graph', interactive=True)
|
14 |
d5 = gr.Dropdown(['ARIMA', 'Prophet', 'LSTM'], label='Select Forecasting Method', value='ARIMA', interactive=True)
|
15 |
|
16 |
-
# New date inputs
|
17 |
-
date_start = gr.
|
18 |
-
date_end = gr.
|
19 |
|
20 |
out_graph = gr.Plot()
|
21 |
out_fundamentals = gr.DataFrame()
|
@@ -27,13 +33,27 @@ with demo:
|
|
27 |
stocks = get_stocks_from_index(index)
|
28 |
return gr.Dropdown(choices=stocks)
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
d1.change(update_stock_options, d1, d2)
|
31 |
-
d2.change(
|
32 |
-
d3.change(
|
33 |
-
d4.change(
|
34 |
-
d5.change(
|
35 |
-
date_start.change(
|
36 |
-
date_end.change(
|
37 |
|
38 |
if __name__ == "__main__":
|
39 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from datetime import datetime, date, timedelta
|
3 |
from config import index_options, time_intervals, START_DATE, END_DATE, FORECAST_PERIOD
|
4 |
from data_fetcher import get_stocks_from_index
|
5 |
from stock_analysis import get_stock_graph_and_info
|
6 |
|
7 |
+
def validate_date(date_string):
|
8 |
+
try:
|
9 |
+
return datetime.strptime(date_string, "%Y-%m-%d").date()
|
10 |
+
except ValueError:
|
11 |
+
return None
|
12 |
+
|
13 |
demo = gr.Blocks()
|
14 |
|
15 |
with demo:
|
|
|
19 |
d4 = gr.Radio(['Line Graph', 'Candlestick Graph'], label='Select Graph Type', value='Line Graph', interactive=True)
|
20 |
d5 = gr.Dropdown(['ARIMA', 'Prophet', 'LSTM'], label='Select Forecasting Method', value='ARIMA', interactive=True)
|
21 |
|
22 |
+
# New date inputs using Textbox
|
23 |
+
date_start = gr.Textbox(label="Start Date (YYYY-MM-DD)", value=START_DATE.strftime("%Y-%m-%d"))
|
24 |
+
date_end = gr.Textbox(label="End Date (YYYY-MM-DD)", value=END_DATE.strftime("%Y-%m-%d"))
|
25 |
|
26 |
out_graph = gr.Plot()
|
27 |
out_fundamentals = gr.DataFrame()
|
|
|
33 |
stocks = get_stocks_from_index(index)
|
34 |
return gr.Dropdown(choices=stocks)
|
35 |
|
36 |
+
def process_inputs(*args):
|
37 |
+
idx, stock, interval, graph_type, forecast_method, start_date, end_date = args
|
38 |
+
|
39 |
+
start = validate_date(start_date)
|
40 |
+
end = validate_date(end_date)
|
41 |
+
|
42 |
+
if start is None or end is None:
|
43 |
+
return gr.Textbox(value="Invalid date format. Please use YYYY-MM-DD."), None
|
44 |
+
|
45 |
+
if start > end:
|
46 |
+
return gr.Textbox(value="Start date must be before end date."), None
|
47 |
+
|
48 |
+
return get_stock_graph_and_info(idx, stock, interval, graph_type, forecast_method, start, end)
|
49 |
+
|
50 |
d1.change(update_stock_options, d1, d2)
|
51 |
+
d2.change(process_inputs, inputs, outputs)
|
52 |
+
d3.change(process_inputs, inputs, outputs)
|
53 |
+
d4.change(process_inputs, inputs, outputs)
|
54 |
+
d5.change(process_inputs, inputs, outputs)
|
55 |
+
date_start.change(process_inputs, inputs, outputs)
|
56 |
+
date_end.change(process_inputs, inputs, outputs)
|
57 |
|
58 |
if __name__ == "__main__":
|
59 |
demo.launch()
|