Spaces:
Runtime error
Runtime error
import gradio as gr | |
from src.data_fetcher import fetch_crypto_data, fetch_stock_data, fetch_sentiment_data | |
from src.model import train_model, predict_growth | |
from src.visualizer import plot_price_trends, plot_sentiment_trends | |
def analyze_asset(asset_type, symbol): | |
""" | |
Analyze a stock or cryptocurrency symbol. | |
Fetches market data, performs sentiment analysis, | |
trains AI model, and provides predictions with visualizations. | |
""" | |
try: | |
if asset_type == "Crypto": | |
market_data = fetch_crypto_data(symbol) | |
elif asset_type == "Stock": | |
market_data = fetch_stock_data(symbol) | |
else: | |
return "Invalid asset type." | |
sentiment_score = fetch_sentiment_data(symbol) | |
train_model(market_data) | |
latest_data = market_data.iloc[-1][["close", "volume"]].values.tolist() | |
prediction = predict_growth(latest_data) | |
price_plot = plot_price_trends(market_data) | |
sentiment_plot = plot_sentiment_trends(symbol) | |
action = "BUY" if prediction == 1 else "SELL" | |
result = { | |
"Symbol": symbol, | |
"Sentiment Score": f"{sentiment_score:.2f}", | |
"Prediction": action, | |
"Visualizations": [price_plot, sentiment_plot], | |
} | |
return result | |
except Exception as e: | |
return {"Error": str(e)} | |
# Gradio Interface | |
asset_type_input = gr.Radio(["Crypto", "Stock"], label="Asset Type") | |
symbol_input = gr.Textbox(label="Enter Symbol (e.g., BTCUSDT or AAPL)") | |
output_result = gr.JSON(label="Analysis Results") | |
gr.Interface( | |
fn=analyze_asset, | |
inputs=[asset_type_input, symbol_input], | |
outputs=output_result, | |
title="Explosive Growth Bot", | |
description="Predicts explosive growth in stocks and cryptocurrencies using AI.", | |
).launch() | |