cryogenic22 commited on
Commit
5137929
·
verified ·
1 Parent(s): 212c449

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -9
app.py CHANGED
@@ -100,6 +100,43 @@ def detect_chart_type(client, image_data):
100
  st.error(f"Error in chart type detection: {str(e)}")
101
  return "Other"
102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  def continue_analysis_with_claude(client, question, previous_analysis, image_data=None):
104
  """Continue the analysis based on a follow-up question"""
105
  try:
@@ -282,16 +319,17 @@ def main():
282
  st.title("🚀 Chart Analysis AI")
283
  upload_option = st.radio(
284
  "Choose input method:",
285
- ("Upload Image", "Take Screenshot", "Ask Question")
 
286
  )
287
 
288
  # File uploader
289
  if upload_option == "Upload Image":
290
- uploaded_file = st.file_uploader("Upload your chart", type=["png", "jpg", "jpeg"])
291
  if uploaded_file:
292
  st.session_state.current_image = uploaded_file.getvalue()
293
  elif upload_option == "Take Screenshot":
294
- if st.button("Take Screenshot", key="screenshot"):
295
  st.info("Feature coming soon! For now, please use the Upload Image option.")
296
  screenshot_taken = False
297
 
@@ -300,13 +338,15 @@ def main():
300
  patterns = st.multiselect(
301
  "Patterns to Look For",
302
  ["Double Top/Bottom", "Head and Shoulders", "Triangle",
303
- "Flag", "Wedge", "Channel", "Support/Resistance"]
 
304
  )
305
 
306
  indicators = st.multiselect(
307
  "Technical Indicators",
308
  ["Moving Averages", "RSI", "MACD", "Bollinger Bands",
309
- "Volume", "Stochastic", "ADX"]
 
310
  )
311
 
312
  # Main content area
@@ -396,8 +436,8 @@ def main():
396
  st.write(f"Follow-up: {chat['question']}")
397
 
398
  # Save chat options
399
- save_name = st.text_input("Save chat as (optional):")
400
- if st.button("Save Chat"):
401
  if st.session_state.chat_history:
402
  filename = save_chat_history(
403
  st.session_state.chat_history,
@@ -412,8 +452,8 @@ def main():
412
  st.title("📚 Learn Trading")
413
 
414
  # Search or select trading concept
415
- concept = st.text_input("Enter a trading concept you'd like to learn about (e.g., 'evening star pattern', 'RSI', 'MACD'):")
416
- if st.button("Learn"):
417
  if concept:
418
  with st.spinner("Getting educational content..."):
419
  education_content = get_trading_education(client, concept)
 
100
  st.error(f"Error in chart type detection: {str(e)}")
101
  return "Other"
102
 
103
+ def analyze_chart_with_claude(client, image_data, prompt, chart_type=None):
104
+ """Analyze chart using Claude Vision"""
105
+ try:
106
+ encoded_image = base64.b64encode(image_data).decode('utf-8')
107
+
108
+ # If chart type wasn't provided, detect it first
109
+ if not chart_type:
110
+ chart_type = detect_chart_type(client, image_data)
111
+ st.info(f"Detected chart type: {chart_type}")
112
+
113
+ message = client.messages.create(
114
+ model="claude-3-opus-20240229",
115
+ max_tokens=1000,
116
+ messages=[{
117
+ "role": "user",
118
+ "content": [
119
+ {
120
+ "type": "text",
121
+ "text": prompt.format(chart_type=chart_type)
122
+ },
123
+ {
124
+ "type": "image",
125
+ "source": {
126
+ "type": "base64",
127
+ "media_type": "image/jpeg",
128
+ "data": encoded_image
129
+ }
130
+ }
131
+ ]
132
+ }]
133
+ )
134
+
135
+ return message.content[0].text, chart_type
136
+ except Exception as e:
137
+ st.error(f"Error in Claude analysis: {str(e)}")
138
+ return None, None
139
+
140
  def continue_analysis_with_claude(client, question, previous_analysis, image_data=None):
141
  """Continue the analysis based on a follow-up question"""
142
  try:
 
319
  st.title("🚀 Chart Analysis AI")
320
  upload_option = st.radio(
321
  "Choose input method:",
322
+ ("Upload Image", "Take Screenshot", "Ask Question"),
323
+ key="analysis_upload_option" # Added unique key
324
  )
325
 
326
  # File uploader
327
  if upload_option == "Upload Image":
328
+ uploaded_file = st.file_uploader("Upload your chart", type=["png", "jpg", "jpeg"], key="analysis_file_uploader")
329
  if uploaded_file:
330
  st.session_state.current_image = uploaded_file.getvalue()
331
  elif upload_option == "Take Screenshot":
332
+ if st.button("Take Screenshot", key="analysis_screenshot_button"):
333
  st.info("Feature coming soon! For now, please use the Upload Image option.")
334
  screenshot_taken = False
335
 
 
338
  patterns = st.multiselect(
339
  "Patterns to Look For",
340
  ["Double Top/Bottom", "Head and Shoulders", "Triangle",
341
+ "Flag", "Wedge", "Channel", "Support/Resistance"],
342
+ key="analysis_patterns"
343
  )
344
 
345
  indicators = st.multiselect(
346
  "Technical Indicators",
347
  ["Moving Averages", "RSI", "MACD", "Bollinger Bands",
348
+ "Volume", "Stochastic", "ADX"],
349
+ key="analysis_indicators"
350
  )
351
 
352
  # Main content area
 
436
  st.write(f"Follow-up: {chat['question']}")
437
 
438
  # Save chat options
439
+ save_name = st.text_input("Save chat as (optional):", key="save_chat_name")
440
+ if st.button("Save Chat", key="save_chat_button"):
441
  if st.session_state.chat_history:
442
  filename = save_chat_history(
443
  st.session_state.chat_history,
 
452
  st.title("📚 Learn Trading")
453
 
454
  # Search or select trading concept
455
+ concept = st.text_input("Enter a trading concept you'd like to learn about (e.g., 'evening star pattern', 'RSI', 'MACD'):", key="learn_concept")
456
+ if st.button("Learn", key="learn_button"):
457
  if concept:
458
  with st.spinner("Getting educational content..."):
459
  education_content = get_trading_education(client, concept)