|
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(""" |
|
<style> |
|
.main { |
|
background-color: #f5f7fa; |
|
} |
|
h1 { |
|
color: #3b3b3b; |
|
} |
|
.stButton > button { |
|
color: white; |
|
background-color: #4CAF50; |
|
font-size: 16px; |
|
border-radius: 10px; |
|
padding: 10px 24px; |
|
} |
|
</style> |
|
""", 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...") |
|
|
|
|
|
import base64 |
|
import io |
|
buffered = io.BytesIO() |
|
image.save(buffered, format="PNG") |
|
img_str = base64.b64encode(buffered.getvalue()).decode("utf-8") |
|
|
|
|
|
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}") |
|
|
|
|
|
|
|
st.markdown("---") |
|
st.markdown("Made β€οΈ by Abdullah's AI Labs") |
|
|