cryogenic22 commited on
Commit
58046c9
·
verified ·
1 Parent(s): 877d096

Update ui/components.py

Browse files
Files changed (1) hide show
  1. ui/components.py +51 -17
ui/components.py CHANGED
@@ -70,29 +70,63 @@ def show_analysis_section(uploaded_files):
70
  analyze_btn = st.button("Analyze Charts", key="main_analyze_btn")
71
  return analyze_btn
72
 
73
- def show_chat_history(chat_history):
74
- """Display chat history"""
75
- st.subheader("Chat History")
76
- for idx, chat in enumerate(chat_history):
77
- timestamp = chat.get('timestamp', 'No date')
78
- analysis_type = chat.get('analysis_type', 'Analysis')
79
- label = f"{analysis_type} from {timestamp[:16]}"
80
-
81
- expander = st.expander(label)
82
- with expander:
83
- st.write(chat.get('analysis', ''))
84
- if chat.get('question'):
85
- st.write(f"Follow-up: {chat['question']}")
86
-
87
  def show_follow_up_section(key_suffix=""):
88
  """Show the follow-up question section"""
89
- st.subheader("Continue Analysis")
90
  follow_up = st.text_input(
91
  "Ask a follow-up question:",
92
  key=f"followup_input_{key_suffix}"
93
  )
94
- send_btn = st.button("Send", key=f"followup_send_btn_{key_suffix}")
95
- return follow_up if send_btn else None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
 
97
  def show_save_options():
98
  """Show save chat options"""
 
70
  analyze_btn = st.button("Analyze Charts", key="main_analyze_btn")
71
  return analyze_btn
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  def show_follow_up_section(key_suffix=""):
74
  """Show the follow-up question section"""
 
75
  follow_up = st.text_input(
76
  "Ask a follow-up question:",
77
  key=f"followup_input_{key_suffix}"
78
  )
79
+
80
+ # Store the input in session state
81
+ input_key = f"followup_input_{key_suffix}"
82
+ if input_key not in st.session_state:
83
+ st.session_state[input_key] = ""
84
+
85
+ # Create a unique key for the send button
86
+ button_key = f"followup_send_btn_{key_suffix}"
87
+
88
+ # Use button click with session state to maintain conversation
89
+ if st.button("Send", key=button_key):
90
+ if follow_up:
91
+ return follow_up
92
+ return None
93
+
94
+ def show_chat_history(chat_history):
95
+ """Display chat history"""
96
+ st.subheader("Chat History")
97
+
98
+ # Group chat messages by conversation
99
+ current_conversation = []
100
+ for idx, chat in enumerate(chat_history):
101
+ # Start a new conversation if this is an initial analysis
102
+ if chat.get('analysis_type') == 'Individual' or chat.get('analysis_type') == 'Correlated Analysis':
103
+ if current_conversation:
104
+ display_conversation_group(current_conversation)
105
+ current_conversation = [chat]
106
+ else:
107
+ current_conversation.append(chat)
108
+
109
+ # Display the last conversation group
110
+ if current_conversation:
111
+ display_conversation_group(current_conversation)
112
+
113
+ def display_conversation_group(conversation):
114
+ """Display a group of related chat messages"""
115
+ if not conversation:
116
+ return
117
+
118
+ # Use the first message timestamp for the expander label
119
+ timestamp = conversation[0].get('timestamp', 'No date')
120
+ analysis_type = conversation[0].get('analysis_type', 'Analysis')
121
+
122
+ with st.expander(f"{analysis_type} from {timestamp[:16]}", expanded=True):
123
+ for message in conversation:
124
+ if message.get('analysis_type') in ['Individual', 'Correlated Analysis']:
125
+ st.markdown("**Initial Analysis:**")
126
+ elif message.get('question'):
127
+ st.markdown(f"**Follow-up Question:** {message['question']}")
128
+
129
+ st.markdown(message.get('analysis', ''))
130
 
131
  def show_save_options():
132
  """Show save chat options"""