Spaces:
Build error
Build error
| """FastAPI micro-service for enterprise EHR integration""" | |
| from fastapi import FastAPI, UploadFile, File, Form | |
| import openai, pydicom, numpy as np, io | |
| from PIL import Image | |
| import os, tempfile | |
| app = FastAPI() | |
| openai.api_key = os.getenv("OPENAI_API_KEY") | |
| async def radiology(file: UploadFile = File(...)): | |
| data = await file.read() | |
| if file.filename.endswith(".dcm"): | |
| ds = pydicom.dcmread(io.BytesIO(data)) | |
| arr = ds.pixel_array.tolist() | |
| else: | |
| img = Image.open(io.BytesIO(data)) | |
| arr = np.array(img).tolist() | |
| rpt = openai.chat.completions.create(model="gpt-4o-mini", messages=[{"role":"user","content":"Analyze this study."}], images=[arr]).choices[0].message.content | |
| return {"report": rpt} | |
| --------------------------------------------------------------------- | |