Spaces:
Running
Running
Ifeanyi
commited on
Commit
·
345eb49
1
Parent(s):
c4d954a
Application files
Browse files- app.py +15 -0
- geminisearch.py +32 -0
- requirements.txt +2 -0
app.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=300),
|
6 |
+
type = "messages",
|
7 |
+
textbox=gr.Textbox(placeholder="Search the web", container=False, scale=7),
|
8 |
+
title="Gemini Web Search",
|
9 |
+
theme="ocean",
|
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,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
combined_prompt = f"Current information: {history}\n\nQuestion: {prompt}"
|
18 |
+
|
19 |
+
response = client.models.generate_content(
|
20 |
+
model=model_id,
|
21 |
+
contents=combined_prompt,
|
22 |
+
config=GenerateContentConfig(
|
23 |
+
tools=[google_search_tool],
|
24 |
+
response_modalities=["TEXT"],
|
25 |
+
)
|
26 |
+
)
|
27 |
+
|
28 |
+
# stream response
|
29 |
+
for each in response.candidates[0].content.parts:
|
30 |
+
for i in range(len(each.text)):
|
31 |
+
time.sleep(0.001)
|
32 |
+
yield each.text[: i+1]
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
google
|
2 |
+
gradio
|