ONEROCKS commited on
Commit
3d0aef7
·
verified ·
1 Parent(s): 66fae58

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -26
app.py CHANGED
@@ -22,33 +22,27 @@ import torch
22
  import json
23
  from langdetect import detect
24
 
25
- # Mood image URLs
26
- MOOD_IMAGES = {
27
- "happy": "https://i.imgur.com/kY9P9OK.png",
28
- "sad": "https://i.imgur.com/jzddFeQ.png",
29
- "surprised": "https://i.imgur.com/IbO6O7U.png",
30
- "neutral": "https://i.imgur.com/v6BUdZR.png"
31
- }
32
 
33
- def detect_mood(text):
34
- text = text.lower()
35
- if any(word in text for word in ["great", "awesome", "nice", "love", "glad", "happy"]):
36
- return "happy"
37
- elif any(word in text for word in ["sorry", "sad", "unfortunately", "can't", "won't", "not working"]):
38
- return "sad"
39
- elif any(word in text for word in ["what!", "really?", "unbelievable", "wow", "whoa"]):
40
- return "surprised"
41
- else:
42
- return "neutral"
43
-
44
- def download_avatar(url):
45
- response = requests.get(url)
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):