Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,17 +3,48 @@ import requests
|
|
3 |
|
4 |
API_URL = "https://rahul7star-FramePack-F1-DiffusionForce.hf.space/api/generate/"
|
5 |
|
6 |
-
def call_framepack_api(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
files = {}
|
8 |
data = {
|
9 |
"prompt": prompt,
|
10 |
"t2v": str(t2v).lower(),
|
11 |
-
"
|
12 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
}
|
14 |
|
15 |
if input_image:
|
16 |
files["input_image"] = ("input.png", input_image, "image/png")
|
|
|
|
|
17 |
|
18 |
try:
|
19 |
response = requests.post(API_URL, data=data, files=files)
|
@@ -21,33 +52,64 @@ def call_framepack_api(input_image, prompt, t2v, seed, seconds):
|
|
21 |
result = response.json()
|
22 |
video_url = result.get("video_url")
|
23 |
preview_url = result.get("preview_image_url")
|
24 |
-
return video_url, preview_url
|
25 |
else:
|
26 |
-
return f"API Error: {response.status_code}"
|
27 |
except Exception as e:
|
28 |
-
return str(e)
|
29 |
|
30 |
with gr.Blocks() as demo:
|
31 |
-
gr.Markdown("
|
32 |
|
33 |
with gr.Row():
|
34 |
-
input_image = gr.Image(type="file", label="Input Image (optional)", sources=["upload"])
|
35 |
with gr.Column():
|
36 |
-
|
|
|
|
|
|
|
37 |
t2v = gr.Checkbox(label="Text-to-Video", value=True)
|
38 |
seed = gr.Number(label="Seed", value=31337, precision=0)
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
-
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
46 |
|
47 |
generate_btn.click(
|
48 |
fn=call_framepack_api,
|
49 |
-
inputs=[
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
)
|
52 |
|
53 |
demo.launch()
|
|
|
3 |
|
4 |
API_URL = "https://rahul7star-FramePack-F1-DiffusionForce.hf.space/api/generate/"
|
5 |
|
6 |
+
def call_framepack_api(
|
7 |
+
input_image,
|
8 |
+
prompt,
|
9 |
+
t2v,
|
10 |
+
n_prompt,
|
11 |
+
seed,
|
12 |
+
total_second_length,
|
13 |
+
latent_window_size,
|
14 |
+
steps,
|
15 |
+
cfg,
|
16 |
+
gs,
|
17 |
+
rs,
|
18 |
+
gpu_memory_preservation,
|
19 |
+
use_teacache,
|
20 |
+
mp4_crf,
|
21 |
+
lora_file,
|
22 |
+
lora_multiplier,
|
23 |
+
fp8_optimization,
|
24 |
+
):
|
25 |
files = {}
|
26 |
data = {
|
27 |
"prompt": prompt,
|
28 |
"t2v": str(t2v).lower(),
|
29 |
+
"n_prompt": n_prompt,
|
30 |
+
"seed": int(seed),
|
31 |
+
"total_second_length": float(total_second_length),
|
32 |
+
"latent_window_size": int(latent_window_size),
|
33 |
+
"steps": int(steps),
|
34 |
+
"cfg": float(cfg),
|
35 |
+
"gs": float(gs),
|
36 |
+
"rs": float(rs),
|
37 |
+
"gpu_memory_preservation": float(gpu_memory_preservation),
|
38 |
+
"use_teacache": str(use_teacache).lower(),
|
39 |
+
"mp4_crf": int(mp4_crf),
|
40 |
+
"lora_multiplier": float(lora_multiplier),
|
41 |
+
"fp8_optimization": str(fp8_optimization).lower(),
|
42 |
}
|
43 |
|
44 |
if input_image:
|
45 |
files["input_image"] = ("input.png", input_image, "image/png")
|
46 |
+
if lora_file:
|
47 |
+
files["lora_file"] = (lora_file.name, lora_file, "application/octet-stream")
|
48 |
|
49 |
try:
|
50 |
response = requests.post(API_URL, data=data, files=files)
|
|
|
52 |
result = response.json()
|
53 |
video_url = result.get("video_url")
|
54 |
preview_url = result.get("preview_image_url")
|
55 |
+
return video_url, preview_url, str(result)
|
56 |
else:
|
57 |
+
return None, None, f"API Error: {response.status_code} - {response.text}"
|
58 |
except Exception as e:
|
59 |
+
return None, None, f"Exception: {str(e)}"
|
60 |
|
61 |
with gr.Blocks() as demo:
|
62 |
+
gr.Markdown("# FramePack API Client with Full Options")
|
63 |
|
64 |
with gr.Row():
|
|
|
65 |
with gr.Column():
|
66 |
+
input_image = gr.File(label="Input Image (PNG/JPG) — optional", file_types=[".png", ".jpg", ".jpeg"])
|
67 |
+
lora_file = gr.File(label="LoRA File (optional)", file_types=[".safetensors", ".pt", ".bin"])
|
68 |
+
prompt = gr.Textbox(label="Prompt")
|
69 |
+
n_prompt = gr.Textbox(label="Negative Prompt (optional)", value="")
|
70 |
t2v = gr.Checkbox(label="Text-to-Video", value=True)
|
71 |
seed = gr.Number(label="Seed", value=31337, precision=0)
|
72 |
+
total_second_length = gr.Slider(label="Video Length (seconds)", minimum=1, maximum=120, value=5, step=0.1)
|
73 |
+
latent_window_size = gr.Slider(label="Latent Window Size", minimum=1, maximum=33, value=9, step=1)
|
74 |
+
steps = gr.Slider(label="Steps", minimum=1, maximum=100, value=25, step=1)
|
75 |
+
cfg = gr.Slider(label="CFG Scale", minimum=1.0, maximum=32.0, value=1.0, step=0.01)
|
76 |
+
gs = gr.Slider(label="Distilled CFG Scale", minimum=1.0, maximum=32.0, value=10.0, step=0.01)
|
77 |
+
rs = gr.Slider(label="CFG Re-Scale", minimum=0.0, maximum=1.0, value=0.0, step=0.01)
|
78 |
+
gpu_memory_preservation = gr.Slider(label="GPU Inference Preserved Memory (GB)", minimum=6, maximum=128, value=6, step=0.1)
|
79 |
+
use_teacache = gr.Checkbox(label="Use TeaCache", value=True)
|
80 |
+
mp4_crf = gr.Slider(label="MP4 Compression", minimum=0, maximum=100, value=16, step=1)
|
81 |
+
lora_multiplier = gr.Slider(label="LoRA Multiplier", minimum=0.0, maximum=1.0, value=0.8, step=0.1)
|
82 |
+
fp8_optimization = gr.Checkbox(label="FP8 Optimization", value=False)
|
83 |
|
84 |
+
generate_btn = gr.Button("Generate")
|
85 |
|
86 |
+
with gr.Column():
|
87 |
+
video_output = gr.Video(label="Generated Video", autoplay=True)
|
88 |
+
preview_output = gr.Image(label="Preview Image")
|
89 |
+
api_response = gr.Textbox(label="API JSON Response", lines=10)
|
90 |
|
91 |
generate_btn.click(
|
92 |
fn=call_framepack_api,
|
93 |
+
inputs=[
|
94 |
+
input_image,
|
95 |
+
prompt,
|
96 |
+
t2v,
|
97 |
+
n_prompt,
|
98 |
+
seed,
|
99 |
+
total_second_length,
|
100 |
+
latent_window_size,
|
101 |
+
steps,
|
102 |
+
cfg,
|
103 |
+
gs,
|
104 |
+
rs,
|
105 |
+
gpu_memory_preservation,
|
106 |
+
use_teacache,
|
107 |
+
mp4_crf,
|
108 |
+
lora_file,
|
109 |
+
lora_multiplier,
|
110 |
+
fp8_optimization,
|
111 |
+
],
|
112 |
+
outputs=[video_output, preview_output, api_response],
|
113 |
)
|
114 |
|
115 |
demo.launch()
|