shin0624 commited on
Commit
c0cb016
ยท
verified ยท
1 Parent(s): db6f7ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -12
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  import tempfile
3
  import os
 
4
  from detector.frame_sampler import extract_keyframes
5
  from detector.yolo_pipeline import YOLO3DReconstructor
6
  from exporters.webgl_exporter import export_to_webgl
@@ -14,30 +15,66 @@ def process_video(video):
14
 
15
  # 2. 3D ํฌ์ธํŠธ ํด๋ผ์šฐ๋“œ ์ƒ์„ฑ
16
  reconstructor = YOLO3DReconstructor()
17
- pointcloud = reconstructor.process_frames(frame_paths)
18
 
19
- if pointcloud is None:
20
  raise gr.Error("No detectable objects found in the video!")
 
 
21
 
22
- # 3. 3D ๋ชจ๋ธ ์ €์žฅ
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  obj_path = os.path.join(tmpdir, "factory.obj")
24
  pointcloud.export(obj_path)
25
-
26
- # 4. WebGL ๋ณ€ํ™˜
27
  html_path = export_to_webgl(obj_path, tmpdir)
28
-
29
- return (obj_path, html_path)
 
 
 
 
 
 
30
 
31
  iface = gr.Interface(
32
  fn=process_video,
33
  inputs=gr.Video(label="๊ณต์žฅ ์˜์ƒ ์—…๋กœ๋“œ (MP4/AVI)"),
34
  outputs=[
35
- gr.Model3D(label="3D ํฌ์ธํŠธ ํด๋ผ์šฐ๋“œ"),
36
- gr.File(label="WebGL ๋ทฐ์–ด")
 
 
 
37
  ],
38
- title="๐Ÿญ ๊ณต์žฅ 3D ๊ตฌ์กฐ ๋ถ„์„ ์‹œ์Šคํ…œ",
39
- description="์—…๋กœ๋“œ๋œ ๊ณต์žฅ ์˜์ƒ์—์„œ 3D ๊ตฌ์กฐ๋งต์„ ์ž๋™ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค",
40
- allow_flagging="never"
 
 
 
 
41
  )
42
 
43
  if __name__ == "__main__":
 
1
  import gradio as gr
2
  import tempfile
3
  import os
4
+ import numpy as np
5
  from detector.frame_sampler import extract_keyframes
6
  from detector.yolo_pipeline import YOLO3DReconstructor
7
  from exporters.webgl_exporter import export_to_webgl
 
15
 
16
  # 2. 3D ํฌ์ธํŠธ ํด๋ผ์šฐ๋“œ ์ƒ์„ฑ
17
  reconstructor = YOLO3DReconstructor()
18
+ result = reconstructor.process_frames(frame_paths)
19
 
20
+ if result is None:
21
  raise gr.Error("No detectable objects found in the video!")
22
+
23
+ pointcloud, detections = result
24
 
25
+ # 3. ์‹œ๊ฐํ™” ๊ฒฐ๊ณผ ์ƒ์„ฑ
26
+ vis_dir = os.path.join(tmpdir, "visualizations")
27
+ os.makedirs(vis_dir, exist_ok=True)
28
+
29
+ # 3D ํฌ์ธํŠธ ํด๋ผ์šฐ๋“œ ์‹œ๊ฐํ™”
30
+ pc_points = np.array([point[:3] for point in pointcloud.vertices])
31
+ FactoryVisualizer.plot_3d_pointcloud(
32
+ pc_points,
33
+ save_path=os.path.join(vis_dir, "3d_view.png")
34
+ )
35
+
36
+ # ํƒ‘๋ทฐ ์‹œ๊ฐํ™”
37
+ FactoryVisualizer.create_top_down_view(
38
+ pc_points,
39
+ save_path=os.path.join(vis_dir, "top_view.png")
40
+ )
41
+
42
+ # ํด๋ž˜์Šค ๋ถ„ํฌ ์‹œ๊ฐํ™”
43
+ FactoryVisualizer.plot_class_distribution(
44
+ detections,
45
+ save_path=os.path.join(vis_dir, "distribution.png")
46
+ )
47
+
48
+ # 4. ๋ชจ๋ธ ๋ฐ ๊ฒฐ๊ณผ ํŒŒ์ผ ์ €์žฅ
49
  obj_path = os.path.join(tmpdir, "factory.obj")
50
  pointcloud.export(obj_path)
 
 
51
  html_path = export_to_webgl(obj_path, tmpdir)
52
+
53
+ return (
54
+ obj_path,
55
+ html_path,
56
+ os.path.join(vis_dir, "3d_view.png"),
57
+ os.path.join(vis_dir, "top_view.png"),
58
+ os.path.join(vis_dir, "distribution.png")
59
+ )
60
 
61
  iface = gr.Interface(
62
  fn=process_video,
63
  inputs=gr.Video(label="๊ณต์žฅ ์˜์ƒ ์—…๋กœ๋“œ (MP4/AVI)"),
64
  outputs=[
65
+ gr.Model3D(label="3D ํฌ์ธํŠธ ํด๋ผ์šฐ๋“œ ๋ชจ๋ธ"),
66
+ gr.File(label="WebGL ์ธํ„ฐ๋ž™ํ‹ฐ๋ธŒ ๋ทฐ์–ด"),
67
+ gr.Image(label="3D ๊ณต์žฅ ๊ตฌ์กฐ", type="filepath"),
68
+ gr.Image(label="ํƒ‘๋ทฐ ๊ตฌ์กฐ๋งต", type="filepath"),
69
+ gr.Image(label="๊ฐ์ฒด ๋ถ„ํฌ ๋ถ„์„", type="filepath")
70
  ],
71
+ title="๐Ÿญ AI ๊ณต์žฅ ๊ตฌ์กฐ ๋ถ„์„ ์‹œ์Šคํ…œ",
72
+ description="์—…๋กœ๋“œ๋œ ๊ณต์žฅ ์˜์ƒ์—์„œ 3D ๊ตฌ์กฐ๋งต๊ณผ ๋ถ„์„ ๋ฆฌํฌํŠธ๋ฅผ ์ž๋™ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค",
73
+ allow_flagging="never",
74
+ examples=[
75
+ ["sample_videos/factory_sample1.mp4"],
76
+ ["sample_videos/factory_sample2.avi"]
77
+ ]
78
  )
79
 
80
  if __name__ == "__main__":