File size: 1,722 Bytes
eee7e28
82fa34b
 
 
 
394105b
82fa34b
 
ee1c8ff
82fa34b
 
 
 
 
 
 
 
 
 
 
 
 
 
394105b
 
 
 
 
82fa34b
 
 
 
eee7e28
 
 
 
82fa34b
 
 
394105b
 
 
 
 
82fa34b
 
 
 
 
 
 
394105b
 
 
 
 
82fa34b
 
 
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
import re
from fastapi import FastAPI, Request, Form
from fastapi.templating import Jinja2Templates
from fastapi.responses import HTMLResponse
import wandb
import os

app = FastAPI()
templates = Jinja2Templates(directory="./")

@app.get("/", response_class=HTMLResponse)
async def index(request: Request):
    return templates.TemplateResponse("index.html", {"request": request})

@app.post("/", response_class=HTMLResponse)
async def process_form(
    request: Request,
    token: str = Form(...),
    entity: str = Form(...),
    project: str = Form(...),
    run_id: str = Form(...)
):
    try:
        # Set the token as an environment variable
        os.environ["WANDB_API_KEY"] = token
        # Login with the anonymous parameter set
        wandb.login(key=token)
        
        api = wandb.Api()
        run_path = f"{entity}/{project}/runs/{run_id}"
        run = api.run(run_path)
        iframe_html = run.to_html()

        # Modify the iframe height to be 100%
        iframe_html = re.sub(r'height:\d+px', 'height:100%', iframe_html)
        
        return templates.TemplateResponse(
            "index.html", 
            {
                "request": request,
                "token": token,
                "entity": entity,
                "project": project,
                "run_id": run_id,
                "iframe_html": iframe_html
            }
        )
    except Exception as e:
        return templates.TemplateResponse(
            "index.html", 
            {
                "request": request,
                "token": token,
                "entity": entity,
                "project": project,
                "run_id": run_id,
                "error": str(e)
            }
        )