# formatter.py class ResultFormatter: """Formats recommendation results for display.""" @staticmethod def format_html(recommendations): if not recommendations: print("No recommendations found.") # Debug log return "No recommendations found." result_html = "

Recommended Jewelry Items💍💎:

" for i, rec in enumerate(recommendations, 1): metadata = rec["metadata"] # Start the recommendation tile result_html += f"
" # Add the title result_html += f"

#{i}: {metadata.get('TITLE', 'unavailabe😔☹')}

" # Add images side by side using Flexbox if metadata.get('LINK1') or metadata.get('LINK2'): result_html += "
" if metadata.get('LINK1'): result_html += f"" if metadata.get('LINK2'): result_html += f"" result_html += "
" else: result_html += "

No image available

" # Add metadata details result_html += f"

Tanishq design id: {metadata.get('Design_ID', 'fetching...')}

" result_html += f"

Category: {metadata.get('CATEGORY_TYPE', 'fetching...')}

" result_html += f"

Carets: {metadata.get('GOLD_KARATAGE', 'fetching...')}

" result_html += f"

Description: {metadata.get('SHORT_DESCRIPTION', 'No description available')}

" result_html += f"

Price in 💲(approx): $ {metadata.get('PRICE', 'N/A')}

" result_html += f"

Metal type: {metadata.get('METAL', 'fetching')}

" result_html += f"

Jewellery type: {metadata.get('JEWELLERY_TYPE', 'fetching...')}

" result_html += f"

Similarity👉👈Score: {rec['similarity_score']:.4f}

" # Close the recommendation tile result_html += "
" print("HTML output generated:", result_html) # Debug log return result_html @staticmethod def format_json(recommendations): """Format recommendations as JSON. Args: recommendations (list): List of recommendation dictionaries Returns: list: Clean JSON-serializable results """ if not recommendations: return [] results = [] for rec in recommendations: results.append({ "TITLE": rec["metadata"].get("TITLE", "Unknown"), "CATEGORY_TYPE": rec["metadata"].get("CATEGORY_TYPE", "Unknown"), "SHORT_DESCRIPTION": rec["metadata"].get("SHORT_DESCRIPTION", "No description"), "PRICE": rec["metadata"].get("PRICE", "N/A"), "similarity_score": round(rec["similarity_score"], 4), "image_link🔗": rec["metadata"].get("LINK1", None) }) return results # # formatter.py # class ResultFormatter: # """Formats recommendation results for display.""" # @staticmethod # def format_html(recommendations): # if not recommendations: # print("No recommendations found.") # Debug log # return "No recommendations found." # result_html = "

Recommended Jewelry Items💍💎:

" # for i, rec in enumerate(recommendations, 1): # metadata = rec["metadata"] # # Key: 1, Value: {'filename': '36167805.jpg', 'Design_ID': '51O5PT2QN1BAP1_P', 'TITLE': nan, 'CATEGORY_TYPE': 'SET2', # # 'PRICE': 406384.0, 'SHORT_DESCRIPTION': nan, 'METAL': 'Gold', 'JEWELLERY_TYPE': 'PLAIN', 'GOLD_KARATAGE': 18, # # 'METAL_COLOR': 'Yellow', 'LINK1': 'https://objectstorage.ap-hyderabad-1.oraclecloud.com/n/axpfa55nllwe/b/app-ea/o/ECOM_Manual_Enrichment/51O5PT2QN1BAP1.jpg', # # 'LINK2': nan, 'ID': '36167805'} # result_html += f"
" # result_html += f"

#{i}: {metadata.get('TITLE', 'unavailabe😔☹')}

" # if metadata.get('LINK1'): # result_html += f"

" # result_html += f"

" # else: # result_html += "

No image available

" # result_html += f"

Tanishq design id: {metadata.get('Design_ID', 'fetching...')}

" # result_html += f"

Category: {metadata.get('CATEGORY_TYPE', 'fetching...')}

" # result_html += f"

Carets: {metadata.get('GOLD_KARATAGE', 'fetching...')}

" # result_html += f"

Description: {metadata.get('SHORT_DESCRIPTION', 'No description available')}

" # result_html += f"

Price in 💲(approx): $ {metadata.get('PRICE', 'N/A')}

" # result_html += f"

Metal type: {metadata.get('METAL', 'fetching')}

" # result_html += f"

Jewellery type: {metadata.get('JEWELLERY_TYPE', 'fetching...')}

" # # result_html += f"

Ornament color: {metadata.get('METAL_COLOR', 'fetching...')}

" # result_html += f"

Similarity👉👈Score: {rec['similarity_score']:.4f}

" # # result_html += f"

img link🔗: {metadata.get('LINK1','No link found')}

" # result_html += "
" # print("HTML output generated:", result_html) # Debug log # return result_html # @staticmethod # def format_json(recommendations): # """Format recommendations as JSON. # Args: # recommendations (list): List of recommendation dictionaries # Returns: # list: Clean JSON-serializable results # """ # if not recommendations: # return [] # results = [] # for rec in recommendations: # results.append({ # "TITLE": rec["metadata"].get("TITLE", "Unknown"), # "CATEGORY_TYPE": rec["metadata"].get("CATEGORY_TYPE", "Unknown"), # "SHORT_DESCRIPTION": rec["metadata"].get("SHORT_DESCRIPTION", "No description"), # "PRICE": rec["metadata"].get("PRICE", "N/A"), # "similarity_score": round(rec["similarity_score"], 4), # "image_link🔗": rec["metadata"].get("LINK1", None) # }) # return results