# 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(""" """, 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}")