Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import torch
|
| 3 |
import numpy as np
|
|
@@ -10,6 +13,10 @@ from scipy.ndimage import binary_opening, binary_closing, sobel, binary_dilation
|
|
| 10 |
import zipfile
|
| 11 |
import io
|
| 12 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
# グローバル変数
|
| 15 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
@@ -342,23 +349,26 @@ def process_image(image, max_size, tile_size, tile_overlap, min_area, mesh_res,
|
|
| 342 |
output_data = {'metadata': metadata, 'meshes': meshes}
|
| 343 |
json_str = json.dumps(output_data, ensure_ascii=False, indent=2)
|
| 344 |
|
| 345 |
-
# ZIP
|
| 346 |
-
|
| 347 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 348 |
zip_file.writestr('city_3d_model.json', json_str)
|
| 349 |
|
| 350 |
# セグメンテーション画像
|
| 351 |
_, buffer = cv2.imencode('.png', cv2.cvtColor(colored_seg, cv2.COLOR_RGB2BGR))
|
| 352 |
zip_file.writestr('segmentation_result.png', buffer.tobytes())
|
| 353 |
|
| 354 |
-
zip_buffer.seek(0)
|
| 355 |
-
|
| 356 |
# 統計情報
|
| 357 |
stats = f"総セグメント数: {len(meshes)}\n\n"
|
| 358 |
for cat, info in metadata['categories'].items():
|
| 359 |
stats += f"{info['label']}: {info['count']}個\n"
|
| 360 |
|
| 361 |
-
return colored_seg, overlay, stats,
|
| 362 |
|
| 363 |
# Gradio UI
|
| 364 |
with gr.Blocks(title="3D City Map Generator") as demo:
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
# -*- coding: utf-8 -*-
|
| 3 |
+
|
| 4 |
import gradio as gr
|
| 5 |
import torch
|
| 6 |
import numpy as np
|
|
|
|
| 13 |
import zipfile
|
| 14 |
import io
|
| 15 |
import os
|
| 16 |
+
import tempfile
|
| 17 |
+
import shutil
|
| 18 |
+
import warnings
|
| 19 |
+
warnings.filterwarnings('ignore')
|
| 20 |
|
| 21 |
# グローバル変数
|
| 22 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 349 |
output_data = {'metadata': metadata, 'meshes': meshes}
|
| 350 |
json_str = json.dumps(output_data, ensure_ascii=False, indent=2)
|
| 351 |
|
| 352 |
+
# ZIPファイル作成(一時ファイルとして保存)
|
| 353 |
+
import tempfile
|
| 354 |
+
import shutil
|
| 355 |
+
|
| 356 |
+
temp_dir = tempfile.mkdtemp()
|
| 357 |
+
zip_path = os.path.join(temp_dir, 'city_3d_output.zip')
|
| 358 |
+
|
| 359 |
+
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zip_file:
|
| 360 |
zip_file.writestr('city_3d_model.json', json_str)
|
| 361 |
|
| 362 |
# セグメンテーション画像
|
| 363 |
_, buffer = cv2.imencode('.png', cv2.cvtColor(colored_seg, cv2.COLOR_RGB2BGR))
|
| 364 |
zip_file.writestr('segmentation_result.png', buffer.tobytes())
|
| 365 |
|
|
|
|
|
|
|
| 366 |
# 統計情報
|
| 367 |
stats = f"総セグメント数: {len(meshes)}\n\n"
|
| 368 |
for cat, info in metadata['categories'].items():
|
| 369 |
stats += f"{info['label']}: {info['count']}個\n"
|
| 370 |
|
| 371 |
+
return colored_seg, overlay, stats, zip_path
|
| 372 |
|
| 373 |
# Gradio UI
|
| 374 |
with gr.Blocks(title="3D City Map Generator") as demo:
|