Update app.py
Browse files
app.py
CHANGED
@@ -3,16 +3,15 @@ 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
|
10 |
os.environ["GROQ_API_KEY"] = "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"
|
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 {
|
@@ -30,43 +29,41 @@ st.markdown("""
|
|
30 |
</style>
|
31 |
""", unsafe_allow_html=True)
|
32 |
|
33 |
-
st.title("
|
34 |
-
st.markdown("Upload a candlestick chart image and
|
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 |
-
|
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 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
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 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
else:
|
72 |
st.info("Please upload a candlestick chart image to begin analysis.")
|
|
|
|
3 |
import streamlit as st
|
4 |
from PIL import Image
|
5 |
from groq import Groq
|
|
|
6 |
import io
|
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 |
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
|
12 |
|
13 |
st.set_page_config(page_title="AI Trade Predictor", layout="wide")
|
14 |
+
|
15 |
st.markdown("""
|
16 |
<style>
|
17 |
.main {
|
|
|
29 |
</style>
|
30 |
""", unsafe_allow_html=True)
|
31 |
|
32 |
+
st.title("π° AI Trade Predictor")
|
33 |
+
st.markdown("Upload a candlestick chart image, and the AI will analyze it using common trading strategies.")
|
34 |
|
|
|
35 |
uploaded_file = st.file_uploader("Upload Candlestick Chart Image", type=["jpg", "png", "jpeg"])
|
36 |
|
37 |
if uploaded_file is not None:
|
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 chart and generating predictions..."):
|
43 |
+
# Instead of sending the full image, just notify AI that user uploaded a chart image
|
44 |
+
prompt = (
|
45 |
+
"You are a trading expert AI. "
|
46 |
+
"A user uploaded a candlestick chart image (image content not available). "
|
47 |
+
"Based on your knowledge of standard technical strategies (RSI, MACD, moving averages, "
|
48 |
+
"candlestick patterns, support/resistance), analyze this chart and provide:\n"
|
49 |
+
"1. Should the user BUY or SELL?\n"
|
50 |
+
"2. Confidence level in percentage.\n"
|
51 |
+
"3. Best timeframe for this trade.\n"
|
52 |
+
"4. Risks involved and how this prediction might go wrong.\n"
|
53 |
+
"5. Explanation of your reasoning.\n"
|
54 |
+
"Answer concisely and clearly."
|
|
|
|
|
|
|
|
|
55 |
)
|
56 |
|
57 |
+
try:
|
58 |
+
chat_completion = client.chat.completions.create(
|
59 |
+
messages=[{"role": "user", "content": prompt}],
|
60 |
+
model="llama-3.3-70b-versatile",
|
61 |
+
)
|
62 |
+
result = chat_completion.choices[0].message.content
|
63 |
+
st.markdown("### π Prediction Result")
|
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 |
+
|