Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,32 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from datasets import load_dataset
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
def
|
| 5 |
ds = load_dataset("MultimodalUniverse/jwst", split="train", streaming=True)
|
| 6 |
-
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
lines.append(f"image subkeys: {img_keys}")
|
| 15 |
-
path = img.get("path", None) if isinstance(img, dict) else None
|
| 16 |
-
if isinstance(path, str):
|
| 17 |
-
lines.append(f"image path: {path[:200]}")
|
| 18 |
-
|
| 19 |
-
# brief text previews if present
|
| 20 |
-
previews = [f" {k}: {first[k][:200]}" for k in keys if isinstance(first[k], str) and first[k]]
|
| 21 |
-
if previews:
|
| 22 |
-
lines.append("Text previews:")
|
| 23 |
-
lines += previews
|
| 24 |
-
|
| 25 |
-
return "\n".join(lines)
|
| 26 |
|
| 27 |
demo = gr.Interface(
|
| 28 |
-
fn=
|
| 29 |
inputs=None,
|
| 30 |
-
outputs=gr.
|
| 31 |
-
title="JWST
|
| 32 |
-
description="
|
| 33 |
)
|
| 34 |
|
| 35 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from datasets import load_dataset
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
|
| 6 |
+
def show_first():
|
| 7 |
ds = load_dataset("MultimodalUniverse/jwst", split="train", streaming=True)
|
| 8 |
+
rec = next(iter(ds))
|
| 9 |
+
img = rec["image"]
|
| 10 |
|
| 11 |
+
# convert the flux array to a viewable grayscale image
|
| 12 |
+
flux = np.array(img["flux"], dtype=np.float32)
|
| 13 |
+
lo = np.percentile(flux, 1)
|
| 14 |
+
hi = np.percentile(flux, 99)
|
| 15 |
+
if hi <= lo: # fallback if data is odd
|
| 16 |
+
lo, hi = float(flux.min()), float(flux.max())
|
| 17 |
+
norm = np.clip((flux - lo) / (hi - lo + 1e-9), 0, 1)
|
| 18 |
+
arr = (norm * 255).astype(np.uint8)
|
| 19 |
+
pil = Image.fromarray(arr, mode="L")
|
| 20 |
|
| 21 |
+
caption = f"object_id: {rec.get('object_id')}, band: {img.get('band')}"
|
| 22 |
+
return pil, caption
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
demo = gr.Interface(
|
| 25 |
+
fn=show_first,
|
| 26 |
inputs=None,
|
| 27 |
+
outputs=[gr.Image(type="pil", label="Preview"), gr.Textbox(label="Info", lines=2)],
|
| 28 |
+
title="JWST sample preview",
|
| 29 |
+
description="First streamed record as image + a little metadata."
|
| 30 |
)
|
| 31 |
|
| 32 |
demo.launch()
|