File size: 1,801 Bytes
32458a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import FastAPI, UploadFile, File, Form
from fastapi.responses import JSONResponse
from maira2Service import generate_report
from readimageService import read_image

app = FastAPI()

@app.post("/generate/frontal")
async def generate_frontal_report(frontal: UploadFile = File(...)):
    try:
        frontal_img = read_image(frontal)
        report = generate_report(frontal_image=frontal_img)
        return JSONResponse(content={"report": report})
    except Exception as e:
        return JSONResponse(status_code=500, content={"error": str(e)})

@app.post("/generate/lateral")
async def generate_lateral_report(
    frontal: UploadFile = File(...),
    lateral: UploadFile = File(...),
    indication: str = Form(...),
    technique: str = Form(...),
    comparison: str = Form(...)
):
    try:
        frontal_img = read_image(frontal)
        lateral_img = read_image(lateral)
        report = generate_report(
            frontal_image=frontal_img,
            lateral_image=lateral_img,
            indication=indication,
            technique=technique,
            comparison=comparison
        )
        return JSONResponse(content={"report": report})
    except Exception as e:
        return JSONResponse(status_code=500, content={"error": str(e)})
    
@app.post("/generate/lateral/both")
async def generate_lateral_both_report(
    frontal: UploadFile = File(...),
    lateral: UploadFile = File(...),
):
    try:
        frontal_img = read_image(frontal)
        lateral_img = read_image(lateral)
        report = generate_report(
            frontal_image=frontal_img,
            lateral_image=lateral_img,
        )
        return JSONResponse(content={"report": report})
    except Exception as e:
        return JSONResponse(status_code=500, content={"error": str(e)})