Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,6 +15,10 @@ import pandas as pd
|
|
| 15 |
import numpy as np
|
| 16 |
from scipy import stats
|
| 17 |
import seaborn as sns
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
# Configure logging
|
| 20 |
logging.basicConfig(filename='debug.log', level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
|
@@ -266,13 +270,25 @@ def comprehensive_investment_strategy():
|
|
| 266 |
"""
|
| 267 |
return strategy
|
| 268 |
|
| 269 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
try:
|
| 271 |
logging.debug(f"Starting gradio_interface with tickers: {ticker1}, {ticker2}, {ticker3}, {ticker4}, start_date: {start_date}, end_date: {end_date}, query: {query}, analysis_type: {analysis_type}, interval: {interval}")
|
| 272 |
|
| 273 |
if analysis_type == 'Comprehensive Investment Strategy':
|
| 274 |
return comprehensive_investment_strategy(), None
|
| 275 |
|
|
|
|
|
|
|
|
|
|
| 276 |
tickers = [ticker.split(':')[0].strip() for ticker in [ticker1, ticker2, ticker3, ticker4] if ticker]
|
| 277 |
chart_paths = []
|
| 278 |
data_dict = {}
|
|
@@ -308,7 +324,6 @@ def gradio_interface(ticker1, ticker2, ticker3, ticker4, start_date, end_date, q
|
|
| 308 |
else:
|
| 309 |
return "At least two tickers are required for correlation analysis.", None
|
| 310 |
else:
|
| 311 |
-
|
| 312 |
# Single ticker analysis
|
| 313 |
if chart_paths:
|
| 314 |
insights = predict(Image.open(chart_paths[0]), query)
|
|
@@ -342,6 +357,8 @@ def gradio_app():
|
|
| 342 |
|
| 343 |
8. **Enhanced Image Processing**: The app adds financial metrics and annotations to the generated charts, ensuring clear presentation of data.
|
| 344 |
|
|
|
|
|
|
|
| 345 |
This tool leverages various analysis techniques to provide detailed insights into stock market trends, offering an interactive and educational experience for users.
|
| 346 |
""")
|
| 347 |
|
|
@@ -498,16 +515,17 @@ def gradio_app():
|
|
| 498 |
|
| 499 |
with gr.Row():
|
| 500 |
indicators = gr.CheckboxGroup(label="Indicators", choices=['RSI', 'SMA21', 'SMA50', 'SMA200', 'VWAP', 'Bollinger Bands'], value=['SMA21', 'SMA50'])
|
| 501 |
-
analysis_type = gr.Radio(label="Analysis Type", choices=['Single Ticker', 'Comparative Analysis', 'Trend Analysis', 'Correlation Analysis', 'Comprehensive Investment Strategy'], value='Single Ticker')
|
| 502 |
|
| 503 |
query = gr.Textbox(label="Analysis Query", value="Analyze the price trends.")
|
|
|
|
| 504 |
analyze_button = gr.Button("Analyze")
|
| 505 |
output_image = gr.Image(label="Analysis Chart")
|
| 506 |
output_text = gr.Textbox(label="Generated Insights", lines=10)
|
| 507 |
|
| 508 |
analyze_button.click(
|
| 509 |
fn=gradio_interface,
|
| 510 |
-
inputs=[ticker1, ticker2, ticker3, ticker4, start_date, end_date, query, analysis_type, interval, indicators],
|
| 511 |
outputs=[output_text, output_image]
|
| 512 |
)
|
| 513 |
|
|
|
|
| 15 |
import numpy as np
|
| 16 |
from scipy import stats
|
| 17 |
import seaborn as sns
|
| 18 |
+
import base64
|
| 19 |
+
from io import BytesIO
|
| 20 |
+
|
| 21 |
+
|
| 22 |
|
| 23 |
# Configure logging
|
| 24 |
logging.basicConfig(filename='debug.log', level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
|
|
|
| 270 |
"""
|
| 271 |
return strategy
|
| 272 |
|
| 273 |
+
def analyze_uploaded_image(image, query):
|
| 274 |
+
try:
|
| 275 |
+
logging.debug(f"Analyzing uploaded image with query: {query}")
|
| 276 |
+
insights = predict(image, query)
|
| 277 |
+
return insights, image
|
| 278 |
+
except Exception as e:
|
| 279 |
+
logging.error(f"Error analyzing uploaded image: {e}")
|
| 280 |
+
return f"Error analyzing uploaded image: {e}", None
|
| 281 |
+
|
| 282 |
+
def gradio_interface(ticker1, ticker2, ticker3, ticker4, start_date, end_date, query, analysis_type, interval, indicators, uploaded_image):
|
| 283 |
try:
|
| 284 |
logging.debug(f"Starting gradio_interface with tickers: {ticker1}, {ticker2}, {ticker3}, {ticker4}, start_date: {start_date}, end_date: {end_date}, query: {query}, analysis_type: {analysis_type}, interval: {interval}")
|
| 285 |
|
| 286 |
if analysis_type == 'Comprehensive Investment Strategy':
|
| 287 |
return comprehensive_investment_strategy(), None
|
| 288 |
|
| 289 |
+
if uploaded_image is not None:
|
| 290 |
+
return analyze_uploaded_image(uploaded_image, query)
|
| 291 |
+
|
| 292 |
tickers = [ticker.split(':')[0].strip() for ticker in [ticker1, ticker2, ticker3, ticker4] if ticker]
|
| 293 |
chart_paths = []
|
| 294 |
data_dict = {}
|
|
|
|
| 324 |
else:
|
| 325 |
return "At least two tickers are required for correlation analysis.", None
|
| 326 |
else:
|
|
|
|
| 327 |
# Single ticker analysis
|
| 328 |
if chart_paths:
|
| 329 |
insights = predict(Image.open(chart_paths[0]), query)
|
|
|
|
| 357 |
|
| 358 |
8. **Enhanced Image Processing**: The app adds financial metrics and annotations to the generated charts, ensuring clear presentation of data.
|
| 359 |
|
| 360 |
+
9. **Custom Chart Analysis**: Users can upload their own chart images for analysis.
|
| 361 |
+
|
| 362 |
This tool leverages various analysis techniques to provide detailed insights into stock market trends, offering an interactive and educational experience for users.
|
| 363 |
""")
|
| 364 |
|
|
|
|
| 515 |
|
| 516 |
with gr.Row():
|
| 517 |
indicators = gr.CheckboxGroup(label="Indicators", choices=['RSI', 'SMA21', 'SMA50', 'SMA200', 'VWAP', 'Bollinger Bands'], value=['SMA21', 'SMA50'])
|
| 518 |
+
analysis_type = gr.Radio(label="Analysis Type", choices=['Single Ticker', 'Comparative Analysis', 'Trend Analysis', 'Correlation Analysis', 'Comprehensive Investment Strategy', 'Custom Chart Analysis'], value='Single Ticker')
|
| 519 |
|
| 520 |
query = gr.Textbox(label="Analysis Query", value="Analyze the price trends.")
|
| 521 |
+
uploaded_image = gr.Image(label="Upload Custom Chart (optional)", type="pil")
|
| 522 |
analyze_button = gr.Button("Analyze")
|
| 523 |
output_image = gr.Image(label="Analysis Chart")
|
| 524 |
output_text = gr.Textbox(label="Generated Insights", lines=10)
|
| 525 |
|
| 526 |
analyze_button.click(
|
| 527 |
fn=gradio_interface,
|
| 528 |
+
inputs=[ticker1, ticker2, ticker3, ticker4, start_date, end_date, query, analysis_type, interval, indicators, uploaded_image],
|
| 529 |
outputs=[output_text, output_image]
|
| 530 |
)
|
| 531 |
|