Spaces:
Sleeping
Sleeping
added frontend cors
Browse files- app/main.py +1 -1
- model/eye_disease_model.pth +0 -3
- utils/__pycache__/image_utils.cpython-39.pyc +0 -0
- utils/image_utils.py +0 -53
app/main.py
CHANGED
|
@@ -14,7 +14,7 @@ app = FastAPI()
|
|
| 14 |
# Add CORS middleware to allow requests from your frontend
|
| 15 |
app.add_middleware(
|
| 16 |
CORSMiddleware,
|
| 17 |
-
allow_origins=["http://localhost:5173"], # Set your frontend URL here
|
| 18 |
allow_credentials=True,
|
| 19 |
allow_methods=["*"], # Allow all HTTP methods (GET, POST, etc.)
|
| 20 |
allow_headers=["*"], # Allow all headers
|
|
|
|
| 14 |
# Add CORS middleware to allow requests from your frontend
|
| 15 |
app.add_middleware(
|
| 16 |
CORSMiddleware,
|
| 17 |
+
allow_origins=["http://localhost:5173","https://eye-disease-detection-frontend.vercel.app/"], # Set your frontend URL here
|
| 18 |
allow_credentials=True,
|
| 19 |
allow_methods=["*"], # Allow all HTTP methods (GET, POST, etc.)
|
| 20 |
allow_headers=["*"], # Allow all headers
|
model/eye_disease_model.pth
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:27a2e05d406289e1ac51649c2605d30d32cf917a3c1a9044e03aa8bcbb35f42a
|
| 3 |
-
size 45845690
|
|
|
|
|
|
|
|
|
|
|
|
utils/__pycache__/image_utils.cpython-39.pyc
DELETED
|
Binary file (1.5 kB)
|
|
|
utils/image_utils.py
DELETED
|
@@ -1,53 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
from torchvision import transforms, models
|
| 3 |
-
from PIL import Image
|
| 4 |
-
import io
|
| 5 |
-
import os
|
| 6 |
-
import torch.nn as nn
|
| 7 |
-
|
| 8 |
-
# Model path
|
| 9 |
-
MODEL_PATH = r"D:\College Works\ML_project\Web\api\app\model\eye_disease_model.pth"
|
| 10 |
-
|
| 11 |
-
# Load model
|
| 12 |
-
def load_model(model_path=MODEL_PATH):
|
| 13 |
-
if not os.path.exists(model_path): # Check if model path exists
|
| 14 |
-
raise FileNotFoundError(f"Model file not found at: {model_path}")
|
| 15 |
-
|
| 16 |
-
# Define the model (with custom layers as per your training)
|
| 17 |
-
model = models.resnet18(pretrained=False)
|
| 18 |
-
|
| 19 |
-
# Freeze the layers and modify the final layers
|
| 20 |
-
for param in model.parameters():
|
| 21 |
-
param.requires_grad = False
|
| 22 |
-
|
| 23 |
-
num_ftrs = model.fc.in_features
|
| 24 |
-
model.fc = nn.Sequential(
|
| 25 |
-
nn.Linear(num_ftrs, 512),
|
| 26 |
-
nn.ReLU(),
|
| 27 |
-
nn.Dropout(0.5),
|
| 28 |
-
nn.Linear(512, 4) # Assuming 4 output classes for your eye disease model
|
| 29 |
-
)
|
| 30 |
-
|
| 31 |
-
# Load the trained weights into the model
|
| 32 |
-
model.load_state_dict(torch.load(model_path, map_location=torch.device("cpu")))
|
| 33 |
-
|
| 34 |
-
# Set the model to evaluation mode
|
| 35 |
-
model.eval()
|
| 36 |
-
|
| 37 |
-
return model
|
| 38 |
-
|
| 39 |
-
# Define image transformation (should match test-time transforms)
|
| 40 |
-
def get_transform():
|
| 41 |
-
return transforms.Compose([
|
| 42 |
-
transforms.Resize((224, 224)),
|
| 43 |
-
transforms.ToTensor(),
|
| 44 |
-
transforms.Normalize(mean=[0.485, 0.456, 0.406],
|
| 45 |
-
std=[0.229, 0.224, 0.225])
|
| 46 |
-
])
|
| 47 |
-
|
| 48 |
-
# Process the incoming image
|
| 49 |
-
def process_image(contents):
|
| 50 |
-
image = Image.open(io.BytesIO(contents)).convert("RGB")
|
| 51 |
-
transform = get_transform()
|
| 52 |
-
image = transform(image).unsqueeze(0) # Add batch dimension
|
| 53 |
-
return image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|