Rohannk commited on
Commit
41e9fec
·
verified ·
1 Parent(s): 98488d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -15
app.py CHANGED
@@ -1,27 +1,22 @@
1
  import os
2
  import gradio as gr
3
  import whisper
4
- import google.generativeai as genai
5
 
6
- # Configure Gemini
7
- genai.configure(
8
- api_key=os.getenv("GEMINI_API_KEY")
 
9
  )
10
 
11
  # Load Whisper model
12
  speech_model = whisper.load_model("tiny")
13
 
14
- # Load Gemini model
15
- ai_model = genai.GenerativeModel(
16
- "gemini-2.0-flash"
17
- )
18
-
19
- # Main function
20
  def voice_assistant(audio):
21
 
22
- # Check if audio exists
23
  if audio is None:
24
- return "Please record your voice first."
25
 
26
  try:
27
  # Convert speech to text
@@ -29,10 +24,20 @@ def voice_assistant(audio):
29
 
30
  user_text = result["text"]
31
 
32
- # Gemini response
33
- response = ai_model.generate_content(user_text)
 
 
 
 
 
 
 
 
 
 
34
 
35
- return f"You said: {user_text}\n\nAI: {response.text}"
36
 
37
  except Exception as e:
38
  return f"Error: {str(e)}"
 
1
  import os
2
  import gradio as gr
3
  import whisper
4
+ from openai import OpenAI
5
 
6
+ # OpenRouter client
7
+ client = OpenAI(
8
+ api_key=os.getenv("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"),
9
+ base_url="https://openrouter.ai/api/v1"
10
  )
11
 
12
  # Load Whisper model
13
  speech_model = whisper.load_model("tiny")
14
 
15
+ # Voice assistant function
 
 
 
 
 
16
  def voice_assistant(audio):
17
 
 
18
  if audio is None:
19
+ return "Please record audio first."
20
 
21
  try:
22
  # Convert speech to text
 
24
 
25
  user_text = result["text"]
26
 
27
+ # AI response from OpenRouter
28
+ completion = client.chat.completions.create(
29
+ model="openai/gpt-oss-120b:free",
30
+ messages=[
31
+ {
32
+ "role": "user",
33
+ "content": user_text
34
+ }
35
+ ]
36
+ )
37
+
38
+ ai_reply = completion.choices[0].message.content
39
 
40
+ return f"You said: {user_text}\n\nAI: {ai_reply}"
41
 
42
  except Exception as e:
43
  return f"Error: {str(e)}"