roll-ai commited on
Commit
5478472
Β·
verified Β·
1 Parent(s): fd66ee7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -8
app.py CHANGED
@@ -4,6 +4,9 @@ import torch
4
  import subprocess
5
  from PIL import Image
6
  from pathlib import Path
 
 
 
7
 
8
  # =========================================
9
  # 1. Define Hugging Face weights and paths
@@ -30,16 +33,22 @@ def download_weights():
30
  print(f"βœ… Already exists: {save_path}")
31
 
32
  download_weights()
33
- import gradio as gr
34
- import torch
35
- import os
36
  from inference.flovd_demo import generate_video
37
 
38
  def run_inference(prompt, image, pose_type, speed, use_flow_integration, cam_pose_name):
 
 
 
 
 
 
39
  try:
 
40
  os.makedirs("input_images", exist_ok=True)
41
  image_path = "input_images/input_image.png"
42
  image.save(image_path)
 
43
 
44
  generate_video(
45
  prompt=prompt,
@@ -62,13 +71,25 @@ def run_inference(prompt, image, pose_type, speed, use_flow_integration, cam_pos
62
  cam_pose_name=cam_pose_name,
63
  depth_ckpt_path="./ckpt/others/depth_anything_v2_metric_hypersim_vitb.pth"
64
  )
65
- return f"./outputs/generated_videos/{prompt[:30].strip().replace(' ', '_')}_{cam_pose_name or 'default'}.mp4"
 
 
 
66
 
67
  except Exception as e:
68
- print("πŸ”₯ Inference failed:")
69
- import traceback
70
  traceback.print_exc()
71
- return f"⚠️ Error during inference: {e}"
 
 
 
 
 
 
 
 
 
 
72
 
73
  with gr.Blocks() as demo:
74
  gr.Markdown("## πŸŽ₯ FloVD: Optical Flow + CogVideoX Video Generation")
@@ -83,7 +104,12 @@ with gr.Blocks() as demo:
83
  submit = gr.Button("Generate Video")
84
  with gr.Column():
85
  output_video = gr.Video(label="Generated Video")
 
86
 
87
- submit.click(fn=run_inference, inputs=[prompt, image, pose_type, speed, use_flow_integration, cam_pose_name], outputs=output_video)
 
 
 
 
88
 
89
  demo.launch()
 
4
  import subprocess
5
  from PIL import Image
6
  from pathlib import Path
7
+ import io
8
+ import sys
9
+ import traceback
10
 
11
  # =========================================
12
  # 1. Define Hugging Face weights and paths
 
33
  print(f"βœ… Already exists: {save_path}")
34
 
35
  download_weights()
36
+
 
 
37
  from inference.flovd_demo import generate_video
38
 
39
  def run_inference(prompt, image, pose_type, speed, use_flow_integration, cam_pose_name):
40
+ # Redirect stdout to capture logs
41
+ log_buffer = io.StringIO()
42
+ sys_stdout = sys.stdout
43
+ sys.stdout = log_buffer
44
+
45
+ video_path = None
46
  try:
47
+ print("πŸš€ Starting inference...")
48
  os.makedirs("input_images", exist_ok=True)
49
  image_path = "input_images/input_image.png"
50
  image.save(image_path)
51
+ print(f"πŸ“Έ Saved input image to {image_path}")
52
 
53
  generate_video(
54
  prompt=prompt,
 
71
  cam_pose_name=cam_pose_name,
72
  depth_ckpt_path="./ckpt/others/depth_anything_v2_metric_hypersim_vitb.pth"
73
  )
74
+
75
+ video_name = f"{prompt[:30].strip().replace(' ', '_')}_{cam_pose_name or 'default'}.mp4"
76
+ video_path = f"./outputs/generated_videos/{video_name}"
77
+ print(f"βœ… Inference complete. Video saved to {video_path}")
78
 
79
  except Exception as e:
80
+ print("πŸ”₯ Inference failed with exception:")
 
81
  traceback.print_exc()
82
+
83
+ # Restore stdout and return logs
84
+ sys.stdout = sys_stdout
85
+ logs = log_buffer.getvalue()
86
+ log_buffer.close()
87
+
88
+ return (video_path if video_path and os.path.exists(video_path) else None), logs
89
+
90
+ # ========================
91
+ # Gradio Interface
92
+ # ========================
93
 
94
  with gr.Blocks() as demo:
95
  gr.Markdown("## πŸŽ₯ FloVD: Optical Flow + CogVideoX Video Generation")
 
104
  submit = gr.Button("Generate Video")
105
  with gr.Column():
106
  output_video = gr.Video(label="Generated Video")
107
+ output_logs = gr.Textbox(label="Logs", lines=20, interactive=False)
108
 
109
+ submit.click(
110
+ fn=run_inference,
111
+ inputs=[prompt, image, pose_type, speed, use_flow_integration, cam_pose_name],
112
+ outputs=[output_video, output_logs]
113
+ )
114
 
115
  demo.launch()