Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ import google.generativeai as genai
|
|
8 |
from io import BytesIO
|
9 |
import PyPDF2
|
10 |
from streamlit_webrtc import webrtc_streamer, WebRtcMode, RTCConfiguration
|
|
|
11 |
|
12 |
# Set your API key
|
13 |
api_key = "AIzaSyAHD0FwX-Ds6Y3eI-i5Oz7IdbJqR6rN7pg" # Replace with your actual API key
|
@@ -171,22 +172,23 @@ uploaded_files = st.file_uploader(
|
|
171 |
# --- WebRTC Audio Recording ---
|
172 |
RTC_CONFIGURATION = RTCConfiguration({"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]})
|
173 |
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
|
|
|
|
181 |
|
182 |
-
if webrtc_ctx.audio_receiver:
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
|
187 |
-
|
188 |
-
|
189 |
-
send_message(audio_data=audio_data)
|
190 |
|
191 |
# --- Other Buttons ---
|
192 |
st.button("Clear Conversation", on_click=clear_conversation)
|
@@ -211,5 +213,6 @@ st.markdown(
|
|
211 |
unsafe_allow_html=True
|
212 |
)
|
213 |
|
214 |
-
# ---
|
|
|
215 |
display_chat_history()
|
|
|
8 |
from io import BytesIO
|
9 |
import PyPDF2
|
10 |
from streamlit_webrtc import webrtc_streamer, WebRtcMode, RTCConfiguration
|
11 |
+
import asyncio
|
12 |
|
13 |
# Set your API key
|
14 |
api_key = "AIzaSyAHD0FwX-Ds6Y3eI-i5Oz7IdbJqR6rN7pg" # Replace with your actual API key
|
|
|
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",
|
179 |
+
mode=WebRtcMode.SENDONLY,
|
180 |
+
rtc_configuration=RTC_CONFIGURATION,
|
181 |
+
audio_receiver_size=256,
|
182 |
+
media_stream_constraints={"video": False, "audio": True},
|
183 |
+
)
|
184 |
|
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)
|
|
|
213 |
unsafe_allow_html=True
|
214 |
)
|
215 |
|
216 |
+
# --- Run WebRTC and display chat history ---
|
217 |
+
asyncio.new_event_loop().run_until_complete(run_webrtc())
|
218 |
display_chat_history()
|