Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,47 +1,40 @@
|
|
| 1 |
import os
|
| 2 |
-
import time
|
| 3 |
import gradio as gr
|
| 4 |
from google import genai
|
|
|
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
)
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
video_file = client.files.download(file=generated_video.video)
|
| 23 |
-
|
| 24 |
-
# Save locally
|
| 25 |
-
video_path = "dialogue_example.mp4"
|
| 26 |
-
with open(video_path, "wb") as f:
|
| 27 |
-
f.write(video_file)
|
| 28 |
-
|
| 29 |
-
return video_path
|
| 30 |
|
| 31 |
with gr.Blocks() as demo:
|
| 32 |
-
gr.Markdown("# Gemini
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
generate_btn = gr.Button("Generate
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
def on_generate(prompt):
|
| 40 |
-
status.update("Generating video, please wait...")
|
| 41 |
-
video_path = generate_video(prompt)
|
| 42 |
-
status.update("Generation complete!")
|
| 43 |
-
return video_path, "Generation complete!"
|
| 44 |
-
|
| 45 |
-
generate_btn.click(on_generate, inputs=prompt_input, outputs=[video_output, status])
|
| 46 |
|
| 47 |
demo.launch()
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from google import genai
|
| 4 |
+
from google.genai import types
|
| 5 |
|
| 6 |
+
# Load API key from environment variable
|
| 7 |
+
API_KEY = os.getenv("API_KEY")
|
| 8 |
+
if not API_KEY:
|
| 9 |
+
raise ValueError("API_KEY environment variable is not set")
|
| 10 |
|
| 11 |
+
# Initialize the genai client with API key
|
| 12 |
+
client = genai.Client(api_key=API_KEY)
|
| 13 |
+
|
| 14 |
+
def generate_grounded_response(prompt):
|
| 15 |
+
grounding_tool = types.Tool(
|
| 16 |
+
google_search=types.GoogleSearch()
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
config = types.GenerateContentConfig(
|
| 20 |
+
tools=[grounding_tool]
|
| 21 |
)
|
| 22 |
|
| 23 |
+
response = client.models.generate_content(
|
| 24 |
+
model="gemini-2.5-flash",
|
| 25 |
+
contents=prompt,
|
| 26 |
+
config=config,
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
return response.text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
with gr.Blocks() as demo:
|
| 32 |
+
gr.Markdown("# Gemini 2.5 Flash Grounded Content Generator")
|
| 33 |
+
|
| 34 |
+
prompt_input = gr.Textbox(label="Enter your question or prompt", lines=3, value="Who won the euro 2024?")
|
| 35 |
+
generate_btn = gr.Button("Generate Response")
|
| 36 |
+
output_text = gr.Textbox(label="Grounded Response", lines=10)
|
| 37 |
+
|
| 38 |
+
generate_btn.click(fn=generate_grounded_response, inputs=prompt_input, outputs=output_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
demo.launch()
|