import streamlit as st from PIL import Image import os from groq import Groq from dotenv import load_dotenv load_dotenv() st.set_page_config(page_title="AI Trade Predictor", layout="wide") st.markdown(""" """, unsafe_allow_html=True) st.title("📈 AI Trade Predictor") 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) st.write("Analyzing chart using AI model...") # Convert image to base64 string import base64 import io buffered = io.BytesIO() image.save(buffered, format="PNG") img_str = base64.b64encode(buffered.getvalue()).decode("utf-8") # Connect to Groq and send the image analysis prompt client = Groq(api_key=os.environ.get("GROQ_API_KEY")) user_prompt = f""" Analyze the following candlestick chart image (base64-encoded PNG) and provide a trading decision: - Tell whether the action should be BUY, SELL, or HOLD. - Give confidence level in percentage. - Suggest timeframes (e.g., 30 min, 1 hour, 4 hour, 1 day) and what signal applies to each. - List any risks or reasons the prediction may fail. - Use clear language that a beginner can understand. - Give a short summary at the end. Image (base64 PNG): {img_str} """ try: chat_completion = client.chat.completions.create( messages=[ {"role": "user", "content": user_prompt} ], model="meta-llama/llama-guard-4-12b" ) response = chat_completion.choices[0].message.content st.success("Prediction Complete") st.markdown(response) except Exception as e: st.error(f"Something went wrong: {e}") # --- FOOTER --- st.markdown("---") st.markdown("Made ❤️ by Abdullah's AI Labs")