Spaces:
Build error
Build error
Update src/components/ai_tutor.py
Browse files
src/components/ai_tutor.py
CHANGED
|
@@ -14,7 +14,12 @@ class AITutor:
|
|
| 14 |
# Voice controls
|
| 15 |
col1, col2 = st.columns([3, 2])
|
| 16 |
with col1:
|
| 17 |
-
voice_active
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
if voice_active:
|
| 19 |
st.markdown("""
|
| 20 |
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
@@ -46,14 +51,14 @@ class AITutor:
|
|
| 46 |
if selected_topic != context['current_topic']:
|
| 47 |
context['current_topic'] = selected_topic
|
| 48 |
|
| 49 |
-
# Display chat container using st.empty
|
| 50 |
chat_container = st.empty()
|
| 51 |
with chat_container.container(): # Use nested container
|
| 52 |
# Display chat history with voice output
|
| 53 |
for message in context['chat_history']:
|
| 54 |
with st.chat_message(message["role"]):
|
| 55 |
st.write(message["content"])
|
| 56 |
-
if message["role"] == "assistant" and voice_active:
|
| 57 |
self.service.speak(message["content"])
|
| 58 |
|
| 59 |
# Chat input
|
|
@@ -85,7 +90,7 @@ class AITutor:
|
|
| 85 |
context['chat_history'].append({
|
| 86 |
"role": "assistant",
|
| 87 |
"content": response,
|
| 88 |
-
"speak": True
|
| 89 |
})
|
| 90 |
|
| 91 |
# Update the chat container again with the AI's response
|
|
|
|
| 14 |
# Voice controls
|
| 15 |
col1, col2 = st.columns([3, 2])
|
| 16 |
with col1:
|
| 17 |
+
# Initialize voice_active in session_state if it doesn't exist
|
| 18 |
+
if "voice_active" not in st.session_state:
|
| 19 |
+
st.session_state.voice_active = False
|
| 20 |
+
|
| 21 |
+
voice_active = st.checkbox("Enable Voice", key="voice_active") # Corrected line
|
| 22 |
+
|
| 23 |
if voice_active:
|
| 24 |
st.markdown("""
|
| 25 |
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
|
|
| 51 |
if selected_topic != context['current_topic']:
|
| 52 |
context['current_topic'] = selected_topic
|
| 53 |
|
| 54 |
+
# Display chat container using st.empty
|
| 55 |
chat_container = st.empty()
|
| 56 |
with chat_container.container(): # Use nested container
|
| 57 |
# Display chat history with voice output
|
| 58 |
for message in context['chat_history']:
|
| 59 |
with st.chat_message(message["role"]):
|
| 60 |
st.write(message["content"])
|
| 61 |
+
if message["role"] == "assistant" and st.session_state.voice_active: # Use session state
|
| 62 |
self.service.speak(message["content"])
|
| 63 |
|
| 64 |
# Chat input
|
|
|
|
| 90 |
context['chat_history'].append({
|
| 91 |
"role": "assistant",
|
| 92 |
"content": response,
|
| 93 |
+
"speak": True
|
| 94 |
})
|
| 95 |
|
| 96 |
# Update the chat container again with the AI's response
|