Spaces:
Running
Running
File size: 1,118 Bytes
95b33e4 2a650cd 08b8f30 2a650cd 08b8f30 2a650cd 08b8f30 2a650cd 08b8f30 798d835 08b8f30 798d835 95b33e4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
import os
import gradio as gr
from google import genai
from google.genai import types
# Load API key from environment variable
API_KEY = os.getenv("API_KEY")
if not API_KEY:
raise ValueError("API_KEY environment variable is not set")
# Initialize the genai client with API key
client = genai.Client(api_key=API_KEY)
def generate_grounded_response(prompt):
grounding_tool = types.Tool(
google_search=types.GoogleSearch()
)
config = types.GenerateContentConfig(
tools=[grounding_tool]
)
response = client.models.generate_content(
model="gemini-2.5-flash",
contents=prompt,
config=config,
)
return response.text
with gr.Blocks() as demo:
gr.Markdown("# Gemini 2.5 Flash Grounded Content Generator")
prompt_input = gr.Textbox(label="Enter your question or prompt", lines=3, value="Who won the euro 2024?")
generate_btn = gr.Button("Generate Response")
output_text = gr.Textbox(label="Grounded Response", lines=10)
generate_btn.click(fn=generate_grounded_response, inputs=prompt_input, outputs=output_text)
demo.launch()
|