File size: 4,230 Bytes
d54ba19
 
 
71cc936
 
 
 
 
 
 
 
 
d54ba19
 
 
 
 
 
 
 
 
 
 
 
 
71cc936
 
 
 
 
 
 
 
 
fe4466c
 
 
 
 
 
 
 
 
71cc936
 
 
fe4466c
71cc936
 
d54ba19
9c864b0
d54ba19
 
9c864b0
 
d54ba19
9c864b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d54ba19
9c864b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71cc936
 
 
 
d54ba19
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
"""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()