-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
61 lines (46 loc) · 1.35 KB
/
main.py
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
from pathlib import Path
from fastapi import FastAPI, File, UploadFile, Form
from fastapi.responses import FileResponse
from graph_extractor import GraphExtractor
app = FastAPI()
jsons = Path('.')
frontend = Path('dist/')
extractor = GraphExtractor()
@app.get("/")
async def root():
return FileResponse(frontend / 'index.html')
@app.get("/main.js")
async def js():
return FileResponse(frontend / 'main.js')
@app.get("/main.css")
async def css():
return FileResponse(frontend / 'main.css')
@app.post("/upload")
async def upload_data(file: UploadFile = File(...), language: str = Form(...)):
code = b''
while content := await file.read(1024): # async read chunk
code += content # async write chunk
data = extractor.extract_pipeline(code, language)
# print(data)
return {
"type": "graph",
"error": None,
"values": {
"code": code.decode('utf-8'),
"nodes": data["nodes"],
"edges": data["edges"],
}
}
@app.post("/update")
async def update_code(code: str = Form(...), language: str = Form(...)):
data = extractor.extract_pipeline(code, language)
# print(data)
return {
"type": "graph",
"error": None,
"values": {
"code": code,
"nodes": data["nodes"],
"edges": data["edges"],
}
}