File size: 1,811 Bytes
adc52c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bb8fd69
adc52c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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()