ONEROCKS commited on
Commit
2de2ab1
·
verified ·
1 Parent(s): 3ca7f0c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -57
app.py CHANGED
@@ -21,52 +21,6 @@ from PIL import Image
21
  import torch
22
  import json
23
  from langdetect import detect
24
- from moviepy.editor import AudioFileClip, ImageClip
25
-
26
- # Replace this with your avatar image path (static face)
27
- AVATAR_IMAGE = "avatar.png"
28
-
29
- # Function to simulate lip-sync video with static face
30
- def generate_lip_sync_video(face_img_path, audio_path):
31
- duration = AudioFileClip(audio_path).duration
32
- video_path = f"/tmp/wav2lip_{uuid.uuid4().hex}.mp4"
33
- clip = ImageClip(face_img_path).set_duration(duration).set_audio(AudioFileClip(audio_path))
34
- clip.write_videofile(video_path, fps=24, codec='libx264', audio_codec='aac', verbose=False, logger=None)
35
- return video_path
36
-
37
- # Transcribe the user's speech
38
- def transcribe(audio_path):
39
- recognizer = sr.Recognizer()
40
- with sr.AudioFile(audio_path) as source:
41
- audio = recognizer.record(source)
42
- try:
43
- return recognizer.recognize_google(audio)
44
- except Exception as e:
45
- return f"Error: {e}"
46
-
47
- # Dummy AI response (replace with OpenRouter call if needed)
48
- def ai_response(text):
49
- return f"You said: {text}. Hello from your AI!"
50
-
51
- # Generate audio reply using gTTS
52
- def synthesize_reply(text):
53
- tts = gTTS(text)
54
- audio_path = f"/tmp/tts_{uuid.uuid4().hex}.mp3"
55
- tts.save(audio_path)
56
- return audio_path
57
-
58
- # Complete pipeline
59
- def voice_to_avatar(audio_path):
60
- transcription = transcribe(audio_path)
61
- if transcription.startswith("Error"):
62
- return transcription, None
63
- reply = ai_response(transcription)
64
- tts_audio = synthesize_reply(reply)
65
- video = generate_lip_sync_video(AVATAR_IMAGE, tts_audio)
66
- return reply, video
67
-
68
-
69
-
70
 
71
  THEMES = {
72
  "Default": "",
@@ -526,17 +480,7 @@ window.addEventListener("beforeunload", async function (e) {
526
  </style>
527
  <div id="neon-text">PR1ME</div>
528
  """)
529
- with gr.Tab("Live Mod"):
530
- with gr.Blocks() as demo:
531
- gr.Markdown("## 🧠 AI Voice Chat with Lip-Sync Avatar\nSpeak and watch the AI reply through an animated avatar.")
532
-
533
- audio_input = gr.Audio(source="microphone", type="filepath", label="🎙️ Your Voice")
534
- response_text = gr.Textbox(label="🗣️ AI Response")
535
- video_output = gr.Video(label="🧑‍🎤 Talking Avatar")
536
-
537
- audio_input.change(fn=voice_to_avatar, inputs=audio_input, outputs=[response_text, video_output])
538
-
539
- gr.Markdown("⚠️ This version uses a static avatar image and fake lip sync. Replace with Wav2Lip for realism.")
540
 
541
  with gr.Tab("Settings"):
542
  gr.Markdown("## App Settings")
 
21
  import torch
22
  import json
23
  from langdetect import detect
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  THEMES = {
26
  "Default": "",
 
480
  </style>
481
  <div id="neon-text">PR1ME</div>
482
  """)
483
+
 
 
 
 
 
 
 
 
 
 
484
 
485
  with gr.Tab("Settings"):
486
  gr.Markdown("## App Settings")