ziyadsuper2017 commited on
Commit
e240cad
1 Parent(s): 489223c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -45,6 +45,12 @@ if 'chat_history' not in st.session_state:
45
  st.session_state['chat_history'] = []
46
  if 'file_uploader_key' not in st.session_state:
47
  st.session_state['file_uploader_key'] = str(uuid.uuid4())
 
 
 
 
 
 
48
 
49
  # --- Streamlit UI ---
50
  st.title("Gemini Chatbot")
@@ -64,6 +70,9 @@ def get_file_base64(file_content, mime_type):
64
  def clear_conversation():
65
  st.session_state['chat_history'] = []
66
  st.session_state['file_uploader_key'] = str(uuid.uuid4())
 
 
 
67
 
68
  def display_chat_history():
69
  chat_container = st.empty()
@@ -172,7 +181,6 @@ uploaded_files = st.file_uploader(
172
  # --- WebRTC Audio Recording ---
173
  RTC_CONFIGURATION = RTCConfiguration({"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]})
174
 
175
- # Run webrtc_streamer in a separate async function to avoid conflicts
176
  async def run_webrtc():
177
  webrtc_ctx = webrtc_streamer(
178
  key="audio-recorder",
@@ -185,10 +193,10 @@ async def run_webrtc():
185
  if webrtc_ctx.audio_receiver:
186
  st.write("Recording audio...")
187
  audio_frames = webrtc_ctx.audio_receiver.get_frames(timeout=None)
188
- audio_data = b"".join([frame for frame in audio_frames])
189
 
190
  if st.button("Send Recording"):
191
- send_message(audio_data=audio_data)
192
 
193
  # --- Other Buttons ---
194
  st.button("Clear Conversation", on_click=clear_conversation)
 
45
  st.session_state['chat_history'] = []
46
  if 'file_uploader_key' not in st.session_state:
47
  st.session_state['file_uploader_key'] = str(uuid.uuid4())
48
+ if 'uploaded_files' not in st.session_state:
49
+ st.session_state['uploaded_files'] = []
50
+ if 'user_input' not in st.session_state:
51
+ st.session_state['user_input'] = ''
52
+ if 'audio_data' not in st.session_state:
53
+ st.session_state['audio_data'] = None
54
 
55
  # --- Streamlit UI ---
56
  st.title("Gemini Chatbot")
 
70
  def clear_conversation():
71
  st.session_state['chat_history'] = []
72
  st.session_state['file_uploader_key'] = str(uuid.uuid4())
73
+ st.session_state['user_input'] = ''
74
+ st.session_state['uploaded_files'] = []
75
+ st.session_state['audio_data'] = None
76
 
77
  def display_chat_history():
78
  chat_container = st.empty()
 
181
  # --- WebRTC Audio Recording ---
182
  RTC_CONFIGURATION = RTCConfiguration({"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]})
183
 
 
184
  async def run_webrtc():
185
  webrtc_ctx = webrtc_streamer(
186
  key="audio-recorder",
 
193
  if webrtc_ctx.audio_receiver:
194
  st.write("Recording audio...")
195
  audio_frames = webrtc_ctx.audio_receiver.get_frames(timeout=None)
196
+ st.session_state.audio_data = b"".join([frame.to_ndarray() for frame in audio_frames])
197
 
198
  if st.button("Send Recording"):
199
+ send_message(audio_data=st.session_state.audio_data)
200
 
201
  # --- Other Buttons ---
202
  st.button("Clear Conversation", on_click=clear_conversation)