Spaces:
Runtime error
Runtime error
Madiharehan
commited on
Commit
•
6a73b14
1
Parent(s):
691cb51
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,15 @@
|
|
1 |
# Import necessary libraries
|
2 |
import os
|
3 |
|
4 |
-
#
|
5 |
try:
|
6 |
import whisper
|
7 |
import gtts
|
8 |
import gradio as gr
|
9 |
from groq import Groq
|
10 |
except ImportError:
|
11 |
-
|
|
|
12 |
|
13 |
# Load Whisper model
|
14 |
model = whisper.load_model("base")
|
@@ -25,21 +26,25 @@ client = Groq(api_key=Groq_api_key)
|
|
25 |
|
26 |
# Function to transcribe audio
|
27 |
def transcribe_audio(audio_path):
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
30 |
|
31 |
# Function to get response from Groq's API
|
32 |
def get_groq_response(transcribed_text):
|
33 |
-
|
34 |
-
|
35 |
-
{
|
36 |
"role": "user",
|
37 |
"content": transcribed_text,
|
38 |
-
}
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
43 |
|
44 |
# Function to convert text to speech
|
45 |
def text_to_speech(text):
|
|
|
1 |
# Import necessary libraries
|
2 |
import os
|
3 |
|
4 |
+
# Ensure required libraries are installed
|
5 |
try:
|
6 |
import whisper
|
7 |
import gtts
|
8 |
import gradio as gr
|
9 |
from groq import Groq
|
10 |
except ImportError:
|
11 |
+
print("Required libraries not found. Please install them.")
|
12 |
+
exit(1) # Exit the script if the libraries are not found
|
13 |
|
14 |
# Load Whisper model
|
15 |
model = whisper.load_model("base")
|
|
|
26 |
|
27 |
# Function to transcribe audio
|
28 |
def transcribe_audio(audio_path):
|
29 |
+
try:
|
30 |
+
result = model.transcribe(audio_path)
|
31 |
+
return result["text"]
|
32 |
+
except Exception as e:
|
33 |
+
return f"Error transcribing audio: {str(e)}"
|
34 |
|
35 |
# Function to get response from Groq's API
|
36 |
def get_groq_response(transcribed_text):
|
37 |
+
try:
|
38 |
+
chat_completion = client.chat.completions.create(
|
39 |
+
messages=[{
|
40 |
"role": "user",
|
41 |
"content": transcribed_text,
|
42 |
+
}],
|
43 |
+
model="llama3-8b-8192",
|
44 |
+
)
|
45 |
+
return chat_completion.choices[0].message.content
|
46 |
+
except Exception as e:
|
47 |
+
return f"Error getting response from Groq: {str(e)}"
|
48 |
|
49 |
# Function to convert text to speech
|
50 |
def text_to_speech(text):
|