mygradiodemo / app.py
AnthonyOlatunji's picture
Update app.py
99cb38f verified
raw
history blame
1.05 kB
import os
from huggingface_hub import InferenceClient
import gradio as gr
# ─── STEP 1 ───
# Paste your HF token here (bypasses the need for the Spaces secrets UI)
os.environ["HF_HUB_TOKEN"] = "YOUR_HF_TOKEN_HERE"
# ─── STEP 2 ───
# Initialize the InferenceClient
client = InferenceClient(
repo_id="ali-vilab/text-to-video-ms-1.7b",
token=os.environ["HF_HUB_TOKEN"],
)
# ─── STEP 3 ───
# Define the function that takes a prompt, calls the API, and writes out an MP4
def generate_video(prompt: str) -> str:
result = client.text_to_video(prompt) # {'video': b'...'}
video_bytes = result["video"]
out_path = "out.mp4"
with open(out_path, "wb") as f:
f.write(video_bytes)
return out_path
# ─── STEP 4 ───
# Wire it up in Gradio
demo = gr.Interface(
fn=generate_video,
inputs=gr.Textbox(label="Enter your prompt here"),
outputs=gr.Video(label="Generated Video"),
title="Video Generator",
)
demo.launch(server_name="0.0.0.0", server_port=7860)