Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,17 @@
|
|
| 1 |
-
|
| 2 |
from fastapi import FastAPI, UploadFile, File
|
| 3 |
-
from fastapi.responses import FileResponse
|
| 4 |
from fastapi.staticfiles import StaticFiles
|
| 5 |
-
import os
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
| 9 |
-
# Mount frontend files
|
| 10 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
| 11 |
|
| 12 |
-
@app.post("/
|
| 13 |
-
async def
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
result = [("red", "blue", data1)]
|
| 18 |
-
|
| 19 |
-
if file2:
|
| 20 |
-
content2 = await file2.read()
|
| 21 |
-
data2 = parse_dcm_assembly(content2)
|
| 22 |
-
result.append(("purple", "orange", data2))
|
| 23 |
-
|
| 24 |
-
with open("static/parsed_data.json", "w") as f:
|
| 25 |
-
json.dump({"files": result}, f)
|
| 26 |
-
|
| 27 |
-
return {"status": "ok"}
|
| 28 |
|
| 29 |
-
@app.get("/parsed_data.json")
|
| 30 |
-
def get_parsed():
|
| 31 |
-
return FileResponse("static/parsed_data.json")
|
| 32 |
|
| 33 |
def parse_dcm_assembly(file_bytes):
|
| 34 |
lines = file_bytes.decode("utf-8").splitlines()
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI, UploadFile, File
|
| 2 |
+
from fastapi.responses import FileResponse, JSONResponse
|
| 3 |
from fastapi.staticfiles import StaticFiles
|
| 4 |
+
import os
|
| 5 |
|
| 6 |
app = FastAPI()
|
| 7 |
|
|
|
|
| 8 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
| 9 |
|
| 10 |
+
@app.post("/parse")
|
| 11 |
+
async def parse_file(file: UploadFile = File(...)):
|
| 12 |
+
content = await file.read()
|
| 13 |
+
return JSONResponse(content=parse_dcm_assembly(content))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
def parse_dcm_assembly(file_bytes):
|
| 17 |
lines = file_bytes.decode("utf-8").splitlines()
|