Spaces:
Sleeping
Sleeping
Commit
·
dcb533e
1
Parent(s):
d6684f1
tb update
Browse files- Dockerfile +1 -0
- __pycache__/app.cpython-310.pyc +0 -0
- app.py +19 -5
Dockerfile
CHANGED
|
@@ -15,6 +15,7 @@ RUN pip install torch torchvision --index-url https://download.pytorch.org/whl/c
|
|
| 15 |
RUN pip install torchxrayvision
|
| 16 |
RUN pip install grad-cam
|
| 17 |
RUN pip install opencv-python
|
|
|
|
| 18 |
|
| 19 |
COPY --chown=user . /app
|
| 20 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 15 |
RUN pip install torchxrayvision
|
| 16 |
RUN pip install grad-cam
|
| 17 |
RUN pip install opencv-python
|
| 18 |
+
RUN pip install transformers
|
| 19 |
|
| 20 |
COPY --chown=user . /app
|
| 21 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
__pycache__/app.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/app.cpython-310.pyc and b/__pycache__/app.cpython-310.pyc differ
|
|
|
app.py
CHANGED
|
@@ -5,9 +5,11 @@ import cv2
|
|
| 5 |
import numpy as np
|
| 6 |
from pytorch_grad_cam import GradCAM
|
| 7 |
from pytorch_grad_cam.utils.model_targets import ClassifierOutputTarget
|
| 8 |
-
|
| 9 |
-
|
| 10 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
|
|
|
| 11 |
app = FastAPI()
|
| 12 |
# Add the frontend origin here
|
| 13 |
origins = [
|
|
@@ -25,7 +27,7 @@ app.add_middleware(
|
|
| 25 |
|
| 26 |
|
| 27 |
model = xrv.models.DenseNet(weights="densenet121-res224-all")
|
| 28 |
-
|
| 29 |
|
| 30 |
|
| 31 |
|
|
@@ -82,8 +84,20 @@ def predict(image_url:str = Query(..., description="URL to a chest X-ray image")
|
|
| 82 |
pred_output.update({k:round(v,2)})
|
| 83 |
|
| 84 |
get_bounding_box = show_anomaly_bounding_box(img,model=model)
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
except Exception as e:
|
| 88 |
print(e)
|
| 89 |
raise HTTPException(status_code=400, detail=f"Failed to fetch/process image: {str(e)}")
|
|
|
|
| 5 |
import numpy as np
|
| 6 |
from pytorch_grad_cam import GradCAM
|
| 7 |
from pytorch_grad_cam.utils.model_targets import ClassifierOutputTarget
|
| 8 |
+
from transformers import pipeline
|
| 9 |
+
from PIL import Image
|
| 10 |
from fastapi.middleware.cors import CORSMiddleware
|
| 11 |
+
import requests
|
| 12 |
+
|
| 13 |
app = FastAPI()
|
| 14 |
# Add the frontend origin here
|
| 15 |
origins = [
|
|
|
|
| 27 |
|
| 28 |
|
| 29 |
model = xrv.models.DenseNet(weights="densenet121-res224-all")
|
| 30 |
+
tb_classifier =pipeline("image-classification",model="vimal-humantics/dinov2-base-xray-224-finetuned-tb")
|
| 31 |
|
| 32 |
|
| 33 |
|
|
|
|
| 84 |
pred_output.update({k:round(v,2)})
|
| 85 |
|
| 86 |
get_bounding_box = show_anomaly_bounding_box(img,model=model)
|
| 87 |
+
# TB detection
|
| 88 |
+
|
| 89 |
+
image = Image.open(requests.get(image_url, stream=True).raw)
|
| 90 |
+
tb_finding = tb_classifier(images=image)
|
| 91 |
+
tb_label = tb_finding[0]['label']
|
| 92 |
+
print(tb_label)
|
| 93 |
+
tb_score = round(tb_finding[0]['score'],2)
|
| 94 |
+
tb_output = 0
|
| 95 |
+
if tb_label == "normal":
|
| 96 |
+
tb_output = 1-tb_score
|
| 97 |
+
else:
|
| 98 |
+
tb_output = tb_score
|
| 99 |
+
|
| 100 |
+
return {"prediction_result":pred_output,"bounding_box":{pred_label:get_bounding_box},"tb_finding":tb_output}
|
| 101 |
except Exception as e:
|
| 102 |
print(e)
|
| 103 |
raise HTTPException(status_code=400, detail=f"Failed to fetch/process image: {str(e)}")
|