murphylmf commited on
Commit
053c377
·
1 Parent(s): aab6b64
Files changed (39) hide show
  1. .gitignore +79 -0
  2. app.py +0 -28
  3. index.html +2 -7
  4. unish/__pycache__/pipeline.cpython-310.pyc +0 -0
  5. unish/heads/__pycache__/align_net.cpython-310.pyc +0 -0
  6. unish/heads/__pycache__/dpt_head.cpython-310.pyc +0 -0
  7. unish/heads/__pycache__/head_act.cpython-310.pyc +0 -0
  8. unish/heads/__pycache__/human_head_cliff.cpython-310.pyc +0 -0
  9. unish/heads/__pycache__/pose_transformer.cpython-310.pyc +0 -0
  10. unish/heads/__pycache__/t_cond_mlp.cpython-310.pyc +0 -0
  11. unish/heads/__pycache__/utils.cpython-310.pyc +0 -0
  12. unish/heads/__pycache__/vit.cpython-310.pyc +0 -0
  13. unish/pi3/models/__pycache__/pi3.cpython-310.pyc +0 -0
  14. unish/pi3/models/dinov2/__pycache__/__init__.cpython-310.pyc +0 -0
  15. unish/pi3/models/dinov2/hub/__pycache__/__init__.cpython-310.pyc +0 -0
  16. unish/pi3/models/dinov2/hub/__pycache__/backbones.cpython-310.pyc +0 -0
  17. unish/pi3/models/dinov2/hub/__pycache__/utils.cpython-310.pyc +0 -0
  18. unish/pi3/models/dinov2/layers/__pycache__/__init__.cpython-310.pyc +0 -0
  19. unish/pi3/models/dinov2/layers/__pycache__/attention.cpython-310.pyc +0 -0
  20. unish/pi3/models/dinov2/layers/__pycache__/block.cpython-310.pyc +0 -0
  21. unish/pi3/models/dinov2/layers/__pycache__/dino_head.cpython-310.pyc +0 -0
  22. unish/pi3/models/dinov2/layers/__pycache__/drop_path.cpython-310.pyc +0 -0
  23. unish/pi3/models/dinov2/layers/__pycache__/layer_scale.cpython-310.pyc +0 -0
  24. unish/pi3/models/dinov2/layers/__pycache__/mlp.cpython-310.pyc +0 -0
  25. unish/pi3/models/dinov2/layers/__pycache__/patch_embed.cpython-310.pyc +0 -0
  26. unish/pi3/models/dinov2/layers/__pycache__/swiglu_ffn.cpython-310.pyc +0 -0
  27. unish/pi3/models/dinov2/models/__pycache__/__init__.cpython-310.pyc +0 -0
  28. unish/pi3/models/dinov2/models/__pycache__/vision_transformer.cpython-310.pyc +0 -0
  29. unish/pi3/models/layers/__pycache__/attention.cpython-310.pyc +0 -0
  30. unish/pi3/models/layers/__pycache__/block.cpython-310.pyc +0 -0
  31. unish/pi3/models/layers/__pycache__/camera_head.cpython-310.pyc +0 -0
  32. unish/pi3/models/layers/__pycache__/pos_embed.cpython-310.pyc +0 -0
  33. unish/pi3/models/layers/__pycache__/transformer_head.cpython-310.pyc +0 -0
  34. unish/pi3/utils/__pycache__/geometry.cpython-310.pyc +0 -0
  35. unish/utils/__pycache__/constants.cpython-310.pyc +0 -0
  36. unish/utils/__pycache__/data_utils.cpython-310.pyc +0 -0
  37. unish/utils/__pycache__/inference_utils.cpython-310.pyc +0 -0
  38. unish/utils/__pycache__/renderer.cpython-310.pyc +0 -0
  39. unish/utils/__pycache__/smpl_utils.cpython-310.pyc +0 -0
.gitignore ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ build/
8
+ develop-eggs/
9
+ dist/
10
+ downloads/
11
+ eggs/
12
+ .eggs/
13
+ lib/
14
+ lib64/
15
+ parts/
16
+ sdist/
17
+ var/
18
+ wheels/
19
+ *.egg-info/
20
+ .installed.cfg
21
+ *.egg
22
+
23
+ # Virtual Environments
24
+ venv/
25
+ .venv/
26
+ env/
27
+ .env/
28
+ .anaconda
29
+ .conda
30
+
31
+ # IDE / System
32
+ .idea/
33
+ .vscode/
34
+ *.swp
35
+ .DS_Store
36
+ Thumbs.db
37
+
38
+ # UniSH specific outputs
39
+ output.glb
40
+ visualize.glb
41
+ scene_clouds_per_frame/
42
+ smpl_meshes_per_frame/
43
+ output/
44
+ outputs/
45
+ results/
46
+ tmp/
47
+ temp/
48
+
49
+ # Model weights and large files
50
+ *.pt
51
+ *.pth
52
+ *.ckpt
53
+ *.safetensors
54
+ *.bin
55
+ *.onnx
56
+ *.pkl
57
+
58
+ # SMPL models
59
+ body_models/
60
+ smpl_models/
61
+
62
+ # Media and Datasets
63
+ *.mp4
64
+ *.avi
65
+ *.mov
66
+ *.mkv
67
+ *.jpg
68
+ *.png
69
+ *.jpeg
70
+
71
+ # 3D Intermediate files
72
+ *.ply
73
+ *.obj
74
+ *.gltf
75
+
76
+ # Runtime temporary directories
77
+ _tmp_sam2/
78
+ .gradio/
79
+ flagged/
app.py CHANGED
@@ -17,16 +17,10 @@ import html
17
  import base64
18
  import inspect
19
 
20
- # ==========================================
21
- # 1. 核心路径与环境配置
22
- # ==========================================
23
  BASE_DIR = os.path.dirname(os.path.abspath(__file__))
24
  STATIC_DIR = os.path.join(BASE_DIR, "static")
25
  EXAMPLES_DIR = os.path.join(BASE_DIR, "examples")
26
 
27
- # ==========================================
28
- # 2. 静态资源准备
29
- # ==========================================
30
  def prepare_local_assets():
31
  os.makedirs(STATIC_DIR, exist_ok=True)
32
  base_url = "https://registry.npmmirror.com/three/0.160.0/files"
@@ -50,9 +44,6 @@ def prepare_local_assets():
50
 
51
  prepare_local_assets()
52
 
53
- # ==========================================
54
- # 3. 环境 Patch (SAM 2)
55
- # ==========================================
56
  def install_sam2():
57
  try:
58
  import sam2
@@ -72,7 +63,6 @@ install_sam2()
72
 
73
  sys.path.append(BASE_DIR)
74
 
75
- # 引入核心模型代码
76
  from unish.utils.inference_utils import (
77
  load_model, process_video, run_inference,
78
  generate_mixed_geometries_in_memory,
@@ -82,9 +72,6 @@ from unish.utils.inference_utils import (
82
  MODEL = None
83
  BODY_MODELS_PATH = "body_models/"
84
 
85
- # ==========================================
86
- # 4. 辅助函数
87
- # ==========================================
88
  def download_smpl_assets(body_models_path):
89
  if 'smpl' not in body_models_path:
90
  model_path = os.path.join(body_models_path, 'smpl')
@@ -112,7 +99,6 @@ def pack_sequence_to_glb(base_dir, output_path, start_frame, end_frame, scene_ra
112
  scene_cloud_dir = os.path.join(base_dir, "scene_clouds_per_frame")
113
  smpl_mesh_dir = os.path.join(base_dir, "smpl_meshes_per_frame")
114
 
115
- # 60,000 点/帧
116
  MAX_POINTS_PER_FRAME = 60000
117
 
118
  for i in range(start_frame, end_frame):
@@ -171,10 +157,6 @@ def get_video_duration(video_path):
171
  except:
172
  return 10.0
173
 
174
- # ==========================================
175
- # 5. 前端逻辑: Player & Loading HTML
176
- # ==========================================
177
-
178
  def get_loading_html(message="Processing..."):
179
  return f"""
180
  <div style="height: 600px; width: 100%; background: #f9fafb; border-radius: 12px; border: 1px solid #e5e7eb; display: flex; flex-direction: column; align-items: center; justify-content: center; font-family: sans-serif; color: #4b5563;">
@@ -290,9 +272,6 @@ def get_player_html(abs_glb_path):
290
  """
291
  return f'<iframe srcdoc="{html.escape(raw_html)}" width="100%" height="600px" style="border:none; border-radius: 12px;"></iframe>'
292
 
293
- # ==========================================
294
- # 6. 推理逻辑封装
295
- # ==========================================
296
  if os.environ.get("SPACE_ID"):
297
  from spaces import GPU
298
  gpu_decorator = GPU(duration=120)
@@ -307,7 +286,6 @@ else:
307
 
308
  @gpu_decorator
309
  def predict(video_path, start_time, end_time):
310
- # 1. 时长限制检测
311
  duration_input = end_time - start_time
312
  if duration_input > 10.0:
313
  raise gr.Error(f"Video limit exceeded ({duration_input:.1f}s). Please keep it under 10 seconds.")
@@ -315,7 +293,6 @@ def predict(video_path, start_time, end_time):
315
  if start_time >= end_time:
316
  raise gr.Error("Error: End time must be greater than Start time.")
317
 
318
- # 2. 正常流程
319
  yield get_loading_html("Processing...")
320
 
321
  output_dir = tempfile.mkdtemp()
@@ -355,10 +332,6 @@ def predict(video_path, start_time, end_time):
355
 
356
  yield get_player_html(tmp_glb_path)
357
 
358
- # ==========================================
359
- # 7. UI 构建
360
- # ==========================================
361
-
362
  examples_list = []
363
  if os.path.exists(EXAMPLES_DIR):
364
  examples_list = [[os.path.join("examples", f)] for f in os.listdir(EXAMPLES_DIR) if f.endswith(".mp4")]
@@ -412,7 +385,6 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo", radius_size="md"), css
412
  start_time = gr.Slider(minimum=0, maximum=10, value=0, step=0.01, label="Start Time (s)")
413
  end_time = gr.Slider(minimum=0, maximum=10, value=3, step=0.01, label="End Time (s)")
414
 
415
- # --- Grid Layout 还原完整文案 ---
416
  gr.HTML("""
417
  <div class="alert-box tip-box">
418
  <strong>💡 Use Tips:</strong>
 
17
  import base64
18
  import inspect
19
 
 
 
 
20
  BASE_DIR = os.path.dirname(os.path.abspath(__file__))
21
  STATIC_DIR = os.path.join(BASE_DIR, "static")
22
  EXAMPLES_DIR = os.path.join(BASE_DIR, "examples")
23
 
 
 
 
24
  def prepare_local_assets():
25
  os.makedirs(STATIC_DIR, exist_ok=True)
26
  base_url = "https://registry.npmmirror.com/three/0.160.0/files"
 
44
 
45
  prepare_local_assets()
46
 
 
 
 
47
  def install_sam2():
48
  try:
49
  import sam2
 
63
 
64
  sys.path.append(BASE_DIR)
65
 
 
66
  from unish.utils.inference_utils import (
67
  load_model, process_video, run_inference,
68
  generate_mixed_geometries_in_memory,
 
72
  MODEL = None
73
  BODY_MODELS_PATH = "body_models/"
74
 
 
 
 
75
  def download_smpl_assets(body_models_path):
76
  if 'smpl' not in body_models_path:
77
  model_path = os.path.join(body_models_path, 'smpl')
 
99
  scene_cloud_dir = os.path.join(base_dir, "scene_clouds_per_frame")
100
  smpl_mesh_dir = os.path.join(base_dir, "smpl_meshes_per_frame")
101
 
 
102
  MAX_POINTS_PER_FRAME = 60000
103
 
104
  for i in range(start_frame, end_frame):
 
157
  except:
158
  return 10.0
159
 
 
 
 
 
160
  def get_loading_html(message="Processing..."):
161
  return f"""
162
  <div style="height: 600px; width: 100%; background: #f9fafb; border-radius: 12px; border: 1px solid #e5e7eb; display: flex; flex-direction: column; align-items: center; justify-content: center; font-family: sans-serif; color: #4b5563;">
 
272
  """
273
  return f'<iframe srcdoc="{html.escape(raw_html)}" width="100%" height="600px" style="border:none; border-radius: 12px;"></iframe>'
274
 
 
 
 
275
  if os.environ.get("SPACE_ID"):
276
  from spaces import GPU
277
  gpu_decorator = GPU(duration=120)
 
286
 
287
  @gpu_decorator
288
  def predict(video_path, start_time, end_time):
 
289
  duration_input = end_time - start_time
290
  if duration_input > 10.0:
291
  raise gr.Error(f"Video limit exceeded ({duration_input:.1f}s). Please keep it under 10 seconds.")
 
293
  if start_time >= end_time:
294
  raise gr.Error("Error: End time must be greater than Start time.")
295
 
 
296
  yield get_loading_html("Processing...")
297
 
298
  output_dir = tempfile.mkdtemp()
 
332
 
333
  yield get_player_html(tmp_glb_path)
334
 
 
 
 
 
335
  examples_list = []
336
  if os.path.exists(EXAMPLES_DIR):
337
  examples_list = [[os.path.join("examples", f)] for f in os.listdir(EXAMPLES_DIR) if f.endswith(".mp4")]
 
385
  start_time = gr.Slider(minimum=0, maximum=10, value=0, step=0.01, label="Start Time (s)")
386
  end_time = gr.Slider(minimum=0, maximum=10, value=3, step=0.01, label="End Time (s)")
387
 
 
388
  gr.HTML("""
389
  <div class="alert-box tip-box">
390
  <strong>💡 Use Tips:</strong>
index.html CHANGED
@@ -15,7 +15,7 @@
15
  <link href="https://fonts.googleapis.com/css?family=Google+Sans|Noto+Sans|Castoro" rel="stylesheet">
16
 
17
  <style>
18
- /* 1. 轮播图容器样式 */
19
  .carousel .item {
20
  position: relative;
21
  border-radius: 12px;
@@ -32,7 +32,6 @@
32
  height: auto;
33
  }
34
 
35
- /* 2. 悬浮计数胶囊样式 */
36
  .video-overlay-label {
37
  position: absolute;
38
  bottom: 15px;
@@ -51,7 +50,6 @@
51
  z-index: 10;
52
  }
53
 
54
- /* 3. Player 样式 */
55
  #canvas-container {
56
  width: 100%;
57
  height: 500px;
@@ -62,7 +60,6 @@
62
  box-shadow: inset 0 0 20px rgba(0,0,0,0.05);
63
  }
64
 
65
- /* 4. Teaser 媒体容器样式 */
66
  .teaser-video-wrapper {
67
  position: relative;
68
  border-radius: 8px;
@@ -71,7 +68,7 @@
71
  box-shadow: 0 8px 20px rgba(0,0,0,0.12);
72
  background: #000;
73
  width: 100%;
74
- margin-bottom: 20px; /* 视频和图片之间的间距 */
75
  }
76
 
77
  .teaser-video-wrapper video {
@@ -80,13 +77,11 @@
80
  height: auto;
81
  }
82
 
83
- /* 作者名字样式 */
84
  .author-block {
85
  margin-right: 10px;
86
  white-space: nowrap;
87
  }
88
 
89
- /* 自定义 Slider */
90
  input[type=range].custom-slider {
91
  -webkit-appearance: none;
92
  width: 100%;
 
15
  <link href="https://fonts.googleapis.com/css?family=Google+Sans|Noto+Sans|Castoro" rel="stylesheet">
16
 
17
  <style>
18
+
19
  .carousel .item {
20
  position: relative;
21
  border-radius: 12px;
 
32
  height: auto;
33
  }
34
 
 
35
  .video-overlay-label {
36
  position: absolute;
37
  bottom: 15px;
 
50
  z-index: 10;
51
  }
52
 
 
53
  #canvas-container {
54
  width: 100%;
55
  height: 500px;
 
60
  box-shadow: inset 0 0 20px rgba(0,0,0,0.05);
61
  }
62
 
 
63
  .teaser-video-wrapper {
64
  position: relative;
65
  border-radius: 8px;
 
68
  box-shadow: 0 8px 20px rgba(0,0,0,0.12);
69
  background: #000;
70
  width: 100%;
71
+ margin-bottom: 20px;
72
  }
73
 
74
  .teaser-video-wrapper video {
 
77
  height: auto;
78
  }
79
 
 
80
  .author-block {
81
  margin-right: 10px;
82
  white-space: nowrap;
83
  }
84
 
 
85
  input[type=range].custom-slider {
86
  -webkit-appearance: none;
87
  width: 100%;
unish/__pycache__/pipeline.cpython-310.pyc DELETED
Binary file (6.53 kB)
 
unish/heads/__pycache__/align_net.cpython-310.pyc DELETED
Binary file (13.6 kB)
 
unish/heads/__pycache__/dpt_head.cpython-310.pyc DELETED
Binary file (12.6 kB)
 
unish/heads/__pycache__/head_act.cpython-310.pyc DELETED
Binary file (3.11 kB)
 
unish/heads/__pycache__/human_head_cliff.cpython-310.pyc DELETED
Binary file (2.92 kB)
 
unish/heads/__pycache__/pose_transformer.cpython-310.pyc DELETED
Binary file (10.9 kB)
 
unish/heads/__pycache__/t_cond_mlp.cpython-310.pyc DELETED
Binary file (6.08 kB)
 
unish/heads/__pycache__/utils.cpython-310.pyc DELETED
Binary file (3.14 kB)
 
unish/heads/__pycache__/vit.cpython-310.pyc DELETED
Binary file (11.2 kB)
 
unish/pi3/models/__pycache__/pi3.cpython-310.pyc DELETED
Binary file (7.01 kB)
 
unish/pi3/models/dinov2/__pycache__/__init__.cpython-310.pyc DELETED
Binary file (180 Bytes)
 
unish/pi3/models/dinov2/hub/__pycache__/__init__.cpython-310.pyc DELETED
Binary file (163 Bytes)
 
unish/pi3/models/dinov2/hub/__pycache__/backbones.cpython-310.pyc DELETED
Binary file (3.99 kB)
 
unish/pi3/models/dinov2/hub/__pycache__/utils.cpython-310.pyc DELETED
Binary file (1.78 kB)
 
unish/pi3/models/dinov2/layers/__pycache__/__init__.cpython-310.pyc DELETED
Binary file (450 Bytes)
 
unish/pi3/models/dinov2/layers/__pycache__/attention.cpython-310.pyc DELETED
Binary file (2.47 kB)
 
unish/pi3/models/dinov2/layers/__pycache__/block.cpython-310.pyc DELETED
Binary file (8.04 kB)
 
unish/pi3/models/dinov2/layers/__pycache__/dino_head.cpython-310.pyc DELETED
Binary file (1.99 kB)
 
unish/pi3/models/dinov2/layers/__pycache__/drop_path.cpython-310.pyc DELETED
Binary file (1.21 kB)
 
unish/pi3/models/dinov2/layers/__pycache__/layer_scale.cpython-310.pyc DELETED
Binary file (1.01 kB)
 
unish/pi3/models/dinov2/layers/__pycache__/mlp.cpython-310.pyc DELETED
Binary file (1.2 kB)
 
unish/pi3/models/dinov2/layers/__pycache__/patch_embed.cpython-310.pyc DELETED
Binary file (2.65 kB)
 
unish/pi3/models/dinov2/layers/__pycache__/swiglu_ffn.cpython-310.pyc DELETED
Binary file (2.12 kB)
 
unish/pi3/models/dinov2/models/__pycache__/__init__.cpython-310.pyc DELETED
Binary file (1.18 kB)
 
unish/pi3/models/dinov2/models/__pycache__/vision_transformer.cpython-310.pyc DELETED
Binary file (11.9 kB)
 
unish/pi3/models/layers/__pycache__/attention.cpython-310.pyc DELETED
Binary file (11.1 kB)
 
unish/pi3/models/layers/__pycache__/block.cpython-310.pyc DELETED
Binary file (11.7 kB)
 
unish/pi3/models/layers/__pycache__/camera_head.cpython-310.pyc DELETED
Binary file (3.52 kB)
 
unish/pi3/models/layers/__pycache__/pos_embed.cpython-310.pyc DELETED
Binary file (5.54 kB)
 
unish/pi3/models/layers/__pycache__/transformer_head.cpython-310.pyc DELETED
Binary file (11.4 kB)
 
unish/pi3/utils/__pycache__/geometry.cpython-310.pyc DELETED
Binary file (14.2 kB)
 
unish/utils/__pycache__/constants.cpython-310.pyc DELETED
Binary file (1.71 kB)
 
unish/utils/__pycache__/data_utils.cpython-310.pyc DELETED
Binary file (21.2 kB)
 
unish/utils/__pycache__/inference_utils.cpython-310.pyc DELETED
Binary file (40.9 kB)
 
unish/utils/__pycache__/renderer.cpython-310.pyc DELETED
Binary file (16.8 kB)
 
unish/utils/__pycache__/smpl_utils.cpython-310.pyc DELETED
Binary file (10.7 kB)