|
|
|
|
|
import os |
|
|
import gradio as gr |
|
|
from gradio_client import Client |
|
|
from PIL import Image |
|
|
import io |
|
|
|
|
|
|
|
|
|
|
|
HF_SPACE_URL = "https://huggingface.co/spaces/akhaliq/veo3.1-fast" |
|
|
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: |
|
|
|
|
|
inputs = {"prompt": prompt} |
|
|
|
|
|
if image: |
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
job = client.submit(**inputs, api_name="/predict") |
|
|
video_path = job.outputs()[0] |
|
|
|
|
|
return video_path |
|
|
except Exception as e: |
|
|
return f"Error: {str(e)}" |
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
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) |
|
|
|