Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,61 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
import random
|
|
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
with gr.Blocks(fill_height=True) as demo:
|
5 |
with gr.Sidebar():
|
6 |
-
gr.Markdown("#
|
7 |
-
gr.Markdown("
|
8 |
-
|
9 |
|
10 |
gr.Markdown("## 🎬 Generate Video from Text")
|
11 |
with gr.Row():
|
12 |
with gr.Column():
|
13 |
-
text_input = gr.Textbox(label="Prompt", placeholder="Enter your prompt
|
14 |
fps_slider = gr.Slider(1, 24, value=8, label="FPS")
|
15 |
frames_slider = gr.Slider(8, 48, value=24, label="Number of Frames")
|
16 |
aspect_ratio = gr.Dropdown(choices=["square", "landscape", "portrait"], value="square", label="Aspect Ratio")
|
@@ -20,29 +65,10 @@ with gr.Blocks(fill_height=True) as demo:
|
|
20 |
with gr.Column():
|
21 |
video_output = gr.Video(label="Generated Video")
|
22 |
|
23 |
-
#
|
24 |
-
model = gr.load(
|
25 |
-
"models/Wan-AI/Wan2.1-T2V-1.3B",
|
26 |
-
inputs=["prompt", "num_frames", "fps", "aspect_ratio", "guidance_scale", "negative_prompt", "seed"],
|
27 |
-
outputs=video_output,
|
28 |
-
accept_token=button,
|
29 |
-
provider="fal-ai"
|
30 |
-
)
|
31 |
-
|
32 |
-
def generate_video_fn(prompt, fps, num_frames, aspect_ratio, guidance_scale, seed):
|
33 |
-
return model(
|
34 |
-
prompt=prompt,
|
35 |
-
num_frames=num_frames,
|
36 |
-
fps=fps,
|
37 |
-
aspect_ratio=aspect_ratio,
|
38 |
-
guidance_scale=guidance_scale,
|
39 |
-
negative_prompt="",
|
40 |
-
seed=int(seed)
|
41 |
-
)
|
42 |
-
|
43 |
generate_button.click(
|
44 |
-
fn=
|
45 |
-
inputs=[text_input, fps_slider, frames_slider, aspect_ratio, guidance_scale, seed_input],
|
46 |
outputs=video_output
|
47 |
)
|
48 |
|
|
|
1 |
import gradio as gr
|
2 |
+
import requests
|
3 |
import random
|
4 |
+
import time
|
5 |
|
6 |
+
# FAL endpoint for Wan2.1 T2V
|
7 |
+
FAL_API_URL = "https://api.fal.ai/fal-ai/wan2.1-t2v-1.3b"
|
8 |
+
|
9 |
+
# Function to call fal.ai API
|
10 |
+
def generate_video(prompt, fps, num_frames, aspect_ratio, guidance_scale, seed, token):
|
11 |
+
headers = {
|
12 |
+
"Authorization": f"Bearer {token}"
|
13 |
+
}
|
14 |
+
|
15 |
+
payload = {
|
16 |
+
"prompt": prompt,
|
17 |
+
"num_frames": num_frames,
|
18 |
+
"fps": fps,
|
19 |
+
"aspect_ratio": aspect_ratio,
|
20 |
+
"guidance_scale": guidance_scale,
|
21 |
+
"negative_prompt": "",
|
22 |
+
"seed": int(seed)
|
23 |
+
}
|
24 |
+
|
25 |
+
# Call API
|
26 |
+
response = requests.post(FAL_API_URL, json=payload, headers=headers)
|
27 |
+
response.raise_for_status()
|
28 |
+
result = response.json()
|
29 |
+
|
30 |
+
# Poll for video URL
|
31 |
+
video_url = None
|
32 |
+
for _ in range(20):
|
33 |
+
time.sleep(2)
|
34 |
+
poll = requests.get(result["urls"]["get"], headers=headers)
|
35 |
+
poll.raise_for_status()
|
36 |
+
status = poll.json()
|
37 |
+
if status["status"] == "COMPLETED":
|
38 |
+
video_url = status["output"]["video_url"]
|
39 |
+
break
|
40 |
+
elif status["status"] == "FAILED":
|
41 |
+
raise Exception("Video generation failed.")
|
42 |
+
|
43 |
+
if not video_url:
|
44 |
+
raise Exception("Timeout waiting for video.")
|
45 |
+
|
46 |
+
return video_url
|
47 |
+
|
48 |
+
# Gradio UI
|
49 |
with gr.Blocks(fill_height=True) as demo:
|
50 |
with gr.Sidebar():
|
51 |
+
gr.Markdown("# Wan2.1 T2V Generator")
|
52 |
+
gr.Markdown("Sign in to use this model.")
|
53 |
+
login_button = gr.LoginButton()
|
54 |
|
55 |
gr.Markdown("## 🎬 Generate Video from Text")
|
56 |
with gr.Row():
|
57 |
with gr.Column():
|
58 |
+
text_input = gr.Textbox(label="Prompt", placeholder="Enter your prompt...")
|
59 |
fps_slider = gr.Slider(1, 24, value=8, label="FPS")
|
60 |
frames_slider = gr.Slider(8, 48, value=24, label="Number of Frames")
|
61 |
aspect_ratio = gr.Dropdown(choices=["square", "landscape", "portrait"], value="square", label="Aspect Ratio")
|
|
|
65 |
with gr.Column():
|
66 |
video_output = gr.Video(label="Generated Video")
|
67 |
|
68 |
+
# Wire button to function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
generate_button.click(
|
70 |
+
fn=generate_video,
|
71 |
+
inputs=[text_input, fps_slider, frames_slider, aspect_ratio, guidance_scale, seed_input, login_button],
|
72 |
outputs=video_output
|
73 |
)
|
74 |
|