# 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"] = "your-groq-api-key-here" # 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(""" """, 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.")