Daaku-C5 commited on
Commit
6e6e6ae
Β·
verified Β·
1 Parent(s): d111b47

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +20 -13
src/streamlit_app.py CHANGED
@@ -79,7 +79,7 @@ def load_context():
79
  return f.read().strip()
80
  else:
81
  # Default context if file doesn't exist
82
- return """I am Prakhar. I can help you with general questions and conversations.
83
  I aim to be helpful, harmless, and honest in all my interactions."""
84
 
85
  except Exception as e:
@@ -112,7 +112,7 @@ def transcribe_audio(audio_bytes):
112
  transcript = client.audio.transcriptions.create(
113
  model="whisper-1",
114
  file=audio_file,
115
- language="en"
116
  )
117
 
118
  # Clean up temporary file
@@ -134,7 +134,8 @@ Context about you:
134
 
135
  Instructions:
136
  - Use the context above to inform your responses
137
- - If asked about something not covered in the context, say "I'm not sure about that based on what I know about myself"
 
138
  - Keep responses conversational and natural
139
  - Be helpful and engaging"""
140
 
@@ -194,7 +195,7 @@ def process_audio(audio_bytes):
194
 
195
  def main():
196
  st.title("πŸŽ™οΈ Voice Bot")
197
- st.markdown("*Talk to me using your voice!*")
198
 
199
  # Initialize session state
200
  init_session_state()
@@ -204,7 +205,6 @@ def main():
204
 
205
  with col1:
206
  st.subheader("🎀 Voice Input")
207
- st.write("Audio Recording stops after 2 seconds of silence.")
208
 
209
  # Audio recorder
210
  audio_bytes = audio_recorder(
@@ -217,6 +217,10 @@ def main():
217
  sample_rate=44100
218
  )
219
 
 
 
 
 
220
  # Process audio when new recording is available
221
  if audio_bytes and not st.session_state.processing:
222
  st.session_state.processing = True
@@ -230,12 +234,11 @@ def main():
230
  "ai": ai_response,
231
  "speech": speech_audio
232
  })
 
 
 
233
 
234
  st.session_state.processing = False
235
-
236
- # Show current recording
237
- if audio_bytes:
238
- st.audio(audio_bytes, format="audio/wav")
239
 
240
  with col2:
241
  st.subheader("πŸ’¬ Conversation")
@@ -268,13 +271,17 @@ def main():
268
  else:
269
  st.info("πŸ‘‹ Start by recording your voice message above!")
270
 
271
- # Context management section
272
  st.divider()
273
 
274
- with st.expander("✍️ Context", expanded=False):
275
- st.text_area("Current: ", value=st.session_state.context,
276
- height=270,)
277
 
 
 
 
 
278
 
279
  # Status indicators
280
  if st.session_state.processing:
 
79
  return f.read().strip()
80
  else:
81
  # Default context if file doesn't exist
82
+ return """I am Prakhar, an AI assistant. I can help you with general questions and conversations.
83
  I aim to be helpful, harmless, and honest in all my interactions."""
84
 
85
  except Exception as e:
 
112
  transcript = client.audio.transcriptions.create(
113
  model="whisper-1",
114
  file=audio_file,
115
+ language="en" # You can remove this to auto-detect language
116
  )
117
 
118
  # Clean up temporary file
 
134
 
135
  Instructions:
136
  - Use the context above to inform your responses
137
+ - If asked about something not covered in the context, you can use your general knowledge
138
+ - If you're not sure about something specific to your context, say "I'm not sure about that based on what I know about myself"
139
  - Keep responses conversational and natural
140
  - Be helpful and engaging"""
141
 
 
195
 
196
  def main():
197
  st.title("πŸŽ™οΈ Voice Bot")
198
+ st.markdown("*Talk to Prakhar using your voice!*")
199
 
200
  # Initialize session state
201
  init_session_state()
 
205
 
206
  with col1:
207
  st.subheader("🎀 Voice Input")
 
208
 
209
  # Audio recorder
210
  audio_bytes = audio_recorder(
 
217
  sample_rate=44100
218
  )
219
 
220
+ # Show current recording
221
+ if audio_bytes:
222
+ st.audio(audio_bytes, format="audio/wav")
223
+
224
  # Process audio when new recording is available
225
  if audio_bytes and not st.session_state.processing:
226
  st.session_state.processing = True
 
234
  "ai": ai_response,
235
  "speech": speech_audio
236
  })
237
+
238
+ # Force a rerun to update the conversation display
239
+ st.rerun()
240
 
241
  st.session_state.processing = False
 
 
 
 
242
 
243
  with col2:
244
  st.subheader("πŸ’¬ Conversation")
 
271
  else:
272
  st.info("πŸ‘‹ Start by recording your voice message above!")
273
 
274
+ # Context display section
275
  st.divider()
276
 
277
+ with st.expander("ℹ️ Context", expanded=False):
278
+ st.markdown("**Prakhar's Context:**")
279
+ st.info(st.session_state.context)
280
 
281
+ # Only keep the clear conversation button
282
+ if st.button("πŸ—‘οΈ Clear Conversation"):
283
+ st.session_state.conversation_history = []
284
+ st.rerun()
285
 
286
  # Status indicators
287
  if st.session_state.processing: