Spaces:
Runtime error
Runtime error
| """ | |
| GeneraciΓ³n del output en formato Markdown. | |
| """ | |
| import time | |
| from typing import Dict, List | |
| from config import DEVICE, OCR_MODEL_ID, TRANSLATION_MODEL_ID, DESCRIPTION_MODEL_ID | |
| SECTION_EMOJIS = { | |
| "entrantes": "π₯", | |
| "starters": "π₯", | |
| "principales": "π", | |
| "main": "π", | |
| "postres": "π°", | |
| "desserts": "π°", | |
| "bebidas": "π·", | |
| "drinks": "π·", | |
| } | |
| CULTURAL_NOTES = """## βΉοΈ CULTURAL NOTES | |
| **About Spanish Dining:** | |
| Spanish meals are social events meant to be enjoyed slowly. Lunch (comida) is typically served 2-4 PM, dinner (cena) after 9 PM. Sharing dishes (tapas style) is common and encouraged. | |
| **Regional Diversity:** | |
| Spain's cuisine varies dramatically by region - from seafood in Galicia to paella in Valencia, each area has unique specialties reflecting local ingredients and traditions. | |
| """ | |
| def _get_section_emoji(section_name: str) -> str: | |
| for key, emoji in SECTION_EMOJIS.items(): | |
| if key in section_name.lower(): | |
| return emoji | |
| return "π½οΈ" | |
| def generate_markdown( | |
| dishes: List[Dict], | |
| target_lang: str, | |
| include_cultural_notes: bool, | |
| ) -> str: | |
| """Genera output en formato Markdown estructurado.""" | |
| # Agrupar por secciΓ³n | |
| sections: Dict[str, List[Dict]] = {} | |
| for dish in dishes: | |
| sections.setdefault(dish["section"], []).append(dish) | |
| # Header | |
| md = f"""# πͺπΈ Spanish Menu β Cultural Guide | |
| **Generated:** {time.strftime('%Y-%m-%d %H:%M:%S')} | |
| **Target Language:** {target_lang} | |
| **Total Items:** {len(dishes)} dishes | |
| --- | |
| ## π MENU SUMMARY | |
| - **Sections:** {len(sections)} | |
| - **Dishes Processed:** {len(dishes)} | |
| """ | |
| prices = [d["price"] for d in dishes if d.get("price")] | |
| if prices: | |
| md += f"- **Price Range:** {min(prices)} - {max(prices)}\n" | |
| md += "\n---\n\n" | |
| # Secciones de platos | |
| for section_name, section_dishes in sections.items(): | |
| emoji = _get_section_emoji(section_name) | |
| md += f"## {emoji} {section_name.upper()}\n\n" | |
| for dish in section_dishes: | |
| md += f"### {dish['name']}\n\n" | |
| md += f"**π° Price:** {dish['price']}\n\n" | |
| md += f"**π Description:** \n{dish['description']}\n\n" | |
| md += "---\n\n" | |
| # Notas culturales | |
| if include_cultural_notes: | |
| md += CULTURAL_NOTES | |
| # Footer | |
| md += f"""--- | |
| ## π PROCESSING DETAILS | |
| - **OCR Model:** {OCR_MODEL_ID} | |
| - **Translation Model:** {TRANSLATION_MODEL_ID} | |
| - **Description Model:** {DESCRIPTION_MODEL_ID} | |
| - **Device:** {DEVICE.upper()} | |
| *Generated with β€οΈ by Spanish Menu Translator* | |
| """ | |
| return md | |