Jaywalker061707 commited on
Commit
2044d2c
·
verified ·
1 Parent(s): 4d0d466

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -23
app.py CHANGED
@@ -1,35 +1,32 @@
1
  import gradio as gr
2
  from datasets import load_dataset
 
 
3
 
4
- def peek_image_field():
5
  ds = load_dataset("MultimodalUniverse/jwst", split="train", streaming=True)
6
- first = next(iter(ds))
 
7
 
8
- keys = list(first.keys())
9
- lines = [f"Keys: {keys}", "Types:"]
10
- lines += [f" {k}: {type(first[k]).__name__}" for k in keys]
 
 
 
 
 
 
11
 
12
- img = first.get("image", {})
13
- img_keys = list(img.keys()) if isinstance(img, dict) else []
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=peek_image_field,
29
  inputs=None,
30
- outputs=gr.Textbox(lines=14, label="Output"),
31
- title="JWST dataset schema peek",
32
- description="Shows keys, types, and image field details for the first record."
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()