|
|
|
import os |
|
import streamlit as st |
|
from PIL import Image |
|
from groq import Groq |
|
import io |
|
|
|
|
|
os.environ["GROQ_API_KEY"] = "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" |
|
|
|
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("π° AI Trade Predictor") |
|
st.markdown("Upload a candlestick chart image, and the AI will analyze it using common trading strategies.") |
|
|
|
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) |
|
|
|
if st.button("Analyze Chart π"): |
|
with st.spinner("Analyzing chart and generating predictions..."): |
|
|
|
prompt = ( |
|
"You are a trading expert AI. " |
|
"A user uploaded a candlestick chart image (image content not available). " |
|
"Based on your knowledge of standard technical strategies (RSI, MACD, moving averages, " |
|
"candlestick patterns, support/resistance), analyze this chart and provide:\n" |
|
"1. Should the user BUY or SELL?\n" |
|
"2. Confidence level in percentage.\n" |
|
"3. Best timeframe for this trade.\n" |
|
"4. Risks involved and how this prediction might go wrong.\n" |
|
"5. Explanation of your reasoning.\n" |
|
"Answer concisely and clearly." |
|
) |
|
|
|
try: |
|
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("### π Prediction Result") |
|
st.markdown(result) |
|
except Exception as e: |
|
st.error(f"Error communicating with GROQ API: {e}") |
|
else: |
|
st.info("Please upload a candlestick chart image to begin analysis.") |
|
|
|
|