Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,48 +1,34 @@
|
|
1 |
-
# app.py
|
2 |
import os
|
3 |
-
import gradio as gr
|
4 |
from huggingface_hub import InferenceClient
|
|
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
|
9 |
-
HF_TOKEN = os.getenv("HF_HUB_TOKEN", None)
|
10 |
-
if not HF_TOKEN:
|
11 |
-
raise RuntimeError("Please set a HF_HUB_TOKEN in your Space secrets!")
|
12 |
-
|
13 |
-
# (2) Model to call
|
14 |
-
MODEL_ID = "damo-vilab/text-to-video-ms-1.7b"
|
15 |
-
|
16 |
-
# Initialize the HF Inference client
|
17 |
-
client = InferenceClient(token=HF_TOKEN)
|
18 |
|
19 |
-
#
|
|
|
|
|
|
|
|
|
|
|
20 |
|
|
|
|
|
21 |
def generate_video(prompt: str) -> str:
|
22 |
-
|
23 |
-
|
24 |
-
""
|
25 |
-
out_path = "/tmp/out.mp4"
|
26 |
-
|
27 |
-
# 1) Fire off the inference request
|
28 |
-
# The `text_to_video` method returns raw bytes for the first generated video.
|
29 |
-
result = client.text_to_video(model=MODEL_ID, inputs=prompt)
|
30 |
-
|
31 |
-
# 2) Save to disk
|
32 |
-
video_bytes = result["generated_video"] # bytes
|
33 |
with open(out_path, "wb") as f:
|
34 |
f.write(video_bytes)
|
35 |
-
|
36 |
return out_path
|
37 |
|
38 |
-
#
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
demo.launch(share=True)
|
|
|
|
|
1 |
import os
|
|
|
2 |
from huggingface_hub import InferenceClient
|
3 |
+
import gradio as gr
|
4 |
|
5 |
+
# βββ STEP 1 βββ
|
6 |
+
# Paste your HF token here (bypasses the need for the Spaces secrets UI)
|
7 |
+
os.environ["HF_HUB_TOKEN"] = "YOUR_HF_TOKEN_HERE"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
# βββ STEP 2 βββ
|
10 |
+
# Initialize the InferenceClient
|
11 |
+
client = InferenceClient(
|
12 |
+
repo_id="ali-vilab/text-to-video-ms-1.7b",
|
13 |
+
token=os.environ["HF_HUB_TOKEN"],
|
14 |
+
)
|
15 |
|
16 |
+
# βββ STEP 3 βββ
|
17 |
+
# Define the function that takes a prompt, calls the API, and writes out an MP4
|
18 |
def generate_video(prompt: str) -> str:
|
19 |
+
result = client.text_to_video(prompt) # {'video': b'...'}
|
20 |
+
video_bytes = result["video"]
|
21 |
+
out_path = "out.mp4"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
with open(out_path, "wb") as f:
|
23 |
f.write(video_bytes)
|
|
|
24 |
return out_path
|
25 |
|
26 |
+
# βββ STEP 4 βββ
|
27 |
+
# Wire it up in Gradio
|
28 |
+
demo = gr.Interface(
|
29 |
+
fn=generate_video,
|
30 |
+
inputs=gr.Textbox(label="Enter your prompt here"),
|
31 |
+
outputs=gr.Video(label="Generated Video"),
|
32 |
+
title="Video Generator",
|
33 |
+
)
|
34 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|