Spaces:
Sleeping
Sleeping
Commit
·
d3b130f
1
Parent(s):
e961059
update
Browse files- Dockerfile +2 -0
- __pycache__/app.cpython-310.pyc +0 -0
- app.py +27 -2
- requirements.txt +1 -1
Dockerfile
CHANGED
|
@@ -11,6 +11,8 @@ WORKDIR /app
|
|
| 11 |
|
| 12 |
COPY --chown=user ./requirements.txt requirements.txt
|
| 13 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
|
|
|
|
|
|
| 14 |
|
| 15 |
COPY --chown=user . /app
|
| 16 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 11 |
|
| 12 |
COPY --chown=user ./requirements.txt requirements.txt
|
| 13 |
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 14 |
+
RUN pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
|
| 15 |
+
RUN pip install torchxrayvision
|
| 16 |
|
| 17 |
COPY --chown=user . /app
|
| 18 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
__pycache__/app.cpython-310.pyc
ADDED
|
Binary file (1.4 kB). View file
|
|
|
app.py
CHANGED
|
@@ -1,7 +1,32 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
app = FastAPI()
|
| 4 |
|
|
|
|
|
|
|
| 5 |
@app.get("/")
|
| 6 |
def greet_json():
|
| 7 |
return {"Hello": "World!"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI,Query,HTTPException
|
| 2 |
+
import torchxrayvision as xrv
|
| 3 |
+
import skimage, torch, torchvision
|
| 4 |
+
import requests
|
| 5 |
|
|
|
|
| 6 |
|
| 7 |
+
app = FastAPI()
|
| 8 |
+
model = xrv.models.DenseNet(weights="densenet121-res224-all")
|
| 9 |
@app.get("/")
|
| 10 |
def greet_json():
|
| 11 |
return {"Hello": "World!"}
|
| 12 |
+
|
| 13 |
+
@app.get('/predict')
|
| 14 |
+
def predict(image_url:str = Query(..., description="URL to a chest X-ray image")):
|
| 15 |
+
try:
|
| 16 |
+
img = skimage.io.imread(image_url)
|
| 17 |
+
img = xrv.datasets.normalize(img,255)
|
| 18 |
+
img = img.mean(2)[None, ...]
|
| 19 |
+
transform = torchvision.transforms.Compose([xrv.datasets.XRayCenterCrop(),xrv.datasets.XRayResizer(224)])
|
| 20 |
+
img = transform(img)
|
| 21 |
+
img = torch.from_numpy(img)
|
| 22 |
+
outputs = model(img[None,...])
|
| 23 |
+
prediction = dict(zip(model.pathologies,outputs[0].detach().numpy().tolist()))
|
| 24 |
+
pred_output = {}
|
| 25 |
+
for k,v in prediction.items():
|
| 26 |
+
pred_output.update({k:round(v,2)})
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
return {"prediction_result":pred_output}
|
| 30 |
+
except Exception as e:
|
| 31 |
+
print(e)
|
| 32 |
+
raise HTTPException(status_code=400, detail=f"Failed to fetch/process image: {str(e)}")
|
requirements.txt
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
fastapi
|
| 2 |
-
uvicorn[standard]
|
|
|
|
| 1 |
fastapi
|
| 2 |
+
uvicorn[standard]
|