Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,14 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
from
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
demo = gr.Blocks()
|
6 |
|
@@ -11,6 +19,7 @@ with demo:
|
|
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,6 +29,29 @@ with demo:
|
|
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)
|
|
|
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 |
|
|
|
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 |
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 "Invalid date format. Please use YYYY-MM-DD.", None
|
44 |
+
|
45 |
+
if start > end:
|
46 |
+
return "Start date must be before end date.", None
|
47 |
+
|
48 |
+
try:
|
49 |
+
fig, fundamentals = get_stock_graph_and_info(idx, stock, interval, graph_type, forecast_method, start, end)
|
50 |
+
return fig, fundamentals
|
51 |
+
except Exception as e:
|
52 |
+
error_message = f"An error occurred: {str(e)}"
|
53 |
+
return error_message, None
|
54 |
+
|
55 |
d1.change(update_stock_options, d1, d2)
|
56 |
d2.change(process_inputs, inputs, outputs)
|
57 |
d3.change(process_inputs, inputs, outputs)
|