Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,10 @@
|
|
1 |
-
|
2 |
from fastapi import FastAPI, Request, Form
|
3 |
from fastapi.templating import Jinja2Templates
|
4 |
from fastapi.responses import HTMLResponse
|
5 |
import wandb
|
6 |
import os
|
|
|
7 |
|
8 |
app = FastAPI()
|
9 |
templates = Jinja2Templates(directory="./")
|
@@ -15,24 +16,22 @@ async def index(request: Request):
|
|
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 |
-
#
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
api = wandb.Api()
|
30 |
run_path = f"{entity}/{project}/runs/{run_id}"
|
31 |
run = api.run(run_path)
|
32 |
iframe_html = run.to_html()
|
33 |
-
|
34 |
-
# Modify the iframe height to be 100%
|
35 |
-
iframe_html = re.sub(r'height:\d+px', 'height:100%', iframe_html)
|
36 |
|
37 |
return templates.TemplateResponse(
|
38 |
"index.html",
|
|
|
1 |
+
# app.py
|
2 |
from fastapi import FastAPI, Request, Form
|
3 |
from fastapi.templating import Jinja2Templates
|
4 |
from fastapi.responses import HTMLResponse
|
5 |
import wandb
|
6 |
import os
|
7 |
+
from typing import Optional
|
8 |
|
9 |
app = FastAPI()
|
10 |
templates = Jinja2Templates(directory="./")
|
|
|
16 |
@app.post("/", response_class=HTMLResponse)
|
17 |
async def process_form(
|
18 |
request: Request,
|
19 |
+
token: Optional[str] = Form(None), # Make token optional
|
20 |
entity: str = Form(...),
|
21 |
project: str = Form(...),
|
22 |
run_id: str = Form(...)
|
23 |
):
|
24 |
try:
|
25 |
+
# Only set token and login if one is provided
|
26 |
+
if token and token.strip():
|
27 |
+
os.environ["WANDB_API_KEY"] = token
|
28 |
+
else:
|
29 |
+
|
30 |
api = wandb.Api()
|
31 |
run_path = f"{entity}/{project}/runs/{run_id}"
|
32 |
run = api.run(run_path)
|
33 |
iframe_html = run.to_html()
|
34 |
+
iframe_html = iframe_html.replace('height:420px', 'height:100%')
|
|
|
|
|
35 |
|
36 |
return templates.TemplateResponse(
|
37 |
"index.html",
|