Update app.py
Browse files
app.py
CHANGED
|
@@ -71,46 +71,14 @@ def generate(input_text):
|
|
| 71 |
data = clean_json_string(response_text)
|
| 72 |
data = data[:-1]
|
| 73 |
return response_text, ""
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
def generate1(input_text):
|
| 78 |
-
client = genai.Client(
|
| 79 |
-
api_key=os.environ.get("GEMINI_API_KEY"),
|
| 80 |
-
)
|
| 81 |
-
|
| 82 |
-
model = "gemini-3-flash-preview"
|
| 83 |
-
contents = [
|
| 84 |
-
types.Content(
|
| 85 |
-
role="user",
|
| 86 |
-
parts=[
|
| 87 |
-
types.Part.from_text(text=f"return json object with keys name and email. name = {input_text} search the web for the email value. return json object only, no additional text or comments"),
|
| 88 |
-
],
|
| 89 |
-
),
|
| 90 |
-
]
|
| 91 |
-
tools = [
|
| 92 |
-
types.Tool(googleSearchRetrieval=types.DynamicRetrievalConfig(dynamicThreshold=0.3, mode=types.DynamicRetrievalConfigMode.MODE_DYNAMIC)),
|
| 93 |
-
]
|
| 94 |
-
generate_content_config = types.GenerateContentConfig(
|
| 95 |
-
temperature=0.45,
|
| 96 |
-
tools=tools,
|
| 97 |
-
response_mime_type="text/plain",
|
| 98 |
-
)
|
| 99 |
-
|
| 100 |
-
for chunk in client.models.generate_content_stream(
|
| 101 |
-
model=model,
|
| 102 |
-
contents=contents,
|
| 103 |
-
config=generate_content_config,
|
| 104 |
-
):
|
| 105 |
-
print(chunk.text, end="")
|
| 106 |
-
|
| 107 |
|
| 108 |
if __name__ == '__main__':
|
| 109 |
|
| 110 |
with gr.Blocks() as demo:
|
| 111 |
title=gr.Markdown("# Gemini 2.0 Flash + Websearch")
|
| 112 |
output_textbox = gr.Markdown()
|
| 113 |
-
input_textbox = gr.Textbox(lines=3, label="", placeholder="Enter
|
| 114 |
submit_button = gr.Button("send")
|
| 115 |
submit_button.click(fn=generate,inputs=input_textbox,outputs=[output_textbox, input_textbox])
|
| 116 |
demo.launch(show_error=True)
|
|
|
|
| 71 |
data = clean_json_string(response_text)
|
| 72 |
data = data[:-1]
|
| 73 |
return response_text, ""
|
| 74 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
if __name__ == '__main__':
|
| 77 |
|
| 78 |
with gr.Blocks() as demo:
|
| 79 |
title=gr.Markdown("# Gemini 2.0 Flash + Websearch")
|
| 80 |
output_textbox = gr.Markdown()
|
| 81 |
+
input_textbox = gr.Textbox(lines=3, label="", placeholder="Enter message here...")
|
| 82 |
submit_button = gr.Button("send")
|
| 83 |
submit_button.click(fn=generate,inputs=input_textbox,outputs=[output_textbox, input_textbox])
|
| 84 |
demo.launch(show_error=True)
|