-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
35 lines (27 loc) · 943 Bytes
/
api.py
File metadata and controls
35 lines (27 loc) · 943 Bytes
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
import logging
from typing import List
from fastapi import FastAPI, UploadFile
from fastapi.responses import HTMLResponse
from profiler import profile
TMP_FILES_DIR = './tmp_files'
PROFILE_RESULT_DIR = './profile_results'
app = FastAPI()
logger = logging.getLogger(__name__)
@app.get("/", response_class = HTMLResponse)
def index():
f = open(f'frontend/index.html', "r")
return f.read()
@app.get("/results/{result_id}", response_class = HTMLResponse)
def read_results(result_id: str):
f = open(f'{PROFILE_RESULT_DIR}/{result_id}', "r")
return f.read()
@app.post("/profile/")
def profile_file(files: List[UploadFile]):
profile_id = profile_file(files[0])
return {'profile_id': profile_id}
def profile_file(input_file):
file_path = f'{TMP_FILES_DIR}/{input_file.filename}'
with open(file_path, 'wb') as f:
f.write(input_file.file.read())
result_file = profile(file_path)
return result_file