roll-ai commited on
Commit
d8bfbd8
·
verified ·
1 Parent(s): 9ea7e1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -16
app.py CHANGED
@@ -6,7 +6,7 @@ from inference.flovd_demo import generate_video
6
  from huggingface_hub import snapshot_download
7
 
8
  # -----------------------------------
9
- # Step 1: Setup Hugging Face Cache
10
  # -----------------------------------
11
  hf_token = os.getenv("HF_TOKEN", None)
12
 
@@ -18,16 +18,6 @@ snapshot_download(
18
  token=hf_token,
19
  )
20
 
21
- # Optional: print ckpt directory structure
22
- print("📁 CKPT Directory Contents:")
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: Define inference function
33
  # -----------------------------------
@@ -39,6 +29,11 @@ OUTPUT_PATH = "./results/"
39
  POSE_TYPE = "re10k"
40
  CONTROLNET_GUIDANCE_END = 0.4
41
  SPEED = 1.0
 
 
 
 
 
42
 
43
  def run_flovd(prompt, image, cam_pose_name):
44
  image_path = "./temp_input.png"
@@ -51,18 +46,27 @@ def run_flovd(prompt, image, cam_pose_name):
51
  image_path=image_path,
52
  cam_pose_name=cam_pose_name,
53
  output_path=OUTPUT_PATH,
54
- pose_type=POSE_TYPE,
55
  controlnet_guidance_end=CONTROLNET_GUIDANCE_END,
 
56
  speed=SPEED,
57
  use_flow_integration=True,
58
  depth_ckpt_path=DEPTH_CKPT_PATH,
59
  dtype=torch.float16,
 
 
 
60
  )
61
 
62
- return "./results/generated_videos/your_video.mp4"
 
 
 
 
 
 
63
 
64
  # -----------------------------------
65
- # Step 3: Gradio UI
66
  # -----------------------------------
67
 
68
  iface = gr.Interface(
@@ -70,10 +74,11 @@ iface = gr.Interface(
70
  inputs=[
71
  gr.Textbox(label="Prompt"),
72
  gr.Image(type="pil", label="Input Image"),
73
- gr.Textbox(label="Camera Pose File Name", value="example.txt"),
74
  ],
75
  outputs=gr.Video(label="Generated Video"),
76
- title="FloVD - Camera Motion Guided Video Generation"
 
77
  )
78
 
79
  iface.launch(server_name="0.0.0.0", server_port=7860)
 
6
  from huggingface_hub import snapshot_download
7
 
8
  # -----------------------------------
9
+ # Step 1: Download model checkpoints
10
  # -----------------------------------
11
  hf_token = os.getenv("HF_TOKEN", None)
12
 
 
18
  token=hf_token,
19
  )
20
 
 
 
 
 
 
 
 
 
 
 
21
  # -----------------------------------
22
  # Step 2: Define inference function
23
  # -----------------------------------
 
29
  POSE_TYPE = "re10k"
30
  CONTROLNET_GUIDANCE_END = 0.4
31
  SPEED = 1.0
32
+ NUM_FRAMES = 81
33
+ FPS = 16
34
+ INFER_STEPS = 50
35
+
36
+ os.makedirs(os.path.join(OUTPUT_PATH, "generated_videos"), exist_ok=True)
37
 
38
  def run_flovd(prompt, image, cam_pose_name):
39
  image_path = "./temp_input.png"
 
46
  image_path=image_path,
47
  cam_pose_name=cam_pose_name,
48
  output_path=OUTPUT_PATH,
 
49
  controlnet_guidance_end=CONTROLNET_GUIDANCE_END,
50
+ pose_type=POSE_TYPE,
51
  speed=SPEED,
52
  use_flow_integration=True,
53
  depth_ckpt_path=DEPTH_CKPT_PATH,
54
  dtype=torch.float16,
55
+ num_frames=NUM_FRAMES,
56
+ fps=FPS,
57
+ num_inference_steps=INFER_STEPS,
58
  )
59
 
60
+ prompt_short = prompt[:30].strip().replace(" ", "_").replace(".", "").replace(",", "")
61
+ video_path = os.path.join(OUTPUT_PATH, "generated_videos", f"{prompt_short}_{cam_pose_name}.mp4")
62
+
63
+ if os.path.exists(video_path):
64
+ return video_path
65
+ else:
66
+ return "Video generation failed or file not found."
67
 
68
  # -----------------------------------
69
+ # Step 3: Launch Gradio UI
70
  # -----------------------------------
71
 
72
  iface = gr.Interface(
 
74
  inputs=[
75
  gr.Textbox(label="Prompt"),
76
  gr.Image(type="pil", label="Input Image"),
77
+ gr.Textbox(label="Camera Pose File Name (e.g., 1593596b99e2dde9.txt)"),
78
  ],
79
  outputs=gr.Video(label="Generated Video"),
80
+ title="🎥 FloVD + CogVideoX - Camera Motion Guided Video Generation",
81
+ description="Upload an image, enter a descriptive prompt, and provide a camera pose file name to generate video with dynamic camera motion."
82
  )
83
 
84
  iface.launch(server_name="0.0.0.0", server_port=7860)