deep-div commited on
Commit
e87a98f
·
verified ·
1 Parent(s): fc7b6df

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +18 -0
  2. geminisearch.py +39 -0
  3. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from geminisearch import webSearch
3
+
4
+ with gr.Blocks(
5
+ theme = "upsatwal/mlsc_tiet"
6
+ ) as app:
7
+ gr.HTML("<div style='text-align:center;'><h1><strong>Gemini Web Search</strong></h1></div>")
8
+ gr.HTML("<div style='text-align:center;'><h3><strong>Search the web for information</strong></h3></div>")
9
+ with gr.Column():
10
+ input = gr.Textbox(label="Query Field",placeholder="Type in your search query")
11
+ btn = gr.Button("Google Search")
12
+ gr.HTML("<div style='text-align:center;'><h3><strong>Google Search Result</strong></h3></div>")
13
+ output = gr.Markdown()
14
+
15
+ btn.click(webSearch, inputs=[input], outputs=output)
16
+
17
+ if __name__ == "__main__":
18
+ app.launch(mcp_server=True)
geminisearch.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from google import genai
2
+ from google.genai.types import Tool, GenerateContentConfig, GoogleSearch
3
+ import time
4
+ import os
5
+
6
+ api_key = os.getenv("GEMINI_API_KEY")
7
+ client = genai.Client(api_key=api_key)
8
+
9
+ model_id = "gemini-2.0-flash"
10
+
11
+ google_search_tool = Tool(
12
+ google_search = GoogleSearch()
13
+ )
14
+
15
+ def webSearch(prompt):
16
+ """
17
+ Searches the web using Google Search.
18
+
19
+ Args:
20
+ prompt: A string representing the search query
21
+
22
+ Returns:
23
+ Search results in natural language.
24
+ """
25
+
26
+ response = client.models.generate_content(
27
+ model=model_id,
28
+ contents=prompt,
29
+ config=GenerateContentConfig(
30
+ tools=[google_search_tool],
31
+ response_modalities=["TEXT"],
32
+ )
33
+ )
34
+
35
+ # stream response
36
+ for each in response.candidates[0].content.parts:
37
+ for i in range(len(each.text)):
38
+ time.sleep(0.001)
39
+ yield each.text[: i+1]
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ google-genai
2
+ gradio==5.29.0
3
+ gradio[mcp]