File size: 2,843 Bytes
1d200e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# app.py
import os
import gradio as gr
from gradio_client import Client
from PIL import Image
import io

# Replace with your actual Veo 3 access via CometAPI or Vertex AI key
# For demo, using public HF Space proxy (update with your token if needed)
HF_SPACE_URL = "https://huggingface.co/spaces/akhaliq/veo3.1-fast"  # From search results
client = Client(HF_SPACE_URL)

def generate_video(prompt, image=None, audio_prompt=None):
    """
    Generate Veo 3 video from text/image prompt with optional audio.
    Uses HF Space client for inference.
    """
    try:
        # Prepare inputs: text prompt, optional image bytes, audio description
        inputs = {"prompt": prompt}
        
        if image:
            # Convert PIL Image to bytes for upload
            img_buffer = io.BytesIO()
            image.save(img_buffer, format='PNG')
            img_buffer.seek(0)
            inputs["image"] = img_buffer
        
        if audio_prompt:
            inputs["audio_prompt"] = audio_prompt
        
        # Submit job to HF Space (Veo 3 proxy)
        job = client.submit(**inputs, api_name="/predict")
        video_path = job.outputs()[0]  # Returns video file path/URL
        
        return video_path
    except Exception as e:
        return f"Error: {str(e)}"

# Gradio Interface with multi-modal support
with gr.Blocks(title="Veo 3 Generator") as demo:
    gr.Markdown("# Veo 3 Video Generator\nGenerate videos with image/audio support via Hugging Face")
    
    with gr.Row():
        with gr.Column(scale=1):
            text_prompt = gr.Textbox(
                label="Text Prompt", 
                placeholder="A futuristic cityscape at night with flying cars...",
                lines=3
            )
            image_input = gr.Image(
                label="Reference Image (Optional)", 
                type="pil"
            )
            audio_prompt = gr.Textbox(
                label="Audio Prompt (Optional)", 
                placeholder="Add ambient city sounds and engine hums"
            )
            generate_btn = gr.Button("Generate Video", variant="primary")
        
        with gr.Column(scale=1):
            video_output = gr.Video(label="Generated Video")
            status = gr.Textbox(label="Status", interactive=False)
    
    # Event handler
    generate_btn.click(
        fn=generate_video,
        inputs=[text_prompt, image_input, audio_prompt],
        outputs=[video_output, status],
        show_progress=True
    )
    
    gr.Examples(
        examples=[
            ["A cat playing piano", None, "Soft piano music with meows"],
            [None, "path/to/your/image.jpg", "Animate with ocean waves"],
        ],
        inputs=[text_prompt, image_input, audio_prompt]
    )

if __name__ == "__main__":
    demo.launch(server_name="0.0.0.0", server_port=7860, share=True)