Spaces:
Sleeping
Sleeping
Safwanahmad619
commited on
Commit
•
c2924bd
1
Parent(s):
8c920d0
Update app.py
Browse files
app.py
CHANGED
@@ -59,12 +59,14 @@ import os
|
|
59 |
import gradio as gr
|
60 |
import whisper
|
61 |
from gtts import gTTS
|
62 |
-
from
|
|
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
68 |
|
69 |
# Load Whisper model
|
70 |
model = whisper.load_model("base")
|
@@ -78,16 +80,18 @@ def chatbot(audio=None):
|
|
78 |
transcription = model.transcribe(audio)
|
79 |
user_input = transcription.get("text", "")
|
80 |
|
81 |
-
# Generate a response using
|
82 |
chat_completion = client.chat.completions.create(
|
83 |
messages=[{"role": "user", "content": user_input}],
|
84 |
-
model="
|
85 |
)
|
86 |
response_text = chat_completion.choices[0].message.content
|
87 |
|
88 |
# Convert the response text to speech using gTTS
|
89 |
tts = gTTS(text=response_text, lang='en')
|
90 |
-
response_audio_io =
|
|
|
|
|
91 |
|
92 |
return response_text, response_audio_io
|
93 |
|
|
|
59 |
import gradio as gr
|
60 |
import whisper
|
61 |
from gtts import gTTS
|
62 |
+
from gemani import Gemani # Assuming you have a Gemani client similar to Groq
|
63 |
+
import io # Import io for BytesIO
|
64 |
|
65 |
+
# Get the Gemani API key from environment variables
|
66 |
+
GEMANI_API_KEY = os.getenv("GEMANI_API_KEY")
|
67 |
+
if not GEMANI_API_KEY:
|
68 |
+
raise ValueError("GEMANI_API_KEY environment variable is not set.")
|
69 |
+
client = Gemani(api_key=GEMANI_API_KEY) # Initialize the Gemani client
|
70 |
|
71 |
# Load Whisper model
|
72 |
model = whisper.load_model("base")
|
|
|
80 |
transcription = model.transcribe(audio)
|
81 |
user_input = transcription.get("text", "")
|
82 |
|
83 |
+
# Generate a response using Gemani API
|
84 |
chat_completion = client.chat.completions.create(
|
85 |
messages=[{"role": "user", "content": user_input}],
|
86 |
+
model="gemani-model-8b", # Replace with the correct model name for Gemani
|
87 |
)
|
88 |
response_text = chat_completion.choices[0].message.content
|
89 |
|
90 |
# Convert the response text to speech using gTTS
|
91 |
tts = gTTS(text=response_text, lang='en')
|
92 |
+
response_audio_io = io.BytesIO() # Create a BytesIO object
|
93 |
+
tts.save(response_audio_io) # Save the audio to the BytesIO object
|
94 |
+
response_audio_io.seek(0) # Rewind the BytesIO object
|
95 |
|
96 |
return response_text, response_audio_io
|
97 |
|