Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
|
4 |
+
API_URL = "https://rahul7star-FramePack-F1-DiffusionForce.hf.space/api/generate/"
|
5 |
+
|
6 |
+
def call_framepack_api(input_image, prompt, t2v, seed, seconds):
|
7 |
+
files = {}
|
8 |
+
data = {
|
9 |
+
"prompt": prompt,
|
10 |
+
"t2v": str(t2v).lower(),
|
11 |
+
"seed": seed,
|
12 |
+
"total_second_length": seconds,
|
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)
|
20 |
+
if response.status_code == 200:
|
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}", None
|
27 |
+
except Exception as e:
|
28 |
+
return str(e), None
|
29 |
+
|
30 |
+
with gr.Blocks() as demo:
|
31 |
+
gr.Markdown("## FramePack API Client")
|
32 |
+
|
33 |
+
with gr.Row():
|
34 |
+
input_image = gr.Image(type="file", label="Input Image (optional)", sources=["upload"])
|
35 |
+
with gr.Column():
|
36 |
+
prompt = gr.Textbox(label="Prompt", placeholder="Describe the scene")
|
37 |
+
t2v = gr.Checkbox(label="Text-to-Video", value=True)
|
38 |
+
seed = gr.Number(label="Seed", value=31337, precision=0)
|
39 |
+
seconds = gr.Slider(label="Video Length (seconds)", minimum=1, maximum=10, value=3)
|
40 |
+
|
41 |
+
generate_btn = gr.Button("Generate")
|
42 |
+
|
43 |
+
with gr.Row():
|
44 |
+
video_output = gr.Video(label="Generated Video", autoplay=True)
|
45 |
+
preview_output = gr.Image(label="Preview Image")
|
46 |
+
|
47 |
+
generate_btn.click(
|
48 |
+
fn=call_framepack_api,
|
49 |
+
inputs=[input_image, prompt, t2v, seed, seconds],
|
50 |
+
outputs=[video_output, preview_output]
|
51 |
+
)
|
52 |
+
|
53 |
+
demo.launch()
|