nomadeats / utils /markdown_output.py
carreroguille's picture
Upload 15 files
00fddaf verified
Raw
History Blame Contribute Delete
2.63 kB
"""
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