Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -18,25 +18,15 @@ snapshot_download(
|
|
18 |
token=hf_token,
|
19 |
)
|
20 |
|
21 |
-
print("β
Download complete.")
|
22 |
-
print("π Contents of ./ckpt directory:")
|
23 |
-
for root, dirs, files in os.walk("./ckpt"):
|
24 |
-
level = root.replace("./ckpt", "").count(os.sep)
|
25 |
-
indent = " " * 4 * level
|
26 |
-
print(f"{indent}{os.path.basename(root)}/")
|
27 |
-
subindent = " " * 4 * (level + 1)
|
28 |
-
for f in files:
|
29 |
-
print(f"{subindent}{f}")
|
30 |
-
|
31 |
# -----------------------------------
|
32 |
-
# Step 2:
|
33 |
# -----------------------------------
|
34 |
-
|
35 |
FVSM_PATH = "./ckpt/FVSM/FloVD_FVSM_Controlnet.pt"
|
36 |
OMSM_PATH = "./ckpt/OMSM/"
|
37 |
DEPTH_CKPT_PATH = "./ckpt/others/depth_anything_v2_metric_hypersim_vitb.pth"
|
38 |
OUTPUT_PATH = "./results/"
|
39 |
GEN_VID_DIR = os.path.join(OUTPUT_PATH, "generated_videos")
|
|
|
40 |
POSE_TYPE = "re10k"
|
41 |
CONTROLNET_GUIDANCE_END = 0.4
|
42 |
SPEED = 1.0
|
@@ -46,14 +36,19 @@ INFER_STEPS = 50
|
|
46 |
|
47 |
os.makedirs(GEN_VID_DIR, exist_ok=True)
|
48 |
|
|
|
|
|
|
|
|
|
49 |
def list_generated_videos():
|
50 |
try:
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
except Exception as e:
|
56 |
print(f"[β οΈ] Could not list contents: {str(e)}")
|
|
|
57 |
|
58 |
def run_flovd(prompt, image, cam_pose_name):
|
59 |
try:
|
@@ -61,8 +56,6 @@ def run_flovd(prompt, image, cam_pose_name):
|
|
61 |
print("π Starting video generation")
|
62 |
print("----------------------------")
|
63 |
|
64 |
-
list_generated_videos()
|
65 |
-
|
66 |
image_path = "./temp_input.png"
|
67 |
image.save(image_path)
|
68 |
print(f"πΈ Image saved at {image_path}")
|
@@ -85,9 +78,6 @@ def run_flovd(prompt, image, cam_pose_name):
|
|
85 |
num_inference_steps=INFER_STEPS,
|
86 |
)
|
87 |
|
88 |
-
print("\nβ
Generation finished.")
|
89 |
-
list_generated_videos()
|
90 |
-
|
91 |
prompt_short = prompt[:30].strip().replace(" ", "_").replace(".", "").replace(",", "")
|
92 |
video_filename = f"{prompt_short}_{cam_pose_name}.mp4"
|
93 |
video_path = os.path.join(GEN_VID_DIR, video_filename)
|
@@ -95,30 +85,51 @@ def run_flovd(prompt, image, cam_pose_name):
|
|
95 |
print(f"\nπ Looking for generated video at: {video_path}")
|
96 |
if os.path.exists(video_path):
|
97 |
print("β
Video file found.")
|
98 |
-
return video_path
|
99 |
else:
|
100 |
print("β File missing:", video_path)
|
101 |
-
list_generated_videos()
|
102 |
-
return f"[ERROR] File not found at: {video_path}"
|
103 |
|
104 |
except Exception as e:
|
105 |
print(f"π₯ Exception occurred: {str(e)}")
|
106 |
-
return f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
# -----------------------------------
|
109 |
-
# Step 3: Launch Gradio
|
110 |
# -----------------------------------
|
111 |
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
gr.
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
)
|
123 |
-
|
124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
token=hf_token,
|
19 |
)
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
# -----------------------------------
|
22 |
+
# Step 2: Setup paths and config
|
23 |
# -----------------------------------
|
|
|
24 |
FVSM_PATH = "./ckpt/FVSM/FloVD_FVSM_Controlnet.pt"
|
25 |
OMSM_PATH = "./ckpt/OMSM/"
|
26 |
DEPTH_CKPT_PATH = "./ckpt/others/depth_anything_v2_metric_hypersim_vitb.pth"
|
27 |
OUTPUT_PATH = "./results/"
|
28 |
GEN_VID_DIR = os.path.join(OUTPUT_PATH, "generated_videos")
|
29 |
+
|
30 |
POSE_TYPE = "re10k"
|
31 |
CONTROLNET_GUIDANCE_END = 0.4
|
32 |
SPEED = 1.0
|
|
|
36 |
|
37 |
os.makedirs(GEN_VID_DIR, exist_ok=True)
|
38 |
|
39 |
+
# -----------------------------------
|
40 |
+
# Helper Functions
|
41 |
+
# -----------------------------------
|
42 |
+
|
43 |
def list_generated_videos():
|
44 |
try:
|
45 |
+
return sorted([
|
46 |
+
f for f in os.listdir(GEN_VID_DIR)
|
47 |
+
if f.endswith(".mp4")
|
48 |
+
])
|
49 |
except Exception as e:
|
50 |
print(f"[β οΈ] Could not list contents: {str(e)}")
|
51 |
+
return []
|
52 |
|
53 |
def run_flovd(prompt, image, cam_pose_name):
|
54 |
try:
|
|
|
56 |
print("π Starting video generation")
|
57 |
print("----------------------------")
|
58 |
|
|
|
|
|
59 |
image_path = "./temp_input.png"
|
60 |
image.save(image_path)
|
61 |
print(f"πΈ Image saved at {image_path}")
|
|
|
78 |
num_inference_steps=INFER_STEPS,
|
79 |
)
|
80 |
|
|
|
|
|
|
|
81 |
prompt_short = prompt[:30].strip().replace(" ", "_").replace(".", "").replace(",", "")
|
82 |
video_filename = f"{prompt_short}_{cam_pose_name}.mp4"
|
83 |
video_path = os.path.join(GEN_VID_DIR, video_filename)
|
|
|
85 |
print(f"\nπ Looking for generated video at: {video_path}")
|
86 |
if os.path.exists(video_path):
|
87 |
print("β
Video file found.")
|
88 |
+
return video_path, list_generated_videos(), None
|
89 |
else:
|
90 |
print("β File missing:", video_path)
|
91 |
+
return f"[ERROR] File not found at: {video_path}", list_generated_videos(), None
|
|
|
92 |
|
93 |
except Exception as e:
|
94 |
print(f"π₯ Exception occurred: {str(e)}")
|
95 |
+
return f"[EXCEPTION] {str(e)}", list_generated_videos(), None
|
96 |
+
|
97 |
+
def get_video_file(video_name):
|
98 |
+
video_path = os.path.join(GEN_VID_DIR, video_name)
|
99 |
+
if os.path.exists(video_path):
|
100 |
+
return video_path
|
101 |
+
else:
|
102 |
+
return None
|
103 |
|
104 |
# -----------------------------------
|
105 |
+
# Step 3: Launch Gradio Interface
|
106 |
# -----------------------------------
|
107 |
|
108 |
+
with gr.Blocks(title="FloVD + CogVideoX") as demo:
|
109 |
+
gr.Markdown("## π₯ FloVD - Camera Motion Guided Video Generation + Downloader")
|
110 |
+
|
111 |
+
with gr.Row():
|
112 |
+
with gr.Column():
|
113 |
+
prompt = gr.Textbox(label="Prompt")
|
114 |
+
image = gr.Image(type="pil", label="Input Image")
|
115 |
+
pose_file = gr.Textbox(label="Camera Pose Filename (e.g. abc.txt)")
|
116 |
+
run_btn = gr.Button("Generate Video")
|
117 |
+
with gr.Column():
|
118 |
+
output_video = gr.Video(label="Generated Video")
|
119 |
+
video_selector = gr.Dropdown(choices=list_generated_videos(), label="Select Video to Download")
|
120 |
+
download_btn = gr.Button("Download Selected")
|
121 |
+
file_output = gr.File(label="Download Link")
|
122 |
+
|
123 |
+
run_btn.click(
|
124 |
+
fn=run_flovd,
|
125 |
+
inputs=[prompt, image, pose_file],
|
126 |
+
outputs=[output_video, video_selector, file_output],
|
127 |
+
)
|
128 |
+
|
129 |
+
download_btn.click(
|
130 |
+
fn=get_video_file,
|
131 |
+
inputs=[video_selector],
|
132 |
+
outputs=[file_output],
|
133 |
+
)
|
134 |
+
|
135 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|