Update app.py
Browse files
app.py
CHANGED
|
@@ -22,33 +22,27 @@ import torch
|
|
| 22 |
import json
|
| 23 |
from langdetect import detect
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
"
|
| 31 |
-
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
if response.status_code == 200:
|
| 47 |
-
path = f"/tmp/{uuid.uuid4().hex}.png"
|
| 48 |
-
with open(path, "wb") as f:
|
| 49 |
-
f.write(response.content)
|
| 50 |
-
return path
|
| 51 |
-
return None
|
| 52 |
|
| 53 |
THEMES = {
|
| 54 |
"Default": "",
|
|
@@ -520,7 +514,13 @@ window.addEventListener("beforeunload", async function (e) {
|
|
| 520 |
label="🎤 Speak to the AI",
|
| 521 |
show_label=True
|
| 522 |
)
|
|
|
|
| 523 |
record_btn = gr.Button("▶️ Send")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 524 |
gr.Markdown("###Currently Under Development")
|
| 525 |
|
| 526 |
def detect_mood(text):
|
|
|
|
| 22 |
import json
|
| 23 |
from langdetect import detect
|
| 24 |
|
| 25 |
+
def loop_voice_chat(audio_file, history):
|
| 26 |
+
message = transcribe_audio(audio_file)
|
| 27 |
+
if not message.strip():
|
| 28 |
+
return None
|
| 29 |
+
|
| 30 |
+
role = "All rounder"
|
| 31 |
+
use_search = False
|
| 32 |
|
| 33 |
+
chat_out, new_history = chat_with_ai(message, history, role, use_search)
|
| 34 |
+
reply = new_history[-1][1]
|
| 35 |
+
|
| 36 |
+
try:
|
| 37 |
+
lang = detect(reply)
|
| 38 |
+
tts = gTTS(reply, lang=lang)
|
| 39 |
+
except:
|
| 40 |
+
tts = gTTS(reply, lang="en")
|
| 41 |
+
|
| 42 |
+
output_path = f"/tmp/{uuid.uuid4().hex}.mp3"
|
| 43 |
+
tts.save(output_path)
|
| 44 |
+
|
| 45 |
+
return output_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
THEMES = {
|
| 48 |
"Default": "",
|
|
|
|
| 514 |
label="🎤 Speak to the AI",
|
| 515 |
show_label=True
|
| 516 |
)
|
| 517 |
+
ai_audio_out = gr.Audio(type="filepath", autoplay=True, visible=False)
|
| 518 |
record_btn = gr.Button("▶️ Send")
|
| 519 |
+
record_btn.click(
|
| 520 |
+
fn=loop_voice_chat,
|
| 521 |
+
inputs=[mic_input, voice_state],
|
| 522 |
+
outputs=[ai_audio_out]
|
| 523 |
+
)
|
| 524 |
gr.Markdown("###Currently Under Development")
|
| 525 |
|
| 526 |
def detect_mood(text):
|