Update frontend/input_handlers.py
Browse files- frontend/input_handlers.py +19 -6
frontend/input_handlers.py
CHANGED
@@ -19,13 +19,26 @@ class InputHandlers:
|
|
19 |
skip_exact_match (bool): Whether to skip the first/exact match
|
20 |
|
21 |
Returns:
|
22 |
-
str: HTML formatted results
|
23 |
"""
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
@staticmethod
|
31 |
def process_url(url, num_recommendations=5, skip_exact_match=True):
|
|
|
19 |
skip_exact_match (bool): Whether to skip the first/exact match
|
20 |
|
21 |
Returns:
|
22 |
+
str: HTML formatted results or error message
|
23 |
"""
|
24 |
+
try:
|
25 |
+
# Initialize the recommender service
|
26 |
+
recommender = JewelryRecommenderService()
|
27 |
+
|
28 |
+
# Get recommendations
|
29 |
+
recommendations = recommender.get_recommendations(
|
30 |
+
image, num_recommendations, skip_exact_match
|
31 |
+
)
|
32 |
+
|
33 |
+
# Format and return the results as HTML
|
34 |
+
return ResultFormatter.format_html(recommendations)
|
35 |
+
|
36 |
+
except Exception as e:
|
37 |
+
# Log the error for debugging
|
38 |
+
print(f"Error processing image: {str(e)}")
|
39 |
+
|
40 |
+
# Return a user-friendly error message
|
41 |
+
return "<p style='color: red;'>Error: Unable to process the image. Please try again.</p>"
|
42 |
|
43 |
@staticmethod
|
44 |
def process_url(url, num_recommendations=5, skip_exact_match=True):
|