siyah1 commited on
Commit
3813680
·
verified ·
1 Parent(s): 4df2d45

Upload 3 files

Browse files
Files changed (3) hide show
  1. app (1).py +15 -0
  2. geminisearch.py +42 -0
  3. requirements (2).txt +3 -0
app (1).py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from geminisearch import webSearch
3
+
4
+ app = gr.ChatInterface(webSearch,
5
+ chatbot=gr.Chatbot(height=400),
6
+ type = "messages",
7
+ textbox=gr.Textbox(placeholder="Chat the web", container=False, scale=7),
8
+ title="Gemini Web Chat",
9
+ theme="upsatwal/mlsc_tiet",
10
+ examples=["What is the current weather in Paris",
11
+ "What is the current exchange rate between USD and EUR",
12
+ "What is the current price of Bitcoin"])
13
+
14
+ if __name__ == "__main__":
15
+ app.launch(mcp_server=True)
geminisearch.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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,history):
16
+ """
17
+ Searches the web using Google Search.
18
+
19
+ Args:
20
+ prompt: A string representing the search query
21
+ history: A placeholder representing query history
22
+
23
+ Returns:
24
+ Search results in natural language.
25
+ """
26
+
27
+ combined_prompt = f"Current information: \n\nQuestion: {prompt}"
28
+
29
+ response = client.models.generate_content(
30
+ model=model_id,
31
+ contents=combined_prompt,
32
+ config=GenerateContentConfig(
33
+ tools=[google_search_tool],
34
+ response_modalities=["TEXT"],
35
+ )
36
+ )
37
+
38
+ # stream response
39
+ for each in response.candidates[0].content.parts:
40
+ for i in range(len(each.text)):
41
+ time.sleep(0.001)
42
+ yield each.text[: i+1]
requirements (2).txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ google-genai
2
+ gradio==5.29.0
3
+ gradio[mcp]