Wiuhh commited on
Commit
ee4f1b7
·
verified ·
1 Parent(s): c54e0e4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from dotenv import load_dotenv
3
+
4
+ # Load .env locally (Spaces will use Secrets, but this helps local dev)
5
+ load_dotenv()
6
+
7
+ import gradio as gr
8
+ from veo_vid import generate_video
9
+
10
+ def make_ui():
11
+ with gr.Blocks(title="Veo Video Generator") as demo:
12
+ gr.Markdown("# Veo Video Generator\nEnter a prompt and generate a short video using the Veo model.")
13
+
14
+ with gr.Row():
15
+ prompt = gr.Textbox(
16
+ label="Prompt",
17
+ value="A high-end fashion ad showing a confident male model in a new dark blue suit sprinting down a professional runway.",
18
+ lines=4,
19
+ placeholder="Describe the video you want..."
20
+ )
21
+ with gr.Row():
22
+ generate_btn = gr.Button("Generate Video")
23
+ status = gr.Textbox(value="", label="Status", interactive=False)
24
+ video_output = gr.Video(label="Generated Video", value=None)
25
+
26
+ def on_generate(prompt_text):
27
+ # Quick pre-check
28
+ api_key = os.getenv("GOOGLE_API_KEY")
29
+ if not api_key:
30
+ return "Missing GOOGLE_API_KEY — set it in your Space secrets.", None
31
+
32
+ # Inform user
33
+ try:
34
+ status_msg = "Starting generation..."
35
+ # Update status immediately (Gradio will show returned status)
36
+ # Call the shared generation function from veo_vid.py
37
+ video_path = generate_video(prompt_text)
38
+ status_msg = "Generation finished."
39
+ # return (status_text, video_path)
40
+ return status_msg, video_path
41
+ except Exception as e:
42
+ # Return error to status box
43
+ return f"Error: {e}", None
44
+
45
+ generate_btn.click(fn=on_generate, inputs=prompt, outputs=[status, video_output])
46
+
47
+ return demo
48
+
49
+ app = make_ui()
50
+
51
+ # For Hugging Face Spaces just call launch without host/port.
52
+ if __name__ == "__main__":
53
+ app.launch()