saima730 commited on
Commit
81844ee
·
verified ·
1 Parent(s): a2c4cbf

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -50
app.py DELETED
@@ -1,50 +0,0 @@
1
- !pip install gradio groq openai-whisper gtts
2
-
3
-
4
- import os
5
- import gradio as gr
6
- from groq import Groq
7
- import whisper
8
- from gtts import gTTS
9
- import tempfile
10
-
11
- # Set up Groq API key
12
- GROQ_API_KEY= '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'
13
- groq_client = Groq(api_key=os.environ.get('GROQ_API_KEY'))
14
-
15
- # Load Whisper model
16
- whisper_model = whisper.load_model("base")
17
-
18
- def process_audio(audio_file):
19
- # Transcribe audio using Whisper
20
- result = whisper_model.transcribe(audio_file)
21
- user_text = result['text']
22
-
23
- # Generate response using Llama 8b model with Groq API
24
- chat_completion = groq_client.chat.completions.create(
25
- messages=[
26
- {
27
- "role": "user",
28
- "content": user_text,
29
- }
30
- ],
31
- model="llama3-8b-8192",
32
- )
33
- response_text = chat_completion.choices[0].message.content
34
-
35
- # Convert response text to speech using gTTS
36
- tts = gTTS(text=response_text, lang='en')
37
- audio_file = tempfile.NamedTemporaryFile(delete=False, suffix='.mp3')
38
- tts.save(audio_file.name)
39
-
40
- return response_text, audio_file.name
41
-
42
- # Create Gradio interface
43
- iface = gr.Interface(
44
- fn=process_audio,
45
- inputs=gr.Audio(type="filepath"),
46
- outputs=[gr.Textbox(label="Response"), gr.Audio(label="Response Audio")],
47
- live=True
48
- )
49
-
50
- iface.launch()