rizwanaidris2 commited on
Commit
47116a8
·
verified ·
1 Parent(s): eb9fc70

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -57
app.py CHANGED
@@ -1,60 +1,3 @@
1
- # Import libraries
2
- # Import libraries
3
- import whisper
4
- import os
5
- from gtts import gTTS
6
- import gradio as gr
7
- from groq import Groq
8
-
9
-
10
- # Load Whisper model for transcription
11
- model = whisper.load_model("base")
12
-
13
- # Set up Groq API client (ensure GROQ_API_KEY is set in your environment)
14
-
15
- GROQ_API_KEY = "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"
16
- client = Groq(api_key=GROQ_API_KEY)
17
- # Function to get the LLM response from Groq
18
- def get_llm_response(user_input):
19
- chat_completion = client.chat.completions.create(
20
- messages=[{"role": "user", "content": user_input}],
21
- model="llama3-8b-8192", # Replace with your desired model
22
- )
23
- return chat_completion.choices[0].message.content
24
-
25
- # Function to convert text to speech using gTTS
26
- def text_to_speech(text, output_audio="output_audio.mp3"):
27
- tts = gTTS(text)
28
- tts.save(output_audio)
29
- return output_audio
30
-
31
- # Main chatbot function to handle audio input and output
32
- def chatbot(audio):
33
- # Step 1: Transcribe the audio using Whisper
34
- result = model.transcribe(audio)
35
- user_text = result["text"]
36
-
37
- # Step 2: Get LLM response from Groq
38
- response_text = get_llm_response(user_text)
39
-
40
- # Step 3: Convert the response text to speech
41
- output_audio = text_to_speech(response_text)
42
-
43
- return response_text, output_audio
44
-
45
- # Gradio interface for real-time interaction
46
- iface = gr.Interface(
47
- fn=chatbot,
48
- inputs=gr.Audio(type="filepath"), # Input from mic
49
- outputs=[gr.Textbox(), gr.Audio(type="filepath")], # Output: response text and audio
50
- live=True
51
- )
52
-
53
- # Launch the Gradio app
54
- iface.launch()
55
-
56
-
57
-
58
  # Import libraries
59
  import whisper
60
  import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # Import libraries
2
  import whisper
3
  import os