Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from datasets import load_dataset | |
| import numpy as np | |
| from PIL import Image | |
| def show_first(): | |
| ds = load_dataset("MultimodalUniverse/jwst", split="train", streaming=True) | |
| rec = next(iter(ds)) | |
| img = rec["image"] | |
| # convert the flux array to a viewable grayscale image | |
| flux = np.array(img["flux"], dtype=np.float32) | |
| lo = np.percentile(flux, 1) | |
| hi = np.percentile(flux, 99) | |
| if hi <= lo: # fallback if data is odd | |
| lo, hi = float(flux.min()), float(flux.max()) | |
| norm = np.clip((flux - lo) / (hi - lo + 1e-9), 0, 1) | |
| arr = (norm * 255).astype(np.uint8) | |
| pil = Image.fromarray(arr, mode="L") | |
| caption = f"object_id: {rec.get('object_id')}, band: {img.get('band')}" | |
| return pil, caption | |
| demo = gr.Interface( | |
| fn=show_first, | |
| inputs=None, | |
| outputs=[gr.Image(type="pil", label="Preview"), gr.Textbox(label="Info", lines=2)], | |
| title="JWST sample preview", | |
| description="First streamed record as image + a little metadata." | |
| ) | |
| demo.launch() |