"""Aplicativo de Gerenciamento de Checklists""" import streamlit as st import traceback import sys try: from utils.database import get_all_checklists, test_connection except Exception as e: st.error(f"❌ Erro ao importar módulos: {str(e)}") st.code(traceback.format_exc()) st.stop() st.set_page_config( page_title="Gerenciador de Checklists", page_icon="✅", layout="centered", initial_sidebar_state="collapsed" ) def init_session_state(): if 'current_checklist_id' not in st.session_state: st.session_state.current_checklist_id = None def main(): try: init_session_state() st.title("🗂️ Gerenciador de Checklists") st.markdown("---") # Testar conexão com banco try: if not test_connection(): st.error("❌ Não foi possível conectar ao banco de dados PostgreSQL!") st.warning("⚠️ **Problema identificado**: O servidor PostgreSQL não está acessível do Hugging Face Space") st.info("🔧 **Possíveis soluções:**") st.markdown(""" - Verificar se o servidor PostgreSQL está rodando - Configurar firewall para permitir conexões do Hugging Face (IPs externos) - Usar um banco PostgreSQL na nuvem (Railway, Supabase, ElephantSQL) - Configurar pg_hba.conf para aceitar conexões remotas """) st.stop() except Exception as e: st.error(f"❌ Erro na conexão: {str(e)}") st.info("💡 O Hugging Face Space pode estar bloqueado para acessar servidores externos") st.code(traceback.format_exc()) st.stop() col1, col2, col3 = st.columns([1, 2, 1]) with col2: st.markdown("### Bem-vindo!") st.markdown("Crie e gerencie seus checklists personalizados de forma simples e eficiente.") st.markdown("") col1, col2, col3 = st.columns(3) with col1: if st.button("➕ Novo Checklist", type="primary", use_container_width=True): st.switch_page("pages/criar_checklist.py") with col2: if st.button("📊 Dashboard Geral", use_container_width=True): st.switch_page("pages/dashboard_geral.py") with col3: if st.button("🤖 Relatórios IA", use_container_width=True): st.switch_page("pages/relatorio_ia.py") # Buscar checklists do banco try: checklists = get_all_checklists() if checklists: st.markdown("### Seus Checklists") for checklist in checklists: col_name, col_process, col_date, col_btn = st.columns([3, 2, 1.5, 1]) with col_name: st.write(f"📋 {checklist['name']}") with col_process: if checklist['numero_processo']: st.caption(f"🔢 {checklist['numero_processo']}") else: st.caption("🔢 Sem processo") with col_date: st.caption(checklist['created_at'].strftime("%d/%m/%Y")) with col_btn: if st.button("Ver", key=f"view_{checklist['id']}"): st.session_state.current_checklist_id = checklist['id'] st.switch_page("pages/dashboard.py") else: st.info("Você ainda não tem checklists. Clique em 'Novo Checklist' para criar o primeiro!") except Exception as e: st.error(f"Erro ao buscar checklists: {str(e)}") st.code(traceback.format_exc()) except Exception as e: st.error(f"❌ Erro crítico na aplicação: {str(e)}") st.code(traceback.format_exc()) if __name__ == "__main__": main()