Spaces:
Runtime error
Runtime error
ziyadsuper2017
commited on
Commit
•
4598a68
1
Parent(s):
3f12240
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ from gtts import gTTS
|
|
7 |
import google.generativeai as genai
|
8 |
from io import BytesIO
|
9 |
import PyPDF2
|
10 |
-
from
|
11 |
|
12 |
# Set your API key
|
13 |
api_key = "AIzaSyAHD0FwX-Ds6Y3eI-i5Oz7IdbJqR6rN7pg" # Replace with your actual API key
|
@@ -108,7 +108,7 @@ def send_message(audio_data=None):
|
|
108 |
{"role": "user", "parts": [get_file_base64(file_content, uploaded_file.type)]}
|
109 |
)
|
110 |
|
111 |
-
# Handle audio data
|
112 |
if audio_data:
|
113 |
prompt_parts.append(get_file_base64(audio_data, 'audio/wav'))
|
114 |
st.session_state['chat_history'].append(
|
@@ -145,6 +145,7 @@ def send_message(audio_data=None):
|
|
145 |
# Update the chat history display
|
146 |
display_chat_history()
|
147 |
|
|
|
148 |
# --- User Input Area ---
|
149 |
col1, col2 = st.columns([3, 1])
|
150 |
with col1:
|
@@ -168,25 +169,12 @@ uploaded_files = st.file_uploader(
|
|
168 |
key=st.session_state.file_uploader_key
|
169 |
)
|
170 |
|
171 |
-
# ---
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
key="audio-recorder",
|
176 |
-
mode=WebRtcMode.SENDONLY,
|
177 |
-
rtc_configuration=RTC_CONFIGURATION,
|
178 |
-
audio_receiver_size=256,
|
179 |
-
media_stream_constraints={"video": False, "audio": True},
|
180 |
-
)
|
181 |
-
|
182 |
-
if webrtc_ctx.audio_receiver:
|
183 |
-
st.write("Recording audio...")
|
184 |
-
audio_frames = webrtc_ctx.audio_receiver.get_frames(timeout=None)
|
185 |
-
audio_data = b"".join([frame for frame in audio_frames])
|
186 |
-
|
187 |
-
# Send the recorded audio when the "Send" button is clicked
|
188 |
if st.button("Send Recording"):
|
189 |
-
send_message(audio_data=
|
190 |
|
191 |
# --- Other Buttons ---
|
192 |
st.button("Clear Conversation", on_click=clear_conversation)
|
|
|
7 |
import google.generativeai as genai
|
8 |
from io import BytesIO
|
9 |
import PyPDF2
|
10 |
+
from audio_recorder_streamlit import audio_recorder
|
11 |
|
12 |
# Set your API key
|
13 |
api_key = "AIzaSyAHD0FwX-Ds6Y3eI-i5Oz7IdbJqR6rN7pg" # Replace with your actual API key
|
|
|
108 |
{"role": "user", "parts": [get_file_base64(file_content, uploaded_file.type)]}
|
109 |
)
|
110 |
|
111 |
+
# Handle audio data
|
112 |
if audio_data:
|
113 |
prompt_parts.append(get_file_base64(audio_data, 'audio/wav'))
|
114 |
st.session_state['chat_history'].append(
|
|
|
145 |
# Update the chat history display
|
146 |
display_chat_history()
|
147 |
|
148 |
+
|
149 |
# --- User Input Area ---
|
150 |
col1, col2 = st.columns([3, 1])
|
151 |
with col1:
|
|
|
169 |
key=st.session_state.file_uploader_key
|
170 |
)
|
171 |
|
172 |
+
# --- Audio Recorder ---
|
173 |
+
audio_bytes = audio_recorder()
|
174 |
+
if audio_bytes:
|
175 |
+
st.audio(audio_bytes, format="audio/wav")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
if st.button("Send Recording"):
|
177 |
+
send_message(audio_data=audio_bytes)
|
178 |
|
179 |
# --- Other Buttons ---
|
180 |
st.button("Clear Conversation", on_click=clear_conversation)
|