Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -98,8 +98,6 @@ def cosine_similarity(vec1, vec2):
|
|
| 98 |
return float(np.dot(vec1, vec2) / (np.linalg.norm(vec1) * np.linalg.norm(vec2)))
|
| 99 |
|
| 100 |
def segment_guided_object(image: Image.Image, object_label: str) -> Image.Image:
|
| 101 |
-
# --- CORRECTED PROMPT ---
|
| 102 |
-
# Use only the object name for a simpler, more effective prompt.
|
| 103 |
prompt = f"a {object_label}."
|
| 104 |
|
| 105 |
print(f" [Segment] Using simple prompt: '{prompt}'")
|
|
@@ -185,24 +183,10 @@ def compare_items():
|
|
| 185 |
payload = request.json
|
| 186 |
query_item = payload['queryItem']
|
| 187 |
search_list = payload['searchList']
|
| 188 |
-
print(f"\n[COMPARE] Received {len(search_list)} candidates for '{query_item.get('objectName')}'.")
|
| 189 |
|
| 190 |
-
# --- HIERARCHICAL FILTERING ---
|
| 191 |
-
|
| 192 |
-
if query_label:
|
| 193 |
-
search_list = [item for item in search_list if item.get('canonicalLabel') == query_label]
|
| 194 |
-
print(f" [FILTER] After object name: {len(search_list)} candidates remain.")
|
| 195 |
-
|
| 196 |
-
query_date_str = query_item.get('dateLost') or query_item.get('dateFound')
|
| 197 |
-
query_date = datetime.fromisoformat(query_date_str.replace('Z', '+00:00'))
|
| 198 |
-
one_week = timedelta(days=7)
|
| 199 |
-
search_list = [item for item in search_list if abs(query_date - datetime.fromisoformat((item.get('dateFound') or item.get('dateLost')).replace('Z', '+00:00'))) <= one_week]
|
| 200 |
-
print(f" [FILTER] After date: {len(search_list)} candidates remain.")
|
| 201 |
-
|
| 202 |
-
query_location = query_item.get('locationLost') or query_item.get('locationFound')
|
| 203 |
-
if query_location and query_location != "Campus":
|
| 204 |
-
search_list = [item for item in search_list if (item.get('locationFound') or item.get('locationLost')) in [query_location, "Campus"]]
|
| 205 |
-
print(f" [FILTER] After location: {len(search_list)} candidates for scoring.")
|
| 206 |
|
| 207 |
# --- SCORING ---
|
| 208 |
results = []
|
|
@@ -257,4 +241,4 @@ def compare_items():
|
|
| 257 |
return jsonify({"error": str(e)}), 500
|
| 258 |
|
| 259 |
if __name__ == '__main__':
|
| 260 |
-
app.run(host='0.0.0.0', port=7860)
|
|
|
|
| 98 |
return float(np.dot(vec1, vec2) / (np.linalg.norm(vec1) * np.linalg.norm(vec2)))
|
| 99 |
|
| 100 |
def segment_guided_object(image: Image.Image, object_label: str) -> Image.Image:
|
|
|
|
|
|
|
| 101 |
prompt = f"a {object_label}."
|
| 102 |
|
| 103 |
print(f" [Segment] Using simple prompt: '{prompt}'")
|
|
|
|
| 183 |
payload = request.json
|
| 184 |
query_item = payload['queryItem']
|
| 185 |
search_list = payload['searchList']
|
| 186 |
+
print(f"\n[COMPARE] Received {len(search_list)} pre-filtered candidates for '{query_item.get('objectName')}'.")
|
| 187 |
|
| 188 |
+
# --- HIERARCHICAL FILTERING BLOCK HAS BEEN REMOVED ---
|
| 189 |
+
# The service now proceeds directly to scoring.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
|
| 191 |
# --- SCORING ---
|
| 192 |
results = []
|
|
|
|
| 241 |
return jsonify({"error": str(e)}), 500
|
| 242 |
|
| 243 |
if __name__ == '__main__':
|
| 244 |
+
app.run(host='0.0.0.0', port=7860)
|