Update app.py
Browse files
app.py
CHANGED
|
@@ -22,27 +22,6 @@ import torch
|
|
| 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": "",
|
|
@@ -516,33 +495,9 @@ window.addEventListener("beforeunload", async function (e) {
|
|
| 516 |
)
|
| 517 |
ai_audio_out = gr.Audio(type="filepath", autoplay=True, visible=False)
|
| 518 |
record_btn = gr.Button("▶️ Send")
|
| 519 |
-
|
| 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):
|
| 527 |
-
text = text.lower()
|
| 528 |
-
if any(word in text for word in ["great", "awesome", "nice", "love", "glad", "happy"]):
|
| 529 |
-
return "happy"
|
| 530 |
-
elif any(word in text for word in ["sorry", "sad", "unfortunately", "can't", "won't", "not working"]):
|
| 531 |
-
return "sad"
|
| 532 |
-
elif any(word in text for word in ["what!", "really?", "unbelievable", "wow", "whoa"]):
|
| 533 |
-
return "surprised"
|
| 534 |
-
else:
|
| 535 |
-
return "neutral"
|
| 536 |
-
|
| 537 |
-
def download_avatar(url):
|
| 538 |
-
response = requests.get(url)
|
| 539 |
-
if response.status_code == 200:
|
| 540 |
-
path = f"/tmp/{uuid.uuid4().hex}.png"
|
| 541 |
-
with open(path, "wb") as f:
|
| 542 |
-
f.write(response.content)
|
| 543 |
-
return path
|
| 544 |
-
return None
|
| 545 |
-
|
| 546 |
def loop_voice_chat(audio_file, history):
|
| 547 |
message = transcribe_audio(audio_file)
|
| 548 |
if not message.strip():
|
|
@@ -559,15 +514,16 @@ window.addEventListener("beforeunload", async function (e) {
|
|
| 559 |
tts = gTTS(reply, lang=lang)
|
| 560 |
except:
|
| 561 |
tts = gTTS(reply, lang="en")
|
|
|
|
| 562 |
output_path = f"/tmp/{uuid.uuid4().hex}.mp3"
|
| 563 |
tts.save(output_path)
|
| 564 |
|
| 565 |
-
return output_path
|
| 566 |
|
| 567 |
record_btn.click(
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
)
|
| 572 |
|
| 573 |
with gr.Tab("Settings"):
|
|
|
|
| 22 |
import json
|
| 23 |
from langdetect import detect
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
THEMES = {
|
| 27 |
"Default": "",
|
|
|
|
| 495 |
)
|
| 496 |
ai_audio_out = gr.Audio(type="filepath", autoplay=True, visible=False)
|
| 497 |
record_btn = gr.Button("▶️ Send")
|
| 498 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 499 |
gr.Markdown("###Currently Under Development")
|
| 500 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 501 |
def loop_voice_chat(audio_file, history):
|
| 502 |
message = transcribe_audio(audio_file)
|
| 503 |
if not message.strip():
|
|
|
|
| 514 |
tts = gTTS(reply, lang=lang)
|
| 515 |
except:
|
| 516 |
tts = gTTS(reply, lang="en")
|
| 517 |
+
|
| 518 |
output_path = f"/tmp/{uuid.uuid4().hex}.mp3"
|
| 519 |
tts.save(output_path)
|
| 520 |
|
| 521 |
+
return output_path
|
| 522 |
|
| 523 |
record_btn.click(
|
| 524 |
+
fn=loop_voice_chat,
|
| 525 |
+
inputs=[mic_input, voice_state],
|
| 526 |
+
outputs=[ai_audio_out]
|
| 527 |
)
|
| 528 |
|
| 529 |
with gr.Tab("Settings"):
|