abdullahrehan commited on
Commit
a8b0bcf
Β·
verified Β·
1 Parent(s): 6cf3153

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -31
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 Key (put your key directly for Colab or use environment variables)
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("\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.")
 
 
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
+