Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -20,22 +20,21 @@ app.add_middleware(
|
|
| 20 |
allow_headers=["*"],
|
| 21 |
)
|
| 22 |
|
| 23 |
-
# ✅ Corrected path to relative static directory
|
| 24 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 25 |
|
| 26 |
@app.get("/")
|
| 27 |
def read_root():
|
| 28 |
return FileResponse("static/index.html")
|
| 29 |
|
| 30 |
-
# Load
|
| 31 |
-
model = models.resnet50(
|
|
|
|
| 32 |
model.eval()
|
| 33 |
|
| 34 |
# Load labels
|
| 35 |
with open("imagenet_classes.txt") as f:
|
| 36 |
labels = [line.strip() for line in f]
|
| 37 |
|
| 38 |
-
# Define image transforms
|
| 39 |
transform = transforms.Compose([
|
| 40 |
transforms.Resize(256),
|
| 41 |
transforms.CenterCrop(224),
|
|
|
|
| 20 |
allow_headers=["*"],
|
| 21 |
)
|
| 22 |
|
|
|
|
| 23 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 24 |
|
| 25 |
@app.get("/")
|
| 26 |
def read_root():
|
| 27 |
return FileResponse("static/index.html")
|
| 28 |
|
| 29 |
+
# ✅ Load model without downloading
|
| 30 |
+
model = models.resnet50()
|
| 31 |
+
model.load_state_dict(torch.load("resnet50_weights.pth", map_location="cpu"))
|
| 32 |
model.eval()
|
| 33 |
|
| 34 |
# Load labels
|
| 35 |
with open("imagenet_classes.txt") as f:
|
| 36 |
labels = [line.strip() for line in f]
|
| 37 |
|
|
|
|
| 38 |
transform = transforms.Compose([
|
| 39 |
transforms.Resize(256),
|
| 40 |
transforms.CenterCrop(224),
|