Spaces:
Sleeping
Sleeping
BhuiyanMasum commited on
Commit ·
4d61771
1
Parent(s): 1a9e80b
Upload model files
Browse files
app.py
CHANGED
|
@@ -5,12 +5,14 @@ from fastapi import FastAPI, UploadFile, File
|
|
| 5 |
from fastapi.responses import JSONResponse
|
| 6 |
from pydantic import BaseModel
|
| 7 |
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
model_uri = "model.pth"
|
| 12 |
-
model = torch.load(model_uri)
|
| 13 |
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# Define input schema for JSON requests
|
| 16 |
class ImageInput(BaseModel):
|
|
|
|
| 5 |
from fastapi.responses import JSONResponse
|
| 6 |
from pydantic import BaseModel
|
| 7 |
|
| 8 |
+
# Allowlist the required global for PyTorch model loading
|
| 9 |
+
torch.serialization.add_safe_globals(['cloudpickle.cloudpickle._make_skeleton_class'])
|
| 10 |
|
| 11 |
+
app = FastAPI()
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
# Load the pre-trained model from within the container
|
| 14 |
+
model_uri = "/app/model.pth"
|
| 15 |
+
model = torch.load(model_uri, weights_only=True)
|
| 16 |
|
| 17 |
# Define input schema for JSON requests
|
| 18 |
class ImageInput(BaseModel):
|