Rohannk commited on
Commit
401c8ca
·
verified ·
1 Parent(s): 98e0bdf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -68
app.py CHANGED
@@ -1,91 +1,34 @@
 
1
  import gradio as gr
2
  import whisper
3
  import google.generativeai as genai
4
 
5
- # Gemini API
6
- genai.configure(api_key="import gradio as gr
7
- import whisper
8
- import google.generativeai as genai
9
-
10
- # Gemini API
11
- genai.configure(api_key="import gradio as gr
12
- import whisper
13
- import google.generativeai as genai
14
-
15
- # Gemini API
16
- genai.configure(api_key="AIzaSyABCcQc7tbhSRH-QE1hwgTFgncC5RcANoU")
17
-
18
- # Load models
19
- speech_model = whisper.load_model("base")
20
- ai_model = genai.GenerativeModel("gemini-1.5-flash")
21
-
22
- def voice_assistant(audio):
23
-
24
- # Speech to text
25
- result = speech_model.transcribe(audio)
26
-
27
- user_text = result["text"]
28
-
29
- # Gemini response
30
- response = ai_model.generate_content(user_text)
31
-
32
- return f"You said: {user_text}\n\nAI: {response.text}"
33
-
34
- # Gradio UI
35
- interface = gr.Interface(
36
- fn=voice_assistant,
37
- inputs=gr.Audio(type="filepath"),
38
- outputs="text",
39
- title="AI Voice Assistant",
40
- description="Speak and get AI responses"
41
  )
42
 
43
- interface.launch()")
44
-
45
  # Load models
46
- speech_model = whisper.load_model("base")
47
- ai_model = genai.GenerativeModel("gemini-1.5-flash")
48
-
49
- def voice_assistant(audio):
50
-
51
- # Speech to text
52
- result = speech_model.transcribe(audio)
53
-
54
- user_text = result["text"]
55
-
56
- # Gemini response
57
- response = ai_model.generate_content(user_text)
58
 
59
- return f"You said: {user_text}\n\nAI: {response.text}"
60
-
61
- # Gradio UI
62
- interface = gr.Interface(
63
- fn=voice_assistant,
64
- inputs=gr.Audio(type="filepath"),
65
- outputs="text",
66
- title="AI Voice Assistant",
67
- description="Speak and get AI responses"
68
  )
69
 
70
- interface.launch()")
71
-
72
- # Load models
73
- speech_model = whisper.load_model("base")
74
- ai_model = genai.GenerativeModel("gemini-1.5-flash")
75
-
76
  def voice_assistant(audio):
77
 
78
- # Speech to text
79
  result = speech_model.transcribe(audio)
80
 
81
  user_text = result["text"]
82
 
83
- # Gemini response
84
  response = ai_model.generate_content(user_text)
85
 
86
  return f"You said: {user_text}\n\nAI: {response.text}"
87
 
88
- # Gradio UI
89
  interface = gr.Interface(
90
  fn=voice_assistant,
91
  inputs=gr.Audio(type="filepath"),
 
1
+ import os
2
  import gradio as gr
3
  import whisper
4
  import google.generativeai as genai
5
 
6
+ # Configure Gemini API
7
+ genai.configure(
8
+ api_key=os.getenv("AIzaSyABCcQc7tbhSRH-QE1hwgTFgncC5RcANoU")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  )
10
 
 
 
11
  # Load models
12
+ speech_model = whisper.load_model("tiny")
 
 
 
 
 
 
 
 
 
 
 
13
 
14
+ ai_model = genai.GenerativeModel(
15
+ "gemini-1.5-flash"
 
 
 
 
 
 
 
16
  )
17
 
18
+ # Main function
 
 
 
 
 
19
  def voice_assistant(audio):
20
 
21
+ # Convert speech to text
22
  result = speech_model.transcribe(audio)
23
 
24
  user_text = result["text"]
25
 
26
+ # Generate AI response
27
  response = ai_model.generate_content(user_text)
28
 
29
  return f"You said: {user_text}\n\nAI: {response.text}"
30
 
31
+ # Gradio interface
32
  interface = gr.Interface(
33
  fn=voice_assistant,
34
  inputs=gr.Audio(type="filepath"),