Talha812 commited on
Commit
4f0d39e
·
verified ·
1 Parent(s): eb62234

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import whisper
3
+ from groq import Groq
4
+ from TTS.api import TTS
5
+ import torch
6
+ import os
7
+
8
+ # Load models
9
+ whisper_model = whisper.load_model("base")
10
+ tts_model = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False, gpu=torch.cuda.is_available())
11
+ groq_client = Groq(api_key="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")
12
+
13
+ # Core pipeline
14
+ def voice_to_voice(audio):
15
+ # Transcribe
16
+ transcription = whisper_model.transcribe(audio)["text"]
17
+
18
+ # Generate response from Groq
19
+ response = groq_client.chat.completions.create(
20
+ messages=[{"role": "user", "content": transcription}],
21
+ model="llama3-70b-8192",
22
+ )
23
+ groq_text = response.choices[0].message.content
24
+
25
+ # Convert to speech
26
+ output_path = "response.wav"
27
+ tts_model.tts_to_file(text=groq_text, file_path=output_path)
28
+
29
+ return groq_text, output_path
30
+
31
+ # Gradio Interface
32
+ iface = gr.Interface(
33
+ fn=voice_to_voice,
34
+ inputs=gr.Audio(source="microphone", type="filepath", label="🎙️ Speak your question"),
35
+ outputs=[
36
+ gr.Textbox(label="📝 Groq Answer"),
37
+ gr.Audio(label="🎧 AI Voice Reply"),
38
+ ],
39
+ title="🎤 Voice Chat with Groq (LLaMA 3)",
40
+ description="Speak your question. Whisper will transcribe it, Groq will answer it, and TTS will reply in voice.",
41
+ live=False,
42
+ )
43
+
44
+ iface.launch()