Fixed expander nesting issue in HF Expert analysis section
Browse files
app.py
CHANGED
|
@@ -48,12 +48,6 @@ if "tts_enabled" not in st.session_state:
|
|
| 48 |
if "voice_input" not in st.session_state:
|
| 49 |
st.session_state.voice_input = ""
|
| 50 |
|
| 51 |
-
# DEBUG: Validate session messages (fixed syntax)
|
| 52 |
-
for idx, msg in enumerate(st.session_state.messages):
|
| 53 |
-
if not isinstance(msg, dict) or "role" not in msg or "content" not in msg:
|
| 54 |
-
st.error(f"π¨ Malformed message at index {idx}: {msg}")
|
| 55 |
-
st.stop()
|
| 56 |
-
|
| 57 |
# Sidebar layout redesign
|
| 58 |
with st.sidebar:
|
| 59 |
st.title("π§ AI Life Coach")
|
|
@@ -146,22 +140,19 @@ with st.sidebar:
|
|
| 146 |
st.divider()
|
| 147 |
|
| 148 |
st.subheader("π€ HF Expert Analysis")
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
use_container_width=True,
|
| 163 |
-
disabled=st.session_state.is_processing):
|
| 164 |
-
st.session_state.hf_expert_requested = True
|
| 165 |
|
| 166 |
# Main interface
|
| 167 |
st.title("π§ AI Life Coach")
|
|
@@ -212,58 +203,58 @@ if st.session_state.messages and len(st.session_state.messages) > 0:
|
|
| 212 |
use_container_width=True,
|
| 213 |
disabled=st.session_state.is_processing):
|
| 214 |
st.session_state.hf_expert_requested = True
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
# Add research/web search decisions
|
| 243 |
-
research_needs = coordinator.determine_web_search_needs(conversation_history)
|
| 244 |
-
if research_needs["needs_search"]:
|
| 245 |
-
st.info(f"π **Research Needed:** {research_needs['reasoning']}")
|
| 246 |
-
if st.button("π Perform Web Research", key="web_research_button"):
|
| 247 |
-
# Perform web search
|
| 248 |
-
with st.spinner("π Searching for current information..."):
|
| 249 |
-
# Add web search logic here
|
| 250 |
-
st.success("β
Web research completed!")
|
| 251 |
-
|
| 252 |
-
# Add to message history with HF expert tag
|
| 253 |
-
st.session_state.messages.append({
|
| 254 |
-
"role": "assistant",
|
| 255 |
-
"content": hf_analysis,
|
| 256 |
-
"timestamp": datetime.now().strftime("%H:%M:%S"),
|
| 257 |
-
"source": "hf_expert",
|
| 258 |
-
"research_needs": research_needs
|
| 259 |
-
})
|
| 260 |
-
|
| 261 |
-
st.session_state.hf_expert_requested = False
|
| 262 |
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
|
| 268 |
# Chat input - FIXED VERSION (moved outside of tabs)
|
| 269 |
user_input = st.chat_input("Type your message here...", disabled=st.session_state.is_processing)
|
|
|
|
| 48 |
if "voice_input" not in st.session_state:
|
| 49 |
st.session_state.voice_input = ""
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
# Sidebar layout redesign
|
| 52 |
with st.sidebar:
|
| 53 |
st.title("π§ AI Life Coach")
|
|
|
|
| 140 |
st.divider()
|
| 141 |
|
| 142 |
st.subheader("π€ HF Expert Analysis")
|
| 143 |
+
st.markdown("""
|
| 144 |
+
**HF Expert Features:**
|
| 145 |
+
- Analyzes entire conversation history
|
| 146 |
+
- Performs web research when needed
|
| 147 |
+
- Provides deep insights and recommendations
|
| 148 |
+
- Acts as expert consultant in your conversation
|
| 149 |
+
""")
|
| 150 |
+
if st.button("π§ Activate HF Expert",
|
| 151 |
+
key="activate_hf_expert_sidebar",
|
| 152 |
+
help="Send conversation to HF endpoint for deep analysis",
|
| 153 |
+
use_container_width=True,
|
| 154 |
+
disabled=st.session_state.is_processing):
|
| 155 |
+
st.session_state.hf_expert_requested = True
|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
# Main interface
|
| 158 |
st.title("π§ AI Life Coach")
|
|
|
|
| 203 |
use_container_width=True,
|
| 204 |
disabled=st.session_state.is_processing):
|
| 205 |
st.session_state.hf_expert_requested = True
|
| 206 |
+
|
| 207 |
+
# Show HF expert analysis when requested (outside of the expander)
|
| 208 |
+
if st.session_state.get("hf_expert_requested", False):
|
| 209 |
+
with st.spinner("π§ HF Expert analyzing conversation..."):
|
| 210 |
+
try:
|
| 211 |
+
# Get conversation history
|
| 212 |
+
user_session = session_manager.get_session("default_user")
|
| 213 |
+
conversation_history = user_session.get("conversation", [])
|
| 214 |
+
|
| 215 |
+
# Show what HF expert sees in a separate expander
|
| 216 |
+
with st.expander("π HF Expert Input", expanded=False):
|
| 217 |
+
st.markdown("**Conversation History Sent to HF Expert:**")
|
| 218 |
+
for i, msg in enumerate(conversation_history[-10:]): # Last 10 messages
|
| 219 |
+
st.markdown(f"**{msg['role'].capitalize()}:** {msg['content'][:100]}{'...' if len(msg['content']) > 100 else ''}")
|
| 220 |
+
|
| 221 |
+
# Request HF analysis
|
| 222 |
+
hf_analysis = coordinator.manual_hf_analysis(
|
| 223 |
+
"default_user",
|
| 224 |
+
conversation_history
|
| 225 |
+
)
|
| 226 |
+
|
| 227 |
+
if hf_analysis:
|
| 228 |
+
# Display HF expert response with clear indication
|
| 229 |
+
with st.chat_message("assistant"):
|
| 230 |
+
st.markdown("### π€ HF Expert Analysis")
|
| 231 |
+
st.markdown(hf_analysis)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
|
| 233 |
+
# Add research/web search decisions
|
| 234 |
+
research_needs = coordinator.determine_web_search_needs(conversation_history)
|
| 235 |
+
if research_needs["needs_search"]:
|
| 236 |
+
st.info(f"π **Research Needed:** {research_needs['reasoning']}")
|
| 237 |
+
if st.button("π Perform Web Research", key="web_research_button"):
|
| 238 |
+
# Perform web search
|
| 239 |
+
with st.spinner("π Searching for current information..."):
|
| 240 |
+
# Add web search logic here
|
| 241 |
+
st.success("β
Web research completed!")
|
| 242 |
+
|
| 243 |
+
# Add to message history with HF expert tag
|
| 244 |
+
st.session_state.messages.append({
|
| 245 |
+
"role": "assistant",
|
| 246 |
+
"content": hf_analysis,
|
| 247 |
+
"timestamp": datetime.now().strftime("%H:%M:%S"),
|
| 248 |
+
"source": "hf_expert",
|
| 249 |
+
"research_needs": research_needs
|
| 250 |
+
})
|
| 251 |
+
|
| 252 |
+
st.session_state.hf_expert_requested = False
|
| 253 |
+
|
| 254 |
+
except Exception as e:
|
| 255 |
+
user_msg = translate_error(e)
|
| 256 |
+
st.error(f"β HF Expert analysis failed: {user_msg}")
|
| 257 |
+
st.session_state.hf_expert_requested = False
|
| 258 |
|
| 259 |
# Chat input - FIXED VERSION (moved outside of tabs)
|
| 260 |
user_input = st.chat_input("Type your message here...", disabled=st.session_state.is_processing)
|