File size: 2,392 Bytes
7246624 f954745 7246624 |
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 71 72 73 |
# app.py
import os
import streamlit as st
from PIL import Image
from groq import Groq
import base64
import io
# Set GROQ API Key (put your key directly for Colab or use environment variables)
os.environ["GROQ_API_KEY"] = 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
# Initialize GROQ client
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("\U0001F4B0 AI Trade Predictor")
st.markdown("Upload a candlestick chart image and get a trading signal analysis using AI")
# Upload chart image
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)
buffer = io.BytesIO()
image.save(buffer, format="PNG")
img_str = base64.b64encode(buffer.getvalue()).decode()
if st.button("Analyze Chart \U0001F52C"):
with st.spinner("Analyzing chart and generating predictions..."):
prompt = f"""
You are an expert trading analyst AI.
Analyze the attached candlestick chart image (base64 below).
Apply technical strategies like RSI, MACD, moving averages, support/resistance, candlestick patterns.
Then tell:
1. Whether to BUY or SELL.
2. The confidence level in %.
3. The best timeframe for this prediction.
4. The risk level and how it might go wrong.
5. Why this prediction was made.
Base64 image: {img_str}
"""
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("### \U0001F4C8 Prediction Result")
st.markdown(result)
else:
st.info("Please upload a candlestick chart image to begin analysis.")
|