cryogenic22 commited on
Commit
73ae02a
·
verified ·
1 Parent(s): 58046c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +116 -1
app.py CHANGED
@@ -1,4 +1,119 @@
1
- # app.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  import streamlit as st
4
  from services.claude_service import ClaudeService
 
1
+ def show_chart_analysis_tab(claude_service, analysis_service):
2
+ """Display chart analysis functionality"""
3
+ # Get user expertise level
4
+ expertise_level = create_expertise_selector()
5
+
6
+ # Create sidebar and get inputs
7
+ upload_option, uploaded_files, patterns, indicators, comparison_type = create_sidebar()
8
+
9
+ # Main content area
10
+ col1, col2 = st.columns([2, 1])
11
+
12
+ with col1:
13
+ st.title("📈 Stock Chart Analysis Assistant")
14
+
15
+ if upload_option == "Ask Question":
16
+ question = st.text_input(
17
+ "What would you like to know?",
18
+ key="main_question_input"
19
+ )
20
+
21
+ # Main analysis section
22
+ if uploaded_files:
23
+ # Store all uploaded images
24
+ st.session_state.current_images = [file.getvalue() for file in uploaded_files]
25
+
26
+ analyze_clicked = show_analysis_section(uploaded_files)
27
+
28
+ # Store analysis results in session state
29
+ if 'analysis_results' not in st.session_state:
30
+ st.session_state.analysis_results = []
31
+
32
+ if analyze_clicked:
33
+ if not uploaded_files:
34
+ st.warning("Please upload at least one chart.")
35
+ else:
36
+ with st.spinner("Analyzing charts..."):
37
+ results = analysis_service.analyze_multiple_charts(
38
+ st.session_state.current_images,
39
+ patterns,
40
+ indicators,
41
+ comparison_type,
42
+ expertise_level
43
+ )
44
+
45
+ if results:
46
+ st.session_state.current_analysis = results[-1]['analysis']
47
+ st.session_state.chat_history.extend(results)
48
+ st.session_state.analysis_results = results
49
+
50
+ # Display analysis results from session state
51
+ if st.session_state.analysis_results:
52
+ results = st.session_state.analysis_results
53
+
54
+ # First show comparative analysis if it exists
55
+ for result in results:
56
+ if result.get('analysis_type') != 'Individual':
57
+ with st.container():
58
+ st.subheader(f"{result['analysis_type']} Results")
59
+ st.markdown(result['analysis'])
60
+
61
+ # Add follow-up section immediately after analysis
62
+ follow_up = show_follow_up_section(f"comparative_followup")
63
+ if follow_up:
64
+ with st.spinner("Processing follow-up..."):
65
+ response = analysis_service.handle_follow_up_question(
66
+ follow_up,
67
+ result['analysis'],
68
+ st.session_state.current_images
69
+ )
70
+ if response:
71
+ st.session_state.chat_history.append(response)
72
+ st.markdown(response['analysis'])
73
+
74
+ # Then show individual analyses
75
+ individual_analyses = [r for r in results if r.get('analysis_type') == 'Individual']
76
+ for idx, result in enumerate(individual_analyses):
77
+ with st.container():
78
+ st.subheader(f"Analysis Results - Chart {idx + 1}")
79
+ st.markdown(result['analysis'])
80
+
81
+ # Add follow-up section for each analysis
82
+ container_key = f"individual_followup_{idx}"
83
+ follow_up = show_follow_up_section(container_key)
84
+ if follow_up:
85
+ with st.spinner("Processing follow-up..."):
86
+ response = analysis_service.handle_follow_up_question(
87
+ follow_up,
88
+ result['analysis'],
89
+ st.session_state.current_images[idx] if idx < len(st.session_state.current_images) else None
90
+ )
91
+ if response:
92
+ st.session_state.chat_history.append(response)
93
+ st.markdown(response['analysis'])
94
+
95
+ # Risk warning at the bottom
96
+ st.warning(
97
+ "⚠️ This analysis is AI-generated and for informational purposes only. "
98
+ "Do not make trading decisions solely based on this information."
99
+ )
100
+
101
+ with col2:
102
+ # Chat history
103
+ show_chat_history(st.session_state.chat_history)
104
+
105
+ # Save options
106
+ save_name = show_save_options()
107
+ if save_name and st.session_state.chat_history:
108
+ filename = save_chat_history(
109
+ st.session_state.chat_history,
110
+ st.session_state.current_images[0] if st.session_state.current_images else None,
111
+ f"{save_name}.json" if save_name else None
112
+ )
113
+ if filename:
114
+ st.success(f"Chat saved as {filename}")
115
+ else:
116
+ st.info("Chat saved to session state")# app.py
117
 
118
  import streamlit as st
119
  from services.claude_service import ClaudeService