File size: 2,583 Bytes
7246624
 
 
 
 
 
 
a8b0bcf
6cf3153
7246624
 
 
 
a8b0bcf
7246624
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a8b0bcf
 
7246624
 
 
 
 
 
 
a8b0bcf
7246624
a8b0bcf
 
 
 
 
 
 
 
 
 
 
 
7246624
 
a8b0bcf
 
 
 
 
 
 
 
 
 
7246624
 
a8b0bcf
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# app.py
import os
import streamlit as st
from PIL import Image
from groq import Groq
import io

# Set your GROQ API key here or export as environment variable before running
os.environ["GROQ_API_KEY"] = "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"

client = Groq(api_key=os.environ.get("GROQ_API_KEY"))

st.set_page_config(page_title="AI Trade Predictor", layout="wide")

st.markdown("""
    <style>
    .main {
        background-color: #0d1117;
        color: white;
    }
    .stButton>button {
        background-color: #1f6feb;
        color: white;
        font-weight: bold;
    }
    .stFileUploader label {
        color: #58a6ff;
    }
    </style>
""", unsafe_allow_html=True)

st.title("πŸ’° AI Trade Predictor")
st.markdown("Upload a candlestick chart image, and the AI will analyze it using common trading strategies.")

uploaded_file = st.file_uploader("Upload Candlestick Chart Image", type=["jpg", "png", "jpeg"])

if uploaded_file is not None:
    image = Image.open(uploaded_file)
    st.image(image, caption="Uploaded Chart", use_column_width=True)

    if st.button("Analyze Chart πŸ”"):
        with st.spinner("Analyzing chart and generating predictions..."):
            # Instead of sending the full image, just notify AI that user uploaded a chart image
            prompt = (
                "You are a trading expert AI. "
                "A user uploaded a candlestick chart image (image content not available). "
                "Based on your knowledge of standard technical strategies (RSI, MACD, moving averages, "
                "candlestick patterns, support/resistance), analyze this chart and provide:\n"
                "1. Should the user BUY or SELL?\n"
                "2. Confidence level in percentage.\n"
                "3. Best timeframe for this trade.\n"
                "4. Risks involved and how this prediction might go wrong.\n"
                "5. Explanation of your reasoning.\n"
                "Answer concisely and clearly."
            )

            try:
                chat_completion = client.chat.completions.create(
                    messages=[{"role": "user", "content": prompt}],
                    model="llama-3.3-70b-versatile",
                )
                result = chat_completion.choices[0].message.content
                st.markdown("### πŸ“ˆ Prediction Result")
                st.markdown(result)
            except Exception as e:
                st.error(f"Error communicating with GROQ API: {e}")
else:
    st.info("Please upload a candlestick chart image to begin analysis.")