mgokg commited on
Commit
d44f598
·
verified ·
1 Parent(s): bbf9a20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -3
app.py CHANGED
@@ -16,6 +16,7 @@ from fastrtc import (
16
  wait_for_item,
17
  )
18
  from google import genai
 
19
  from gradio.utils import get_space
20
  from PIL import Image
21
 
@@ -61,7 +62,29 @@ class GeminiHandler(AsyncAudioVideoStreamHandler):
61
  client = genai.Client(
62
  api_key=os.getenv("GEMINI_API_KEY"), http_options={"api_version": "v1alpha"}
63
  )
64
- config = {"response_modalities": ["AUDIO"]}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  async with client.aio.live.connect(
66
  model="gemini-2.0-flash-exp",
67
  config=config, # type: ignore
@@ -146,7 +169,7 @@ with gr.Blocks(css=css) as demo:
146
  <h1>Gen AI Voice Chat</h1>
147
  <p>real-time audio streaming</p>
148
  </center>
149
- </div>
150
  """
151
  )
152
  with gr.Row() as row:
@@ -183,4 +206,4 @@ if __name__ == "__main__":
183
  elif mode == "PHONE":
184
  raise ValueError("Phone mode not supported for this demo")
185
  else:
186
- stream.ui.launch(server_port=7860)
 
16
  wait_for_item,
17
  )
18
  from google import genai
19
+ from google.genai import types # Import the types module
20
  from gradio.utils import get_space
21
  from PIL import Image
22
 
 
62
  client = genai.Client(
63
  api_key=os.getenv("GEMINI_API_KEY"), http_options={"api_version": "v1alpha"}
64
  )
65
+
66
+ # Define the tools and system instruction
67
+ tools = [
68
+ types.Tool(google_search=types.GoogleSearch()),
69
+ ]
70
+
71
+ system_instruction = types.Content(
72
+ parts=[types.Part.from_text(text="you are a helpful assistant")],
73
+ role="user"
74
+ )
75
+
76
+ # Update the config to include tools and system_instruction
77
+ config = types.LiveConnectConfig(
78
+ response_modalities=["AUDIO"],
79
+ speech_config=types.SpeechConfig(
80
+ voice_config=types.VoiceConfig(
81
+ prebuilt_voice_config=types.PrebuiltVoiceConfig(voice_name="Leda")
82
+ )
83
+ ),
84
+ tools=tools,
85
+ system_instruction=system_instruction,
86
+ )
87
+
88
  async with client.aio.live.connect(
89
  model="gemini-2.0-flash-exp",
90
  config=config, # type: ignore
 
169
  <h1>Gen AI Voice Chat</h1>
170
  <p>real-time audio streaming</p>
171
  </center>
172
+ </div>
173
  """
174
  )
175
  with gr.Row() as row:
 
206
  elif mode == "PHONE":
207
  raise ValueError("Phone mode not supported for this demo")
208
  else:
209
+ stream.ui.launch(server_port=7860)