File size: 2,267 Bytes
7246624
0f4aad7
7246624
 
 
 
0f4aad7
7246624
0f4aad7
 
 
7246624
0f4aad7
 
 
 
a8b0bcf
0f4aad7
 
7246624
 
 
0f4aad7
 
7246624
 
0f4aad7
7246624
0f4aad7
7246624
 
 
 
0f4aad7
 
7246624
0f4aad7
7246624
0f4aad7
7246624
 
 
0f4aad7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7246624
a8b0bcf
0f4aad7
a8b0bcf
0f4aad7
a8b0bcf
0f4aad7
 
a8b0bcf
0f4aad7
 
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
# app.py
import os
import streamlit as st
from PIL import Image
from groq import Groq
import base64

# Set up Groq API
GROQ_API_KEY = st.secrets["GROQ_API_KEY"]
client = Groq(api_key=GROQ_API_KEY)

# Helper function to encode image as base64
def encode_image(image):
    buffered = image.getvalue()
    return base64.b64encode(buffered).decode()

# Streamlit UI
st.set_page_config(page_title="AI Trade Predictor", layout="centered")
st.markdown("""
    <style>
    .main {
        background-color: #1e1e1e;
        color: #ffffff;
    }
    .stButton>button {
        background-color: #4CAF50;
        color: white;
        font-size: 18px;
    }
    </style>
""", unsafe_allow_html=True)

st.title("πŸ€– AI Trade Predictor")
st.write("Upload your candlestick chart image and let AI analyze the trading signals for you.")

uploaded_file = st.file_uploader("Upload a candlestick chart image", type=["png", "jpg", "jpeg"])

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

    if st.button("Analyze Chart"):
        with st.spinner("Analyzing..."):
            encoded_image = encode_image(uploaded_file)

            prompt = f"""
You are an AI trading assistant. A user has uploaded a candlestick chart. Based on the chart image, perform the following:
1. Identify key signals like bullish/bearish patterns, RSI, MACD etc.
2. Predict BUY/SELL/WAIT decisions for multiple timeframes (e.g., 30m, 1h, 4h, 1d).
3. Give a confidence percentage for each prediction.
4. Explain in simple terms for beginners β€” avoid complex jargon unless explained.
5. List the risks involved with each prediction.
6. Provide a summary with what a beginner should do next.
7. Format output cleanly with emojis and bullet points.

Here is the chart (as base64): {encoded_image}
"""

            try:
                response = client.chat.completions.create(
                    messages=[{"role": "user", "content": prompt}],
                    model="llama-3.3-70b-versatile"
                )
                st.success("Analysis Complete!")
                st.markdown(response.choices[0].message.content)

            except Exception as e:
                st.error(f"Something went wrong: {e}")