Download cotizar_cli.py from andervier/agosto: direct link, hf CLI and curl.
- Browser
- Download file 1.78 kB
-
https://huggingface.co/spaces/andervier/agosto/resolve/main/cotizar_cli.py
- Command line
-
hf download hf://spaces/andervier/agosto/cotizar_cli.py
-
curl -L -o cotizar_cli.py https://huggingface.co/spaces/andervier/agosto/resolve/main/cotizar_cli.py
1.78 kB
| """Cotizar desde la terminal, sin interfaz (útil para probar prompts): | |
| python cotizar_cli.py solicitud.jpg [--instrucciones "10% de descuento"] | |
| Usa data/existencias.xlsx y data/precios.xlsx. | |
| """ | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| import config | |
| from catalogo import construir_catalogo | |
| from cotizacion import cotizar | |
| from excel_salida import generar_excel | |
| from ia import extraer_solicitud, emparejar, interpretar_instrucciones | |
| from llm import LLM | |
| from memoria import Memoria | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("solicitud") | |
| ap.add_argument("--instrucciones", default="") | |
| ap.add_argument("--salida", default=None) | |
| args = ap.parse_args() | |
| memoria = Memoria() # decisiones guardadas por el departamento (data/memoria.json) | |
| cat = construir_catalogo(config.DATA_DIR / "existencias.xlsx", config.DATA_DIR / "precios.xlsx", memoria=memoria) | |
| llm = LLM() | |
| ruta = Path(args.solicitud) | |
| sol = extraer_solicitud(llm, ruta.name, ruta.read_bytes()) | |
| print(f"Extraídos {len(sol.items)} renglones") | |
| emp = emparejar(llm, sol, cat, memoria) | |
| for it, e in zip(sol.items, emp.items): | |
| prod = cat.productos[e.producto_id].descripcion if e.producto_id else "-" | |
| print(f"{it.n:>3}. {it.principio_activo} {it.concentracion} x{it.cantidad} -> [{e.tipo}] {prod} {e.nota}") | |
| reglas = interpretar_instrucciones(llm, args.instrucciones, sol) | |
| cot = cotizar(sol, emp, cat, reglas) | |
| salida = Path(args.salida or f"RESPUESTA_{ruta.stem}.xlsx") | |
| salida.write_bytes(generar_excel(cot)) | |
| Path(salida.with_suffix(".json")).write_text(json.dumps( | |
| {"solicitud": sol.model_dump(), "emparejamiento": emp.model_dump()}, ensure_ascii=False, indent=1), encoding="utf-8") | |
| print(cot.resumen(), f"| Total USD {cot.total:,.2f} | llamadas al modelo: {llm.llamadas}") | |
| print(f"Excel: {salida}") | |