Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,9 +8,11 @@ from ui.components import (
|
|
| 8 |
show_analysis_section,
|
| 9 |
show_chat_history,
|
| 10 |
show_follow_up_section,
|
| 11 |
-
show_save_options
|
|
|
|
| 12 |
)
|
| 13 |
from utils.file_handlers import save_chat_history
|
|
|
|
| 14 |
|
| 15 |
def init_session_state():
|
| 16 |
"""Initialize session state variables"""
|
|
@@ -23,23 +25,10 @@ def init_session_state():
|
|
| 23 |
if 'current_images' not in st.session_state:
|
| 24 |
st.session_state.current_images = []
|
| 25 |
|
| 26 |
-
def
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
initial_sidebar_state="expanded"
|
| 31 |
-
)
|
| 32 |
-
|
| 33 |
-
# Initialize services
|
| 34 |
-
try:
|
| 35 |
-
claude_service = ClaudeService()
|
| 36 |
-
analysis_service = ChartAnalysisService(claude_service)
|
| 37 |
-
except ValueError as e:
|
| 38 |
-
st.error(str(e))
|
| 39 |
-
return
|
| 40 |
-
|
| 41 |
-
# Initialize session state
|
| 42 |
-
init_session_state()
|
| 43 |
|
| 44 |
# Create sidebar and get inputs
|
| 45 |
upload_option, uploaded_files, patterns, indicators, comparison_type = create_sidebar()
|
|
@@ -87,7 +76,7 @@ def main():
|
|
| 87 |
st.subheader(f"{result['analysis_type']} Results")
|
| 88 |
st.write(result['analysis'])
|
| 89 |
# Add follow-up section immediately
|
| 90 |
-
follow_up = show_follow_up_section("comparative_followup")
|
| 91 |
if follow_up:
|
| 92 |
with st.spinner("Processing follow-up..."):
|
| 93 |
response = analysis_service.handle_follow_up_question(
|
|
@@ -122,20 +111,6 @@ def main():
|
|
| 122 |
"⚠️ This analysis is AI-generated and for informational purposes only. "
|
| 123 |
"Do not make trading decisions solely based on this information."
|
| 124 |
)
|
| 125 |
-
|
| 126 |
-
# Follow-up section
|
| 127 |
-
if st.session_state.current_analysis:
|
| 128 |
-
follow_up = show_follow_up_section(st.session_state.current_analysis)
|
| 129 |
-
if follow_up:
|
| 130 |
-
with st.spinner("Processing follow-up..."):
|
| 131 |
-
response = analysis_service.handle_follow_up_question(
|
| 132 |
-
follow_up,
|
| 133 |
-
st.session_state.current_analysis,
|
| 134 |
-
st.session_state.current_images[0] if st.session_state.current_images else None
|
| 135 |
-
)
|
| 136 |
-
if response:
|
| 137 |
-
st.session_state.chat_history.append(response)
|
| 138 |
-
st.write(response['analysis'])
|
| 139 |
|
| 140 |
with col2:
|
| 141 |
# Chat history
|
|
@@ -154,5 +129,48 @@ def main():
|
|
| 154 |
else:
|
| 155 |
st.info("Chat saved to session state")
|
| 156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
if __name__ == "__main__":
|
| 158 |
main()
|
|
|
|
| 8 |
show_analysis_section,
|
| 9 |
show_chat_history,
|
| 10 |
show_follow_up_section,
|
| 11 |
+
show_save_options,
|
| 12 |
+
create_expertise_selector
|
| 13 |
)
|
| 14 |
from utils.file_handlers import save_chat_history
|
| 15 |
+
from utils.learning_module import LearningModule
|
| 16 |
|
| 17 |
def init_session_state():
|
| 18 |
"""Initialize session state variables"""
|
|
|
|
| 25 |
if 'current_images' not in st.session_state:
|
| 26 |
st.session_state.current_images = []
|
| 27 |
|
| 28 |
+
def show_chart_analysis_tab(claude_service, analysis_service):
|
| 29 |
+
"""Display chart analysis functionality"""
|
| 30 |
+
# Get user expertise level
|
| 31 |
+
expertise_level = create_expertise_selector()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# Create sidebar and get inputs
|
| 34 |
upload_option, uploaded_files, patterns, indicators, comparison_type = create_sidebar()
|
|
|
|
| 76 |
st.subheader(f"{result['analysis_type']} Results")
|
| 77 |
st.write(result['analysis'])
|
| 78 |
# Add follow-up section immediately
|
| 79 |
+
follow_up = show_follow_up_section(f"comparative_followup")
|
| 80 |
if follow_up:
|
| 81 |
with st.spinner("Processing follow-up..."):
|
| 82 |
response = analysis_service.handle_follow_up_question(
|
|
|
|
| 111 |
"⚠️ This analysis is AI-generated and for informational purposes only. "
|
| 112 |
"Do not make trading decisions solely based on this information."
|
| 113 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
with col2:
|
| 116 |
# Chat history
|
|
|
|
| 129 |
else:
|
| 130 |
st.info("Chat saved to session state")
|
| 131 |
|
| 132 |
+
def show_learning_tab(learning_module):
|
| 133 |
+
"""Display learning center functionality"""
|
| 134 |
+
st.title("📚 Trading Learning Center")
|
| 135 |
+
|
| 136 |
+
# Create tabs for different learning options
|
| 137 |
+
learn_tab1, learn_tab2 = st.tabs(["Structured Courses", "Custom Learning"])
|
| 138 |
+
|
| 139 |
+
with learn_tab1:
|
| 140 |
+
st.header("Learn Trading Step by Step")
|
| 141 |
+
learning_module.display_course_selection()
|
| 142 |
+
|
| 143 |
+
with learn_tab2:
|
| 144 |
+
st.header("Ask Any Trading Question")
|
| 145 |
+
learning_module.display_custom_learning()
|
| 146 |
+
|
| 147 |
+
def main():
|
| 148 |
+
st.set_page_config(
|
| 149 |
+
page_title="Stock Chart Assistant",
|
| 150 |
+
layout="wide",
|
| 151 |
+
initial_sidebar_state="expanded"
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
# Initialize services
|
| 155 |
+
try:
|
| 156 |
+
claude_service = ClaudeService()
|
| 157 |
+
analysis_service = ChartAnalysisService(claude_service)
|
| 158 |
+
learning_module = LearningModule(claude_service)
|
| 159 |
+
except ValueError as e:
|
| 160 |
+
st.error(str(e))
|
| 161 |
+
return
|
| 162 |
+
|
| 163 |
+
# Initialize session state
|
| 164 |
+
init_session_state()
|
| 165 |
+
|
| 166 |
+
# Main application tabs
|
| 167 |
+
tab1, tab2 = st.tabs(["Chart Analysis", "Learning Center"])
|
| 168 |
+
|
| 169 |
+
with tab1:
|
| 170 |
+
show_chart_analysis_tab(claude_service, analysis_service)
|
| 171 |
+
|
| 172 |
+
with tab2:
|
| 173 |
+
show_learning_tab(learning_module)
|
| 174 |
+
|
| 175 |
if __name__ == "__main__":
|
| 176 |
main()
|