Safwanahmad619 commited on
Commit
c2924bd
1 Parent(s): 8c920d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -59,12 +59,14 @@ import os
59
  import gradio as gr
60
  import whisper
61
  from gtts import gTTS
62
- from groq import Groq
 
63
 
64
- GROQ_API_KEY = os.getenv("GROQ_API_KEY")
65
- if not GROQ_API_KEY:
66
- raise ValueError("GROQ_API_KEY environment variable is not set.")
67
- client = Groq(api_key=GROQ_API_KEY)
 
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 Llama 8B via Groq API
82
  chat_completion = client.chat.completions.create(
83
  messages=[{"role": "user", "content": user_input}],
84
- model="llama3-8b-8192",
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 = tts.write_to_fp(None) # Save the audio to the BytesIO object
 
 
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