Spaces:
Sleeping
Sleeping
fixing bug where changing theme was clearing narratiin
Browse files- chatbot.py +17 -12
chatbot.py
CHANGED
|
@@ -100,6 +100,7 @@ def render_chatbot(code, output, error):
|
|
| 100 |
st.session_state.setdefault('conversation', [])
|
| 101 |
st.session_state.setdefault('chat_summary', "")
|
| 102 |
st.session_state.setdefault('chat_display_count', 5)
|
|
|
|
| 103 |
|
| 104 |
c1, c2 = st.columns([4, 1], gap='small')
|
| 105 |
with c1:
|
|
@@ -147,18 +148,22 @@ def render_chatbot(code, output, error):
|
|
| 147 |
st.markdown(f'<div class="chat-message bot-message">{formatted}</div>', unsafe_allow_html=True)
|
| 148 |
|
| 149 |
# π Speak
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
if start > 0 and st.button("π½ Show more"):
|
| 164 |
st.session_state.chat_display_count += 5
|
|
|
|
| 100 |
st.session_state.setdefault('conversation', [])
|
| 101 |
st.session_state.setdefault('chat_summary', "")
|
| 102 |
st.session_state.setdefault('chat_display_count', 5)
|
| 103 |
+
st.session_state.setdefault('narrations', []) # persist narrations
|
| 104 |
|
| 105 |
c1, c2 = st.columns([4, 1], gap='small')
|
| 106 |
with c1:
|
|
|
|
| 148 |
st.markdown(f'<div class="chat-message bot-message">{formatted}</div>', unsafe_allow_html=True)
|
| 149 |
|
| 150 |
# π Speak
|
| 151 |
+
if len(st.session_state.narrations) > i:
|
| 152 |
+
narration_text, narration_file = st.session_state.narrations[i]
|
| 153 |
+
st.audio(narration_file, format="audio/mp3")
|
| 154 |
+
else:
|
| 155 |
+
speak_btn = st.button(f"π Narrate #{i+1}", key=f"narrate_{i}")
|
| 156 |
+
if speak_btn:
|
| 157 |
+
status_placeholder = st.empty()
|
| 158 |
+
status_placeholder.info("π§ Generating narration...")
|
| 159 |
+
bot = CodeAssistantBot()
|
| 160 |
+
narration = bot.narrate_response(code, output, error, a, st.session_state.chat_summary)
|
| 161 |
+
status_placeholder.info("ποΈ Converting to audio...")
|
| 162 |
+
audio_filename = f"audio_{uuid.uuid4().hex}.mp3"
|
| 163 |
+
asyncio.run(text_to_speech(narration, audio_filename))
|
| 164 |
+
st.session_state.narrations.append((narration, audio_filename))
|
| 165 |
+
status_placeholder.success("π Narration ready!")
|
| 166 |
+
st.rerun()
|
| 167 |
|
| 168 |
if start > 0 and st.button("π½ Show more"):
|
| 169 |
st.session_state.chat_display_count += 5
|