Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 18 |
|
| 19 |
-
if
|
| 20 |
raise gr.Error("No detectable objects found in the video!")
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
# 3.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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="๐ญ ๊ณต์ฅ
|
| 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__":
|