Update app.py
Browse files
app.py
CHANGED
@@ -1,69 +1,69 @@
|
|
1 |
# app.py
|
|
|
2 |
import os
|
3 |
import streamlit as st
|
4 |
from PIL import Image
|
5 |
from groq import Groq
|
6 |
-
import
|
7 |
-
|
8 |
-
# Set your GROQ API key here or export as environment variable before running
|
9 |
-
os.environ["GROQ_API_KEY"] = "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"
|
10 |
|
11 |
-
|
|
|
|
|
12 |
|
13 |
-
|
|
|
|
|
|
|
14 |
|
|
|
|
|
15 |
st.markdown("""
|
16 |
<style>
|
17 |
.main {
|
18 |
-
background-color: #
|
19 |
-
color:
|
20 |
}
|
21 |
.stButton>button {
|
22 |
-
background-color: #
|
23 |
color: white;
|
24 |
-
font-
|
25 |
-
}
|
26 |
-
.stFileUploader label {
|
27 |
-
color: #58a6ff;
|
28 |
}
|
29 |
</style>
|
30 |
""", unsafe_allow_html=True)
|
31 |
|
32 |
-
st.title("
|
33 |
-
st.
|
34 |
|
35 |
-
uploaded_file = st.file_uploader("Upload
|
36 |
|
37 |
-
if uploaded_file
|
38 |
image = Image.open(uploaded_file)
|
39 |
st.image(image, caption="Uploaded Chart", use_column_width=True)
|
40 |
|
41 |
-
if st.button("Analyze Chart
|
42 |
-
with st.spinner("Analyzing
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
56 |
|
57 |
try:
|
58 |
-
|
59 |
messages=[{"role": "user", "content": prompt}],
|
60 |
-
model="llama-3.3-70b-versatile"
|
61 |
)
|
62 |
-
|
63 |
-
st.markdown(
|
64 |
-
st.markdown(result)
|
65 |
-
except Exception as e:
|
66 |
-
st.error(f"Error communicating with GROQ API: {e}")
|
67 |
-
else:
|
68 |
-
st.info("Please upload a candlestick chart image to begin analysis.")
|
69 |
|
|
|
|
|
|
1 |
# app.py
|
2 |
+
# app.py
|
3 |
import os
|
4 |
import streamlit as st
|
5 |
from PIL import Image
|
6 |
from groq import Groq
|
7 |
+
import base64
|
|
|
|
|
|
|
8 |
|
9 |
+
# Set up Groq API
|
10 |
+
GROQ_API_KEY = st.secrets["GROQ_API_KEY"]
|
11 |
+
client = Groq(api_key=GROQ_API_KEY)
|
12 |
|
13 |
+
# Helper function to encode image as base64
|
14 |
+
def encode_image(image):
|
15 |
+
buffered = image.getvalue()
|
16 |
+
return base64.b64encode(buffered).decode()
|
17 |
|
18 |
+
# Streamlit UI
|
19 |
+
st.set_page_config(page_title="AI Trade Predictor", layout="centered")
|
20 |
st.markdown("""
|
21 |
<style>
|
22 |
.main {
|
23 |
+
background-color: #1e1e1e;
|
24 |
+
color: #ffffff;
|
25 |
}
|
26 |
.stButton>button {
|
27 |
+
background-color: #4CAF50;
|
28 |
color: white;
|
29 |
+
font-size: 18px;
|
|
|
|
|
|
|
30 |
}
|
31 |
</style>
|
32 |
""", unsafe_allow_html=True)
|
33 |
|
34 |
+
st.title("π€ AI Trade Predictor")
|
35 |
+
st.write("Upload your candlestick chart image and let AI analyze the trading signals for you.")
|
36 |
|
37 |
+
uploaded_file = st.file_uploader("Upload a candlestick chart image", type=["png", "jpg", "jpeg"])
|
38 |
|
39 |
+
if uploaded_file:
|
40 |
image = Image.open(uploaded_file)
|
41 |
st.image(image, caption="Uploaded Chart", use_column_width=True)
|
42 |
|
43 |
+
if st.button("Analyze Chart"):
|
44 |
+
with st.spinner("Analyzing..."):
|
45 |
+
encoded_image = encode_image(uploaded_file)
|
46 |
+
|
47 |
+
prompt = f"""
|
48 |
+
You are an AI trading assistant. A user has uploaded a candlestick chart. Based on the chart image, perform the following:
|
49 |
+
1. Identify key signals like bullish/bearish patterns, RSI, MACD etc.
|
50 |
+
2. Predict BUY/SELL/WAIT decisions for multiple timeframes (e.g., 30m, 1h, 4h, 1d).
|
51 |
+
3. Give a confidence percentage for each prediction.
|
52 |
+
4. Explain in simple terms for beginners β avoid complex jargon unless explained.
|
53 |
+
5. List the risks involved with each prediction.
|
54 |
+
6. Provide a summary with what a beginner should do next.
|
55 |
+
7. Format output cleanly with emojis and bullet points.
|
56 |
+
|
57 |
+
Here is the chart (as base64): {encoded_image}
|
58 |
+
"""
|
59 |
|
60 |
try:
|
61 |
+
response = client.chat.completions.create(
|
62 |
messages=[{"role": "user", "content": prompt}],
|
63 |
+
model="llama-3.3-70b-versatile"
|
64 |
)
|
65 |
+
st.success("Analysis Complete!")
|
66 |
+
st.markdown(response.choices[0].message.content)
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
+
except Exception as e:
|
69 |
+
st.error(f"Something went wrong: {e}")
|