Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
from
|
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 |
|
@@ -19,7 +11,6 @@ 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 |
|
@@ -29,24 +20,6 @@ with demo:
|
|
29 |
inputs = [d1, d2, d3, d4, d5, date_start, date_end]
|
30 |
outputs = [out_graph, out_fundamentals]
|
31 |
|
32 |
-
def update_stock_options(index):
|
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)
|
|
|
1 |
import gradio as gr
|
2 |
+
from config import index_options, time_intervals, START_DATE, END_DATE
|
3 |
+
from app_utils import update_stock_options, process_inputs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
demo = gr.Blocks()
|
6 |
|
|
|
11 |
d4 = gr.Radio(['Line Graph', 'Candlestick Graph'], label='Select Graph Type', value='Line Graph', interactive=True)
|
12 |
d5 = gr.Dropdown(['ARIMA', 'Prophet', 'LSTM'], label='Select Forecasting Method', value='ARIMA', interactive=True)
|
13 |
|
|
|
14 |
date_start = gr.Textbox(label="Start Date (YYYY-MM-DD)", value=START_DATE.strftime("%Y-%m-%d"))
|
15 |
date_end = gr.Textbox(label="End Date (YYYY-MM-DD)", value=END_DATE.strftime("%Y-%m-%d"))
|
16 |
|
|
|
20 |
inputs = [d1, d2, d3, d4, d5, date_start, date_end]
|
21 |
outputs = [out_graph, out_fundamentals]
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
d1.change(update_stock_options, d1, d2)
|
24 |
d2.change(process_inputs, inputs, outputs)
|
25 |
d3.change(process_inputs, inputs, outputs)
|