Hh / app.py
Wiuhh's picture
Create app.py
ee4f1b7 verified
import os
from dotenv import load_dotenv
# Load .env locally (Spaces will use Secrets, but this helps local dev)
load_dotenv()
import gradio as gr
from veo_vid import generate_video
def make_ui():
with gr.Blocks(title="Veo Video Generator") as demo:
gr.Markdown("# Veo Video Generator\nEnter a prompt and generate a short video using the Veo model.")
with gr.Row():
prompt = gr.Textbox(
label="Prompt",
value="A high-end fashion ad showing a confident male model in a new dark blue suit sprinting down a professional runway.",
lines=4,
placeholder="Describe the video you want..."
)
with gr.Row():
generate_btn = gr.Button("Generate Video")
status = gr.Textbox(value="", label="Status", interactive=False)
video_output = gr.Video(label="Generated Video", value=None)
def on_generate(prompt_text):
# Quick pre-check
api_key = os.getenv("GOOGLE_API_KEY")
if not api_key:
return "Missing GOOGLE_API_KEY — set it in your Space secrets.", None
# Inform user
try:
status_msg = "Starting generation..."
# Update status immediately (Gradio will show returned status)
# Call the shared generation function from veo_vid.py
video_path = generate_video(prompt_text)
status_msg = "Generation finished."
# return (status_text, video_path)
return status_msg, video_path
except Exception as e:
# Return error to status box
return f"Error: {e}", None
generate_btn.click(fn=on_generate, inputs=prompt, outputs=[status, video_output])
return demo
app = make_ui()
# For Hugging Face Spaces just call launch without host/port.
if __name__ == "__main__":
app.launch()