Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -52,7 +52,7 @@ def stock_forecast(ticker, start_date, end_date):
|
|
52 |
inputs=df,
|
53 |
freq="D", # Daily frequency
|
54 |
value_name="y",
|
55 |
-
num_jobs
|
56 |
)
|
57 |
|
58 |
# Combine actual and forecasted data for plotting
|
@@ -62,8 +62,12 @@ def stock_forecast(ticker, start_date, end_date):
|
|
62 |
fig = px.line(combined_df, x='ds', y=['y', 'timesfm'], labels={'value': 'Price', 'ds': 'Date'},
|
63 |
title=f'{ticker} Stock Price Forecast')
|
64 |
|
65 |
-
#
|
66 |
fig.update_layout(
|
|
|
|
|
|
|
|
|
67 |
legend_title_text='Type',
|
68 |
hovermode='x unified', # Show hover info for all series at the same x-value
|
69 |
xaxis=dict(
|
@@ -74,12 +78,34 @@ def stock_forecast(ticker, start_date, end_date):
|
|
74 |
dict(count=1, label="YTD", step="year", stepmode="todate"),
|
75 |
dict(count=1, label="1y", step="year", stepmode="backward"),
|
76 |
dict(step="all")
|
77 |
-
])
|
|
|
|
|
78 |
),
|
79 |
rangeslider=dict(visible=True), # Add a range slider
|
80 |
-
type="date"
|
|
|
|
|
|
|
81 |
),
|
82 |
-
yaxis=dict(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
)
|
84 |
|
85 |
# Add custom hover data
|
@@ -93,10 +119,14 @@ def stock_forecast(ticker, start_date, end_date):
|
|
93 |
# Return an empty Plotly figure with an error message
|
94 |
error_fig = go.Figure()
|
95 |
error_fig.update_layout(
|
|
|
96 |
title=f"Error: {str(e)}",
|
97 |
xaxis_title="Date",
|
98 |
yaxis_title="Price",
|
99 |
-
annotations=[dict(text="No data available", x=0.5, y=0.5, showarrow=False)]
|
|
|
|
|
|
|
100 |
)
|
101 |
return error_fig
|
102 |
|
@@ -108,7 +138,7 @@ with gr.Blocks() as demo:
|
|
108 |
with gr.Row():
|
109 |
ticker_input = gr.Textbox(label="Enter Stock Ticker", value="AAPL")
|
110 |
start_date_input = gr.Textbox(label="Enter Start Date (YYYY-MM-DD)", value="2022-01-01")
|
111 |
-
end_date_input = gr.Textbox(label="Enter End Date (YYYY-MM-DD)", value="
|
112 |
|
113 |
submit_button = gr.Button("Enter")
|
114 |
plot_output = gr.Plot()
|
|
|
52 |
inputs=df,
|
53 |
freq="D", # Daily frequency
|
54 |
value_name="y",
|
55 |
+
num_jobs=2,
|
56 |
)
|
57 |
|
58 |
# Combine actual and forecasted data for plotting
|
|
|
62 |
fig = px.line(combined_df, x='ds', y=['y', 'timesfm'], labels={'value': 'Price', 'ds': 'Date'},
|
63 |
title=f'{ticker} Stock Price Forecast')
|
64 |
|
65 |
+
# Customize the plot for a dark theme
|
66 |
fig.update_layout(
|
67 |
+
template="plotly_dark", # Use a dark theme
|
68 |
+
plot_bgcolor='rgba(0, 0, 0, 0)', # Transparent plot background
|
69 |
+
paper_bgcolor='rgba(0, 0, 0, 0)', # Transparent paper background
|
70 |
+
font=dict(color='white'), # White font color
|
71 |
legend_title_text='Type',
|
72 |
hovermode='x unified', # Show hover info for all series at the same x-value
|
73 |
xaxis=dict(
|
|
|
78 |
dict(count=1, label="YTD", step="year", stepmode="todate"),
|
79 |
dict(count=1, label="1y", step="year", stepmode="backward"),
|
80 |
dict(step="all")
|
81 |
+
]),
|
82 |
+
bgcolor='black', # Dark background for range selector
|
83 |
+
font=dict(color='white') # White font for range selector
|
84 |
),
|
85 |
rangeslider=dict(visible=True), # Add a range slider
|
86 |
+
type="date",
|
87 |
+
gridcolor='gray', # Grid lines color
|
88 |
+
linecolor='gray', # Axis line color
|
89 |
+
tickfont=dict(color='white') # White tick labels
|
90 |
),
|
91 |
+
yaxis=dict(
|
92 |
+
title="Price (USD)",
|
93 |
+
gridcolor='gray', # Grid lines color
|
94 |
+
linecolor='gray', # Axis line color
|
95 |
+
tickfont=dict(color='white') # White tick labels
|
96 |
+
)
|
97 |
+
)
|
98 |
+
|
99 |
+
# Customize line colors
|
100 |
+
fig.update_traces(
|
101 |
+
line=dict(width=2), # Thicker lines for better visibility
|
102 |
+
selector=dict(name='y'), # Actual prices
|
103 |
+
line_color='blue' # Blue for actual prices
|
104 |
+
)
|
105 |
+
fig.update_traces(
|
106 |
+
line=dict(width=2), # Thicker lines for better visibility
|
107 |
+
selector=dict(name='timesfm'), # Forecasted prices
|
108 |
+
line_color='purple' # Purple for forecasted prices
|
109 |
)
|
110 |
|
111 |
# Add custom hover data
|
|
|
119 |
# Return an empty Plotly figure with an error message
|
120 |
error_fig = go.Figure()
|
121 |
error_fig.update_layout(
|
122 |
+
template="plotly_dark", # Use a dark theme
|
123 |
title=f"Error: {str(e)}",
|
124 |
xaxis_title="Date",
|
125 |
yaxis_title="Price",
|
126 |
+
annotations=[dict(text="No data available", x=0.5, y=0.5, showarrow=False, font=dict(color='white'))],
|
127 |
+
plot_bgcolor='rgba(0, 0, 0, 0)', # Transparent plot background
|
128 |
+
paper_bgcolor='rgba(0, 0, 0, 0)', # Transparent paper background
|
129 |
+
font=dict(color='white') # White font color
|
130 |
)
|
131 |
return error_fig
|
132 |
|
|
|
138 |
with gr.Row():
|
139 |
ticker_input = gr.Textbox(label="Enter Stock Ticker", value="AAPL")
|
140 |
start_date_input = gr.Textbox(label="Enter Start Date (YYYY-MM-DD)", value="2022-01-01")
|
141 |
+
end_date_input = gr.Textbox(label="Enter End Date (YYYY-MM-DD)", value="2026-01-01")
|
142 |
|
143 |
submit_button = gr.Button("Enter")
|
144 |
plot_output = gr.Plot()
|