Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
import os
|
| 3 |
+
import streamlit as st
|
| 4 |
+
from PIL import Image
|
| 5 |
+
from groq import Groq
|
| 6 |
+
import base64
|
| 7 |
+
import io
|
| 8 |
+
|
| 9 |
+
# Set GROQ API Key (put your key directly for Colab or use environment variables)
|
| 10 |
+
os.environ["GROQ_API_KEY"] = "your-groq-api-key-here"
|
| 11 |
+
|
| 12 |
+
# Initialize GROQ client
|
| 13 |
+
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
|
| 14 |
+
|
| 15 |
+
st.set_page_config(page_title="AI Trade Predictor", layout="wide")
|
| 16 |
+
st.markdown("""
|
| 17 |
+
<style>
|
| 18 |
+
.main {
|
| 19 |
+
background-color: #0d1117;
|
| 20 |
+
color: white;
|
| 21 |
+
}
|
| 22 |
+
.stButton>button {
|
| 23 |
+
background-color: #1f6feb;
|
| 24 |
+
color: white;
|
| 25 |
+
font-weight: bold;
|
| 26 |
+
}
|
| 27 |
+
.stFileUploader label {
|
| 28 |
+
color: #58a6ff;
|
| 29 |
+
}
|
| 30 |
+
</style>
|
| 31 |
+
""", unsafe_allow_html=True)
|
| 32 |
+
|
| 33 |
+
st.title("\U0001F4B0 AI Trade Predictor")
|
| 34 |
+
st.markdown("Upload a candlestick chart image and get a trading signal analysis using AI")
|
| 35 |
+
|
| 36 |
+
# Upload chart image
|
| 37 |
+
uploaded_file = st.file_uploader("Upload Candlestick Chart Image", type=["jpg", "png", "jpeg"])
|
| 38 |
+
|
| 39 |
+
if uploaded_file is not None:
|
| 40 |
+
image = Image.open(uploaded_file)
|
| 41 |
+
st.image(image, caption="Uploaded Chart", use_column_width=True)
|
| 42 |
+
|
| 43 |
+
buffer = io.BytesIO()
|
| 44 |
+
image.save(buffer, format="PNG")
|
| 45 |
+
img_str = base64.b64encode(buffer.getvalue()).decode()
|
| 46 |
+
|
| 47 |
+
if st.button("Analyze Chart \U0001F52C"):
|
| 48 |
+
with st.spinner("Analyzing chart and generating predictions..."):
|
| 49 |
+
prompt = f"""
|
| 50 |
+
You are an expert trading analyst AI.
|
| 51 |
+
Analyze the attached candlestick chart image (base64 below).
|
| 52 |
+
Apply technical strategies like RSI, MACD, moving averages, support/resistance, candlestick patterns.
|
| 53 |
+
Then tell:
|
| 54 |
+
1. Whether to BUY or SELL.
|
| 55 |
+
2. The confidence level in %.
|
| 56 |
+
3. The best timeframe for this prediction.
|
| 57 |
+
4. The risk level and how it might go wrong.
|
| 58 |
+
5. Why this prediction was made.
|
| 59 |
+
Base64 image: {img_str}
|
| 60 |
+
"""
|
| 61 |
+
|
| 62 |
+
chat_completion = client.chat.completions.create(
|
| 63 |
+
messages=[{"role": "user", "content": prompt}],
|
| 64 |
+
model="llama-3.3-70b-versatile"
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
result = chat_completion.choices[0].message.content
|
| 68 |
+
st.markdown("### \U0001F4C8 Prediction Result")
|
| 69 |
+
st.markdown(result)
|
| 70 |
+
|
| 71 |
+
else:
|
| 72 |
+
st.info("Please upload a candlestick chart image to begin analysis.")
|