nbroad commited on
Commit
82fa34b
·
verified ·
1 Parent(s): e95adbb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ from fastapi import FastAPI, Request, Form
3
+ from fastapi.templating import Jinja2Templates
4
+ from fastapi.responses import HTMLResponse
5
+ from fastapi.staticfiles import StaticFiles
6
+ import wandb
7
+
8
+ app = FastAPI()
9
+ templates = Jinja2Templates(directory="templates")
10
+
11
+ @app.get("/", response_class=HTMLResponse)
12
+ async def index(request: Request):
13
+ return templates.TemplateResponse("index.html", {"request": request})
14
+
15
+ @app.post("/", response_class=HTMLResponse)
16
+ async def process_form(
17
+ request: Request,
18
+ token: str = Form(...),
19
+ entity: str = Form(...),
20
+ project: str = Form(...),
21
+ run_id: str = Form(...)
22
+ ):
23
+ try:
24
+ wandb.login(token)
25
+ api = wandb.Api()
26
+ run_path = f"{entity}/{project}/runs/{run_id}"
27
+ run = api.run(run_path)
28
+ iframe_html = run.to_html()
29
+ return templates.TemplateResponse(
30
+ "index.html",
31
+ {
32
+ "request": request,
33
+ "iframe_html": iframe_html
34
+ }
35
+ )
36
+ except Exception as e:
37
+ return templates.TemplateResponse(
38
+ "index.html",
39
+ {
40
+ "request": request,
41
+ "error": str(e)
42
+ }
43
+ )