File size: 2,791 Bytes
8edfe19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import gradio as gr
import wandb
import requests
from PIL import Image
from io import BytesIO

# Connect to W&B
api = wandb.Api()

# Replace this with your correct run path
ENTITY = "jarrett-defreitas-university-of-rhode-island"  # your wandb username or team
PROJECT = "pickup-and-place"
RUN_ID = "trr5oagz"  # NOT the display name; the ID like "3xi2sld8"

run = api.run(f"{ENTITY}/{PROJECT}/{RUN_ID}")

# Collect all images and metrics
logged_images = []
logged_scalars = []

# Scan all rows of logged history
for row in run.scan_history():
    for key, val in row.items():
        # Handle images correctly
        if isinstance(val, list):
            for item in val:
                if isinstance(item, wandb.data_types.Image):
                    logged_images.append((key, item.url))
        elif isinstance(val, wandb.data_types.Image):
            logged_images.append((key, val.url))
        
        # Handle scalars (numbers like loss, accuracy)
        if isinstance(val, (int, float)):
            logged_scalars.append((key, val))

# Debug: show what was found
print("Logged Images:", logged_images)
print("Logged Scalars:", logged_scalars)

# --------------------------------------
# 3. Prepare Dropdown Choices
# --------------------------------------

image_keys = [key for key, _ in logged_images]
scalar_keys = [key for key, _ in logged_scalars]

# --------------------------------------
# 4. Define viewer functions
# --------------------------------------

# View image by selected key
def view_image(selected_key):
    for key, url in logged_images:
        if key == selected_key:
            response = requests.get(url)
            if response.status_code == 200:
                return Image.open(BytesIO(response.content))
            else:
                return None
    return None

# View scalar (number) by selected key
def view_scalar(selected_key):
    for key, value in logged_scalars:
        if key == selected_key:
            return f"{key}: {value}"
    return "Not found"

# --------------------------------------
# 5. Build the Gradio App
# --------------------------------------

with gr.Blocks() as demo:
    gr.Markdown("# 📈 WandB Run Viewer")
    gr.Markdown("View images and metrics logged to a specific W&B run.")

    with gr.Tab("Logged Images"):
        img_selector = gr.Dropdown(choices=image_keys, label="Select an Image Key")
        img_display = gr.Image()

        img_selector.change(fn=view_image, inputs=img_selector, outputs=img_display)

    with gr.Tab("Logged Scalars"):
        scalar_selector = gr.Dropdown(choices=scalar_keys, label="Select a Scalar Metric")
        scalar_display = gr.Textbox()

        scalar_selector.change(fn=view_scalar, inputs=scalar_selector, outputs=scalar_display)

demo.launch(share=True)