Spaces:
Sleeping
Sleeping
Download app/report_generator.py from DarkLofi/construtech-api: direct link, hf CLI and curl.
- Browser
- Download file 2.27 kB
-
https://huggingface.co/spaces/DarkLofi/construtech-api/resolve/main/app/report_generator.py
- Command line
-
hf download hf://spaces/DarkLofi/construtech-api/app/report_generator.py
-
curl -L -o report_generator.py https://huggingface.co/spaces/DarkLofi/construtech-api/resolve/main/app/report_generator.py
2.27 kB
| from reportlab.lib.pagesizes import letter | |
| from reportlab.pdfgen import canvas | |
| import json | |
| import os | |
| import datetime | |
| def gerar_relatorio_pdf(obra_nome: str, analise_json: str, output_path: str = "relatorio_obra.pdf"): | |
| """UI-01: Script ReportLab para PDF compilando dados, IA e preços.""" | |
| # Prepara os dados da IA | |
| try: | |
| dados_ia = json.loads(analise_json) | |
| except Exception: | |
| dados_ia = {"error": "Dados da IA inválidos."} | |
| c = canvas.Canvas(output_path, pagesize=letter) | |
| width, height = letter | |
| # Cabeçalho | |
| c.setFont("Helvetica-Bold", 16) | |
| c.drawString(50, height - 50, f"Barueltech ConstruTech - Relatório de Obra") | |
| c.setFont("Helvetica", 12) | |
| c.drawString(50, height - 70, f"Obra: {obra_nome}") | |
| c.drawString(50, height - 90, f"Data: {datetime.datetime.now().strftime('%d/%m/%Y %H:%M')}") | |
| # Seção de IA | |
| c.setFont("Helvetica-Bold", 14) | |
| c.drawString(50, height - 130, "Análise da IA Engenheira:") | |
| y = height - 150 | |
| c.setFont("Helvetica", 11) | |
| if "error" in dados_ia: | |
| c.drawString(50, y, f"Erro: {dados_ia['error']}") | |
| else: | |
| c.drawString(50, y, f"Etapa Identificada: {dados_ia.get('etapa_obra', 'N/A')}") | |
| y -= 20 | |
| c.drawString(50, y, "Materiais Visíveis:") | |
| y -= 15 | |
| for mat in dados_ia.get("materiais_visiveis", []): | |
| c.drawString(70, y, f"- {mat}") | |
| y -= 15 | |
| y -= 10 | |
| c.drawString(50, y, "Gargalos e Riscos:") | |
| y -= 15 | |
| for gargalo in dados_ia.get("gargalos_potenciais", []): | |
| # Quebra linha básica se o texto for muito longo (simplificado para o MVP) | |
| linha = f"- {gargalo}" | |
| if len(linha) > 80: | |
| c.drawString(70, y, linha[:80] + "...") | |
| else: | |
| c.drawString(70, y, linha) | |
| y -= 15 | |
| c.save() | |
| return output_path | |
| if __name__ == "__main__": | |
| # Teste isolado do gerador | |
| json_teste = '{"etapa_obra": "Alvenaria", "materiais_visiveis": ["Cimento", "Tijolo"], "gargalos_potenciais": ["Risco de queda"]}' | |
| gerar_relatorio_pdf("Edifício Teste", json_teste) | |
| print("Relatório PDF de teste gerado com sucesso.") | |