Spaces:
Runtime error
Runtime error
Commit ·
bf9bd7f
1
Parent(s): 75c0461
Adds fixes for updated deployment in Azure
Browse files- Dockerfile +3 -1
- handler.py +8 -3
- main.py +13 -0
Dockerfile
CHANGED
|
@@ -7,8 +7,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
| 7 |
build-essential \
|
| 8 |
gcc \
|
| 9 |
g++ \
|
| 10 |
-
libgl1-mesa-glx \
|
| 11 |
libglib2.0-0 \
|
|
|
|
|
|
|
|
|
|
| 12 |
&& rm -rf /var/lib/apt/lists/*
|
| 13 |
|
| 14 |
COPY requirements.txt .
|
|
|
|
| 7 |
build-essential \
|
| 8 |
gcc \
|
| 9 |
g++ \
|
|
|
|
| 10 |
libglib2.0-0 \
|
| 11 |
+
libsm6 \
|
| 12 |
+
libxext6 \
|
| 13 |
+
libxrender-dev \
|
| 14 |
&& rm -rf /var/lib/apt/lists/*
|
| 15 |
|
| 16 |
COPY requirements.txt .
|
handler.py
CHANGED
|
@@ -237,8 +237,9 @@ class EndpointHandler:
|
|
| 237 |
# It's a base64-encoded image
|
| 238 |
img = self.load_image_from_base64(image_input)
|
| 239 |
else:
|
| 240 |
-
#
|
| 241 |
-
|
|
|
|
| 242 |
|
| 243 |
if img is None:
|
| 244 |
print(f"Failed to load image: {image_input}")
|
|
@@ -260,7 +261,11 @@ class EndpointHandler:
|
|
| 260 |
profile_media_db = [item for item in embeddings_db if 'image_url' in item and 'profile-media' in item['image_url']]
|
| 261 |
print(f"Debug: Profile-media embeddings: {len(profile_media_db)}")
|
| 262 |
|
| 263 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
print(f"Debug: Filtered by gender '{gender}': {len(filtered_db)}")
|
| 265 |
|
| 266 |
if len(filtered_db) == 0:
|
|
|
|
| 237 |
# It's a base64-encoded image
|
| 238 |
img = self.load_image_from_base64(image_input)
|
| 239 |
else:
|
| 240 |
+
# It's a local file path reference - convert to full Azure blob URL
|
| 241 |
+
blob_url = f"https://koottuprod.blob.core.windows.net/koottu-media/{image_input}"
|
| 242 |
+
img = self.load_image_from_url(blob_url)
|
| 243 |
|
| 244 |
if img is None:
|
| 245 |
print(f"Failed to load image: {image_input}")
|
|
|
|
| 261 |
profile_media_db = [item for item in embeddings_db if 'image_url' in item and 'profile-media' in item['image_url']]
|
| 262 |
print(f"Debug: Profile-media embeddings: {len(profile_media_db)}")
|
| 263 |
|
| 264 |
+
# Filter by gender: if 'all', include all items with gender field; otherwise filter by specific gender
|
| 265 |
+
if gender == 'all':
|
| 266 |
+
filtered_db = [item for item in profile_media_db if 'gender' in item and 'embedding' in item]
|
| 267 |
+
else:
|
| 268 |
+
filtered_db = [item for item in profile_media_db if 'gender' in item and item['gender'] == gender and 'embedding' in item]
|
| 269 |
print(f"Debug: Filtered by gender '{gender}': {len(filtered_db)}")
|
| 270 |
|
| 271 |
if len(filtered_db) == 0:
|
main.py
CHANGED
|
@@ -54,6 +54,15 @@ def index():
|
|
| 54 |
# Serve the UI if needed, or just a welcome message
|
| 55 |
return "<h2>FaceMatch FastAPI is running!</h2>"
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
@app.post("/api/init_user")
|
| 58 |
def init_user():
|
| 59 |
user_id = str(uuid.uuid4())
|
|
@@ -163,6 +172,10 @@ async def get_recommendations(
|
|
| 163 |
raise HTTPException(status_code=400, detail="No query images provided")
|
| 164 |
|
| 165 |
similar_images = face_handler.find_similar_images_aggregate(query_images, gender, top_n)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
return {"similar_images": similar_images}
|
| 167 |
except Exception as e:
|
| 168 |
return JSONResponse(status_code=500, content={"error": str(e)})
|
|
|
|
| 54 |
# Serve the UI if needed, or just a welcome message
|
| 55 |
return "<h2>FaceMatch FastAPI is running!</h2>"
|
| 56 |
|
| 57 |
+
@app.get("/health")
|
| 58 |
+
def health_check():
|
| 59 |
+
"""Health check endpoint for Azure Container Apps"""
|
| 60 |
+
return {
|
| 61 |
+
"status": "healthy",
|
| 62 |
+
"service": "facematch-api",
|
| 63 |
+
"model_loaded": face_handler.app is not None
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
@app.post("/api/init_user")
|
| 67 |
def init_user():
|
| 68 |
user_id = str(uuid.uuid4())
|
|
|
|
| 172 |
raise HTTPException(status_code=400, detail="No query images provided")
|
| 173 |
|
| 174 |
similar_images = face_handler.find_similar_images_aggregate(query_images, gender, top_n)
|
| 175 |
+
|
| 176 |
+
if not similar_images:
|
| 177 |
+
return {"message": "No suggestions found please try with other images."}
|
| 178 |
+
|
| 179 |
return {"similar_images": similar_images}
|
| 180 |
except Exception as e:
|
| 181 |
return JSONResponse(status_code=500, content={"error": str(e)})
|