Spaces:
Sleeping
Sleeping
removed logs, added examples, fixed json
Browse files- __pycache__/app.cpython-312.pyc +0 -0
- app.py +29 -13
- examples/examples.json +3 -3
__pycache__/app.cpython-312.pyc
ADDED
|
Binary file (12.7 kB). View file
|
|
|
app.py
CHANGED
|
@@ -103,25 +103,40 @@ EXAMPLES_DIR = os.path.join(os.path.dirname(__file__), "examples")
|
|
| 103 |
|
| 104 |
|
| 105 |
def load_examples():
|
| 106 |
-
"""Read examples/examples.json -> [[file, lat, lng, depth], ...]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
manifest = os.path.join(EXAMPLES_DIR, "examples.json")
|
| 108 |
if not os.path.exists(manifest):
|
| 109 |
-
return []
|
| 110 |
try:
|
| 111 |
with open(manifest) as fh:
|
| 112 |
entries = json.load(fh)
|
| 113 |
-
except (OSError, ValueError):
|
| 114 |
-
|
| 115 |
-
|
|
|
|
| 116 |
for e in entries:
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
else:
|
| 121 |
missing += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
if missing:
|
| 123 |
print(f"[uwcolorkit] {missing} example(s) listed in examples.json have no file yet")
|
| 124 |
-
return rows
|
| 125 |
|
| 126 |
|
| 127 |
def _discard(path):
|
|
@@ -179,7 +194,7 @@ def correct(path, lat, lng, depth):
|
|
| 179 |
except Exception as exc:
|
| 180 |
raise gr.Error(f"Parameter API error: {exc}")
|
| 181 |
|
| 182 |
-
print(f"[uwcolorkit] month={month}
|
| 183 |
matrix = color.correction_matrix(illum.as_tuple())
|
| 184 |
before = color.encode_display(linear)
|
| 185 |
after = color.encode_display(color.apply_correction(linear, matrix))
|
|
@@ -202,13 +217,14 @@ def build():
|
|
| 202 |
lat = gr.Number(label="Latitude", value=DEFAULT_LAT, elem_id="scubai_lat", precision=6)
|
| 203 |
lng = gr.Number(label="Longitude", value=DEFAULT_LNG, elem_id="scubai_lng", precision=6)
|
| 204 |
depth = gr.Slider(0, 40, value=DEFAULT_DEPTH, step=1, label="Depth (m)")
|
| 205 |
-
correct_btn = gr.Button("Correct
|
| 206 |
-
examples = load_examples()
|
| 207 |
if examples:
|
| 208 |
gr.Examples(
|
| 209 |
examples=examples,
|
| 210 |
inputs=[raw_file, lat, lng, depth],
|
| 211 |
label="Or try a sample dive",
|
|
|
|
| 212 |
)
|
| 213 |
with gr.Column():
|
| 214 |
slider = gr.ImageSlider(label="RAW → Corrected", type="numpy", slider_position=50)
|
|
|
|
| 103 |
|
| 104 |
|
| 105 |
def load_examples():
|
| 106 |
+
"""Read examples/examples.json -> ([[file, lat, lng, depth], ...], [label, ...]).
|
| 107 |
+
|
| 108 |
+
GPS lives in each RAW's EXIF, not the manifest, so the sample dives stay in
|
| 109 |
+
sync with the photo and the JSON only carries file + depth (+ optional label).
|
| 110 |
+
Coordinates come from the same exif_gps path the upload handler uses; a file
|
| 111 |
+
without GPS EXIF falls back to the default location (logged).
|
| 112 |
+
"""
|
| 113 |
manifest = os.path.join(EXAMPLES_DIR, "examples.json")
|
| 114 |
if not os.path.exists(manifest):
|
| 115 |
+
return [], []
|
| 116 |
try:
|
| 117 |
with open(manifest) as fh:
|
| 118 |
entries = json.load(fh)
|
| 119 |
+
except (OSError, ValueError) as exc:
|
| 120 |
+
print(f"[uwcolorkit] examples.json could not be parsed: {exc}")
|
| 121 |
+
return [], []
|
| 122 |
+
rows, labels, missing = [], [], 0
|
| 123 |
for e in entries:
|
| 124 |
+
filename = e.get("file", "")
|
| 125 |
+
path = os.path.join(EXAMPLES_DIR, filename)
|
| 126 |
+
if not os.path.exists(path):
|
|
|
|
| 127 |
missing += 1
|
| 128 |
+
continue
|
| 129 |
+
gps = exif_gps.extract_gps(path)
|
| 130 |
+
if gps is None:
|
| 131 |
+
print(f"[uwcolorkit] {filename!r}: no GPS in EXIF, using default location")
|
| 132 |
+
lat, lng = DEFAULT_LAT, DEFAULT_LNG
|
| 133 |
+
else:
|
| 134 |
+
lat, lng = gps
|
| 135 |
+
rows.append([path, round(lat, 6), round(lng, 6), e.get("depth", DEFAULT_DEPTH)])
|
| 136 |
+
labels.append(e.get("label") or os.path.splitext(filename)[0])
|
| 137 |
if missing:
|
| 138 |
print(f"[uwcolorkit] {missing} example(s) listed in examples.json have no file yet")
|
| 139 |
+
return rows, labels
|
| 140 |
|
| 141 |
|
| 142 |
def _discard(path):
|
|
|
|
| 194 |
except Exception as exc:
|
| 195 |
raise gr.Error(f"Parameter API error: {exc}")
|
| 196 |
|
| 197 |
+
print(f"[uwcolorkit] month={month} stub={client.using_stub()}")
|
| 198 |
matrix = color.correction_matrix(illum.as_tuple())
|
| 199 |
before = color.encode_display(linear)
|
| 200 |
after = color.encode_display(color.apply_correction(linear, matrix))
|
|
|
|
| 217 |
lat = gr.Number(label="Latitude", value=DEFAULT_LAT, elem_id="scubai_lat", precision=6)
|
| 218 |
lng = gr.Number(label="Longitude", value=DEFAULT_LNG, elem_id="scubai_lng", precision=6)
|
| 219 |
depth = gr.Slider(0, 40, value=DEFAULT_DEPTH, step=1, label="Depth (m)")
|
| 220 |
+
correct_btn = gr.Button("Correct color", variant="primary")
|
| 221 |
+
examples, example_labels = load_examples()
|
| 222 |
if examples:
|
| 223 |
gr.Examples(
|
| 224 |
examples=examples,
|
| 225 |
inputs=[raw_file, lat, lng, depth],
|
| 226 |
label="Or try a sample dive",
|
| 227 |
+
example_labels=example_labels,
|
| 228 |
)
|
| 229 |
with gr.Column():
|
| 230 |
slider = gr.ImageSlider(label="RAW → Corrected", type="numpy", slider_position=50)
|
examples/examples.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
[
|
| 2 |
-
{ "file": "DSC00291.ARW",
|
| 3 |
-
{ "file": "DSC00694.ARW",
|
| 4 |
-
{ "file": "DSC01755.ARW",
|
| 5 |
]
|
|
|
|
| 1 |
[
|
| 2 |
+
{ "file": "DSC00291.ARW", "label": "Clownfish", "depth": 15 },
|
| 3 |
+
{ "file": "DSC00694.ARW", "label": "Example", "depth": 10 },
|
| 4 |
+
{ "file": "DSC01755.ARW", "label": "Grouper", "depth": 8 }
|
| 5 |
]
|