Spaces:
Sleeping
Sleeping
Initial Space
Browse files- backend/app.py +21 -8
backend/app.py
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI, File, UploadFile, Form
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
from fastapi.responses import JSONResponse
|
|
@@ -15,12 +34,6 @@ from model import MWT as create_model
|
|
| 15 |
from augmentations import Augmentations
|
| 16 |
from model_histo import BreastCancerClassifier # TensorFlow model
|
| 17 |
|
| 18 |
-
from huggingface_hub import login
|
| 19 |
-
import os
|
| 20 |
-
|
| 21 |
-
hf_token = os.getenv("HF_TOKEN")
|
| 22 |
-
if hf_token:
|
| 23 |
-
login(token=hf_token)
|
| 24 |
|
| 25 |
|
| 26 |
# =====================================================
|
|
@@ -36,7 +49,7 @@ app.add_middleware(
|
|
| 36 |
allow_headers=["*"],
|
| 37 |
)
|
| 38 |
|
| 39 |
-
OUTPUT_DIR = "outputs"
|
| 40 |
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 41 |
app.mount("/outputs", StaticFiles(directory=OUTPUT_DIR), name="outputs")
|
| 42 |
|
|
@@ -55,7 +68,7 @@ print("🔹 Loading MWT model...")
|
|
| 55 |
mwt_model = create_model(num_classes=2).to(device)
|
| 56 |
mwt_model.load_state_dict(torch.load("MWTclass2.pth", map_location=device))
|
| 57 |
mwt_model.eval()
|
| 58 |
-
mwt_class_names = ['
|
| 59 |
|
| 60 |
# =====================================================
|
| 61 |
# Model 3: CIN Classifier
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import shutil
|
| 3 |
+
os.environ["HF_HOME"] = "/tmp/huggingface"
|
| 4 |
+
os.environ["HUGGINGFACE_HUB_CACHE"] = "/tmp/huggingface"
|
| 5 |
+
os.environ["TORCH_HOME"] = "/tmp/torch"
|
| 6 |
+
os.environ["MPLCONFIGDIR"] = "/tmp/matplotlib"
|
| 7 |
+
os.environ["YOLO_CONFIG_DIR"] = "/tmp/Ultralytics"
|
| 8 |
+
|
| 9 |
+
for d in ["/tmp/huggingface", "/tmp/Ultralytics", "/tmp/matplotlib", "/tmp/torch", "/root/.cache"]:
|
| 10 |
+
shutil.rmtree(d, ignore_errors=True)
|
| 11 |
+
|
| 12 |
+
from huggingface_hub import login
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
hf_token = os.getenv("HF_TOKEN")
|
| 17 |
+
if hf_token:
|
| 18 |
+
login(token=hf_token)
|
| 19 |
+
|
| 20 |
from fastapi import FastAPI, File, UploadFile, Form
|
| 21 |
from fastapi.middleware.cors import CORSMiddleware
|
| 22 |
from fastapi.responses import JSONResponse
|
|
|
|
| 34 |
from augmentations import Augmentations
|
| 35 |
from model_histo import BreastCancerClassifier # TensorFlow model
|
| 36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
|
| 39 |
# =====================================================
|
|
|
|
| 49 |
allow_headers=["*"],
|
| 50 |
)
|
| 51 |
|
| 52 |
+
OUTPUT_DIR = "/tmp/outputs"
|
| 53 |
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 54 |
app.mount("/outputs", StaticFiles(directory=OUTPUT_DIR), name="outputs")
|
| 55 |
|
|
|
|
| 68 |
mwt_model = create_model(num_classes=2).to(device)
|
| 69 |
mwt_model.load_state_dict(torch.load("MWTclass2.pth", map_location=device))
|
| 70 |
mwt_model.eval()
|
| 71 |
+
mwt_class_names = ['Negative', 'Positive']
|
| 72 |
|
| 73 |
# =====================================================
|
| 74 |
# Model 3: CIN Classifier
|