Fix Gradio date input and update README python version
Browse files
README.md
CHANGED
@@ -5,7 +5,7 @@ colorFrom: blue
|
|
5 |
colorTo: green
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.29.0 # Or check your installed version with pip show gradio
|
8 |
-
python_version: 3.10 # Corrected version
|
9 |
app_file: app.py
|
10 |
license: apache-2.0 # Or choose another license if preferred
|
11 |
---
|
|
|
5 |
colorTo: green
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.29.0 # Or check your installed version with pip show gradio
|
8 |
+
python_version: '3.10' # Corrected version
|
9 |
app_file: app.py
|
10 |
license: apache-2.0 # Or choose another license if preferred
|
11 |
---
|
app.py
CHANGED
@@ -208,14 +208,14 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
208 |
with gr.Row():
|
209 |
with gr.Column(scale=1):
|
210 |
ticker_input = gr.Textbox(label="Stock Ticker", value="AAPL", placeholder="e.g., AAPL, GOOGL")
|
211 |
-
|
212 |
-
|
|
|
213 |
analyze_button = gr.Button("Analyze", variant="primary")
|
214 |
status_output = gr.Textbox(label="Analysis Status", lines=5, interactive=False)
|
215 |
# Optional: Add download button for the merged data
|
216 |
download_data = gr.File(label="Download Merged Data (CSV)")
|
217 |
|
218 |
-
|
219 |
with gr.Column(scale=3):
|
220 |
plot_output = gr.Plot(label="Stock Price vs. Sentiment")
|
221 |
insights_output = gr.Markdown(label="Analysis & Insights")
|
@@ -224,9 +224,19 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
224 |
# Hidden state to store the merged dataframe for download
|
225 |
merged_df_state = gr.State(None)
|
226 |
|
227 |
-
|
|
|
228 |
"""Wrapper function to run analysis and prepare CSV for download."""
|
229 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
|
231 |
csv_path = None
|
232 |
if merged_df is not None and not merged_df.empty:
|
@@ -236,10 +246,9 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
236 |
|
237 |
return plot, insights, news, status, merged_df, csv_path # Return path for download
|
238 |
|
239 |
-
|
240 |
analyze_button.click(
|
241 |
fn=run_analysis_and_prepare_download,
|
242 |
-
inputs=[ticker_input, start_date_input, end_date_input],
|
243 |
outputs=[plot_output, insights_output, news_output, status_output, merged_df_state, download_data] # Update state and file output
|
244 |
)
|
245 |
|
|
|
208 |
with gr.Row():
|
209 |
with gr.Column(scale=1):
|
210 |
ticker_input = gr.Textbox(label="Stock Ticker", value="AAPL", placeholder="e.g., AAPL, GOOGL")
|
211 |
+
# Use Textbox for dates, value should be string
|
212 |
+
start_date_input = gr.Textbox(label="Start Date (YYYY-MM-DD)", value=(datetime.now() - timedelta(days=30)).strftime('%Y-%m-%d'))
|
213 |
+
end_date_input = gr.Textbox(label="End Date (YYYY-MM-DD)", value=datetime.now().strftime('%Y-%m-%d'))
|
214 |
analyze_button = gr.Button("Analyze", variant="primary")
|
215 |
status_output = gr.Textbox(label="Analysis Status", lines=5, interactive=False)
|
216 |
# Optional: Add download button for the merged data
|
217 |
download_data = gr.File(label="Download Merged Data (CSV)")
|
218 |
|
|
|
219 |
with gr.Column(scale=3):
|
220 |
plot_output = gr.Plot(label="Stock Price vs. Sentiment")
|
221 |
insights_output = gr.Markdown(label="Analysis & Insights")
|
|
|
224 |
# Hidden state to store the merged dataframe for download
|
225 |
merged_df_state = gr.State(None)
|
226 |
|
227 |
+
# Modify the wrapper function to accept strings and parse them
|
228 |
+
def run_analysis_and_prepare_download(ticker, start_date_str, end_date_str):
|
229 |
"""Wrapper function to run analysis and prepare CSV for download."""
|
230 |
+
try:
|
231 |
+
# Validate and parse date strings here before passing to perform_analysis
|
232 |
+
start_date_obj = datetime.strptime(start_date_str, '%Y-%m-%d').date()
|
233 |
+
end_date_obj = datetime.strptime(end_date_str, '%Y-%m-%d').date()
|
234 |
+
except ValueError:
|
235 |
+
# Handle invalid date format input from textbox
|
236 |
+
return None, "Error: Invalid date format. Please use YYYY-MM-DD.", None, "Error processing dates.", None, None
|
237 |
+
|
238 |
+
# Pass the original strings to perform_analysis, as it expects strings now
|
239 |
+
plot, insights, news, status, merged_df = perform_analysis(ticker, start_date_str, end_date_str)
|
240 |
|
241 |
csv_path = None
|
242 |
if merged_df is not None and not merged_df.empty:
|
|
|
246 |
|
247 |
return plot, insights, news, status, merged_df, csv_path # Return path for download
|
248 |
|
|
|
249 |
analyze_button.click(
|
250 |
fn=run_analysis_and_prepare_download,
|
251 |
+
inputs=[ticker_input, start_date_input, end_date_input], # Inputs are now textboxes
|
252 |
outputs=[plot_output, insights_output, news_output, status_output, merged_df_state, download_data] # Update state and file output
|
253 |
)
|
254 |
|