Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
import os
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from gradio_client import Client
|
| 5 |
+
from PIL import Image
|
| 6 |
+
import io
|
| 7 |
+
|
| 8 |
+
# Replace with your actual Veo 3 access via CometAPI or Vertex AI key
|
| 9 |
+
# For demo, using public HF Space proxy (update with your token if needed)
|
| 10 |
+
HF_SPACE_URL = "https://huggingface.co/spaces/akhaliq/veo3.1-fast" # From search results
|
| 11 |
+
client = Client(HF_SPACE_URL)
|
| 12 |
+
|
| 13 |
+
def generate_video(prompt, image=None, audio_prompt=None):
|
| 14 |
+
"""
|
| 15 |
+
Generate Veo 3 video from text/image prompt with optional audio.
|
| 16 |
+
Uses HF Space client for inference.
|
| 17 |
+
"""
|
| 18 |
+
try:
|
| 19 |
+
# Prepare inputs: text prompt, optional image bytes, audio description
|
| 20 |
+
inputs = {"prompt": prompt}
|
| 21 |
+
|
| 22 |
+
if image:
|
| 23 |
+
# Convert PIL Image to bytes for upload
|
| 24 |
+
img_buffer = io.BytesIO()
|
| 25 |
+
image.save(img_buffer, format='PNG')
|
| 26 |
+
img_buffer.seek(0)
|
| 27 |
+
inputs["image"] = img_buffer
|
| 28 |
+
|
| 29 |
+
if audio_prompt:
|
| 30 |
+
inputs["audio_prompt"] = audio_prompt
|
| 31 |
+
|
| 32 |
+
# Submit job to HF Space (Veo 3 proxy)
|
| 33 |
+
job = client.submit(**inputs, api_name="/predict")
|
| 34 |
+
video_path = job.outputs()[0] # Returns video file path/URL
|
| 35 |
+
|
| 36 |
+
return video_path
|
| 37 |
+
except Exception as e:
|
| 38 |
+
return f"Error: {str(e)}"
|
| 39 |
+
|
| 40 |
+
# Gradio Interface with multi-modal support
|
| 41 |
+
with gr.Blocks(title="Veo 3 Generator") as demo:
|
| 42 |
+
gr.Markdown("# Veo 3 Video Generator\nGenerate videos with image/audio support via Hugging Face")
|
| 43 |
+
|
| 44 |
+
with gr.Row():
|
| 45 |
+
with gr.Column(scale=1):
|
| 46 |
+
text_prompt = gr.Textbox(
|
| 47 |
+
label="Text Prompt",
|
| 48 |
+
placeholder="A futuristic cityscape at night with flying cars...",
|
| 49 |
+
lines=3
|
| 50 |
+
)
|
| 51 |
+
image_input = gr.Image(
|
| 52 |
+
label="Reference Image (Optional)",
|
| 53 |
+
type="pil"
|
| 54 |
+
)
|
| 55 |
+
audio_prompt = gr.Textbox(
|
| 56 |
+
label="Audio Prompt (Optional)",
|
| 57 |
+
placeholder="Add ambient city sounds and engine hums"
|
| 58 |
+
)
|
| 59 |
+
generate_btn = gr.Button("Generate Video", variant="primary")
|
| 60 |
+
|
| 61 |
+
with gr.Column(scale=1):
|
| 62 |
+
video_output = gr.Video(label="Generated Video")
|
| 63 |
+
status = gr.Textbox(label="Status", interactive=False)
|
| 64 |
+
|
| 65 |
+
# Event handler
|
| 66 |
+
generate_btn.click(
|
| 67 |
+
fn=generate_video,
|
| 68 |
+
inputs=[text_prompt, image_input, audio_prompt],
|
| 69 |
+
outputs=[video_output, status],
|
| 70 |
+
show_progress=True
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
gr.Examples(
|
| 74 |
+
examples=[
|
| 75 |
+
["A cat playing piano", None, "Soft piano music with meows"],
|
| 76 |
+
[None, "path/to/your/image.jpg", "Animate with ocean waves"],
|
| 77 |
+
],
|
| 78 |
+
inputs=[text_prompt, image_input, audio_prompt]
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
if __name__ == "__main__":
|
| 82 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, share=True)
|