admin08077 commited on
Commit
08b8f30
·
verified ·
1 Parent(s): 2a650cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -36
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
- # Initialize client with API key from env var
7
- client = genai.Client()
 
 
8
 
9
- def generate_video(prompt):
10
- operation = client.models.generate_videos(
11
- model="veo-3.0-generate-preview",
12
- prompt=prompt,
 
 
 
 
 
 
13
  )
14
 
15
- while not operation.done:
16
- print("Waiting for video generation to complete...")
17
- time.sleep(10)
18
- operation = client.operations.get(operation)
19
-
20
- generated_video = operation.response.generated_videos[0]
21
- # Download video bytes
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 Veo Video Generator")
33
- prompt_input = gr.Textbox(label="Video Prompt", value="""A close up of two people staring at a cryptic drawing on a wall, torchlight flickering.
34
- A man murmurs, 'This must be it. That's the secret code.' The woman looks at him and whispering excitedly, 'What did you find?'""")
35
- generate_btn = gr.Button("Generate Video")
36
- video_output = gr.Video(label="Generated Video")
37
- status = gr.Textbox(label="Status")
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()