junaid-simamdigital commited on
Commit
29509cf
·
verified ·
1 Parent(s): e27c7bc

Initial reproducible prototype

Browse files
Files changed (1) hide show
  1. app.py +87 -0
app.py ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """General media ingest and honest Gaussian-preview workbench."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import hashlib
6
+ import json
7
+ import time
8
+ from pathlib import Path
9
+
10
+ import gradio as gr
11
+ import numpy as np
12
+ from PIL import Image
13
+
14
+ from core import image_billboard_points, write_preview_ply
15
+
16
+
17
+ def _paths(items):
18
+ if not items:
19
+ return []
20
+ if isinstance(items, (str, Path)):
21
+ return [str(items)]
22
+ return [str(getattr(item, "path", None) or getattr(item, "name", item)) for item in items]
23
+
24
+
25
+ def _hash_file(path):
26
+ digest = hashlib.sha256()
27
+ size = 0
28
+ with Path(path).open("rb") as handle:
29
+ for chunk in iter(lambda: handle.read(1024 * 1024), b""):
30
+ digest.update(chunk)
31
+ size += len(chunk)
32
+ return {"name": Path(path).name, "bytes": size, "sha256": digest.hexdigest()}
33
+
34
+
35
+ def ingest(images, videos, mode):
36
+ image_paths, video_paths = _paths(images), _paths(videos)
37
+ if not image_paths and not video_paths:
38
+ raise gr.Error("Add at least one image or video.")
39
+ if not image_paths:
40
+ raise gr.Error("The CPU preview needs at least one image; video frame extraction is the next backend adapter.")
41
+ first = Image.open(image_paths[0]).convert("RGB")
42
+ points, colors = image_billboard_points(first)
43
+ out_dir = Path("output")
44
+ out_dir.mkdir(exist_ok=True)
45
+ ply_path = write_preview_ply(out_dir / "simamanything2gs_preview.ply", points, colors)
46
+ manifest = {
47
+ "project": "SimamAnything2GS",
48
+ "version": "0.1.0",
49
+ "created_at_unix": int(time.time()),
50
+ "mode": mode,
51
+ "images": [_hash_file(path) for path in image_paths],
52
+ "videos": [_hash_file(path) for path in video_paths],
53
+ "preview_points": int(len(points)),
54
+ "preview_type": "2.5D image billboard; not a learned 3D reconstruction",
55
+ "limitations": [
56
+ "The preview places image pixels on a single plane at z=1.",
57
+ "No depth, camera pose, occlusion completion, or Gaussian optimization is claimed.",
58
+ "Real image/video-to-Gaussian backends must be evaluated separately on held-out views.",
59
+ ],
60
+ }
61
+ manifest_path = out_dir / "simamanything2gs_manifest.json"
62
+ manifest_path.write_text(json.dumps(manifest, indent=2), encoding="utf-8")
63
+ return str(ply_path), str(manifest_path), json.dumps(manifest, indent=2), "Preview exported; use it only as an ingest/export smoke test."
64
+
65
+
66
+ with gr.Blocks(title="SimamAnything2GS") as demo:
67
+ gr.Markdown("# SimamAnything2GS\nImage/video ingest toward Gaussian reconstruction")
68
+ gr.Markdown(
69
+ "This first slice accepts arbitrary media and exports a deterministic 2.5D Gaussian-style preview. "
70
+ "Depth, pose estimation, video frame extraction, and learned Gaussian optimization are explicit future adapters."
71
+ )
72
+ with gr.Row():
73
+ with gr.Column():
74
+ images = gr.Files(label="Images", file_types=["image"], file_count="multiple", type="filepath")
75
+ videos = gr.Files(label="Optional videos", file_types=["video"], file_count="multiple", type="filepath")
76
+ mode = gr.Dropdown(["CPU ingest preview", "Future depth + pose backend"], value="CPU ingest preview", label="Pipeline mode")
77
+ run = gr.Button("Build Gaussian preview", variant="primary")
78
+ with gr.Column():
79
+ ply = gr.File(label="Preview PLY")
80
+ manifest = gr.File(label="Manifest JSON")
81
+ report = gr.Code(label="Run report", language="json")
82
+ status = gr.Markdown()
83
+ run.click(ingest, [images, videos, mode], [ply, manifest, report, status])
84
+
85
+
86
+ if __name__ == "__main__":
87
+ demo.launch(show_error=True)