Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -282,6 +282,35 @@ def show_map_if_details(history,choice):
|
|
282 |
else:
|
283 |
return gr.update(visible=False), ""
|
284 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
285 |
# Gradio Blocks interface
|
286 |
with gr.Blocks(theme='rawrsor1/Everforest') as demo:
|
287 |
with gr.Row():
|
@@ -321,7 +350,10 @@ with gr.Blocks(theme='rawrsor1/Everforest') as demo:
|
|
321 |
gr.Markdown("Locate the Events")
|
322 |
location_output = gr.HTML()
|
323 |
bot_msg.then(show_map_if_details, [chatbot, choice], [location_output, location_output])
|
324 |
-
|
|
|
|
|
|
|
325 |
|
326 |
setup_ui()
|
327 |
|
|
|
282 |
else:
|
283 |
return gr.update(visible=False), ""
|
284 |
|
285 |
+
def generate_audio_elevenlabs(text):
|
286 |
+
XI_API_KEY = os.environ['ELEVENLABS_API']
|
287 |
+
VOICE_ID = 'SHZHI20rSPDR3iE8SvZ0' # Replace with your voice ID
|
288 |
+
tts_url = f"https://api.elevenlabs.io/v1/text-to-speech/{VOICE_ID}/stream"
|
289 |
+
headers = {
|
290 |
+
"Accept": "application/json",
|
291 |
+
"xi-api-key": XI_API_KEY
|
292 |
+
}
|
293 |
+
data = {
|
294 |
+
"text": text,
|
295 |
+
"model_id": "eleven_multilingual_v2",
|
296 |
+
"voice_settings": {
|
297 |
+
"stability": 0.5,
|
298 |
+
"similarity_boost": 0.8,
|
299 |
+
"style": 0.75, # Adjust style for more romantic tone
|
300 |
+
"use_speaker_boost": True
|
301 |
+
}
|
302 |
+
}
|
303 |
+
response = requests.post(tts_url, headers=headers, json=data, stream=True)
|
304 |
+
if response.ok:
|
305 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as f:
|
306 |
+
for chunk in response.iter_content(chunk_size=1024):
|
307 |
+
f.write(chunk)
|
308 |
+
temp_audio_path = f.name
|
309 |
+
return temp_audio_path
|
310 |
+
else:
|
311 |
+
print(response.text)
|
312 |
+
return None
|
313 |
+
|
314 |
# Gradio Blocks interface
|
315 |
with gr.Blocks(theme='rawrsor1/Everforest') as demo:
|
316 |
with gr.Row():
|
|
|
350 |
gr.Markdown("Locate the Events")
|
351 |
location_output = gr.HTML()
|
352 |
bot_msg.then(show_map_if_details, [chatbot, choice], [location_output, location_output])
|
353 |
+
with gr.Column():
|
354 |
+
gr.Markdown("Listen the audio")
|
355 |
+
audio_output = gr.Audio()
|
356 |
+
bot_msg.then(generate_audio_elevenlabs, chatbot, audio_output)
|
357 |
|
358 |
setup_ui()
|
359 |
|