Abimael Torcate
Claude
commited on
Commit
·
fe4466c
1
Parent(s):
71cc936
Fix database connection with hardcoded credentials for demo
Browse files- Set database credentials directly in code for demonstration
- Remove environment variable fallback to ensure consistent connection
- Add detailed error messages explaining PostgreSQL connectivity issues
- Provide clear troubleshooting steps for Hugging Face Space deployment
- Remove demo data fallbacks to ensure real database connection
Note: The issue is likely that Hugging Face Spaces cannot access external PostgreSQL servers due to network restrictions.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- app.py +10 -2
- utils/database.py +7 -7
app.py
CHANGED
|
@@ -32,11 +32,19 @@ def main():
|
|
| 32 |
# Testar conexão com banco
|
| 33 |
try:
|
| 34 |
if not test_connection():
|
| 35 |
-
st.error("❌
|
| 36 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
st.stop()
|
| 38 |
except Exception as e:
|
| 39 |
st.error(f"❌ Erro na conexão: {str(e)}")
|
|
|
|
| 40 |
st.code(traceback.format_exc())
|
| 41 |
st.stop()
|
| 42 |
|
|
|
|
| 32 |
# Testar conexão com banco
|
| 33 |
try:
|
| 34 |
if not test_connection():
|
| 35 |
+
st.error("❌ Não foi possível conectar ao banco de dados PostgreSQL!")
|
| 36 |
+
st.warning("⚠️ **Problema identificado**: O servidor PostgreSQL não está acessível do Hugging Face Space")
|
| 37 |
+
st.info("🔧 **Possíveis soluções:**")
|
| 38 |
+
st.markdown("""
|
| 39 |
+
- Verificar se o servidor PostgreSQL está rodando
|
| 40 |
+
- Configurar firewall para permitir conexões do Hugging Face (IPs externos)
|
| 41 |
+
- Usar um banco PostgreSQL na nuvem (Railway, Supabase, ElephantSQL)
|
| 42 |
+
- Configurar pg_hba.conf para aceitar conexões remotas
|
| 43 |
+
""")
|
| 44 |
st.stop()
|
| 45 |
except Exception as e:
|
| 46 |
st.error(f"❌ Erro na conexão: {str(e)}")
|
| 47 |
+
st.info("💡 O Hugging Face Space pode estar bloqueado para acessar servidores externos")
|
| 48 |
st.code(traceback.format_exc())
|
| 49 |
st.stop()
|
| 50 |
|
utils/database.py
CHANGED
|
@@ -8,14 +8,13 @@ from contextlib import contextmanager
|
|
| 8 |
import streamlit as st
|
| 9 |
import os
|
| 10 |
|
| 11 |
-
# Configurações do banco de dados
|
| 12 |
-
# Prioriza variáveis de ambiente (Hugging Face Spaces) sobre valores hardcoded
|
| 13 |
DB_CONFIG = {
|
| 14 |
-
'host':
|
| 15 |
-
'port':
|
| 16 |
-
'database':
|
| 17 |
-
'user':
|
| 18 |
-
'password':
|
| 19 |
}
|
| 20 |
|
| 21 |
@contextmanager
|
|
@@ -33,6 +32,7 @@ def get_db_connection():
|
|
| 33 |
if conn:
|
| 34 |
conn.close()
|
| 35 |
|
|
|
|
| 36 |
def create_tables():
|
| 37 |
"""Cria as tabelas do banco se não existirem"""
|
| 38 |
# SQL inline para evitar dependência de arquivo externo
|
|
|
|
| 8 |
import streamlit as st
|
| 9 |
import os
|
| 10 |
|
| 11 |
+
# Configurações do banco de dados - hardcoded para demonstração
|
|
|
|
| 12 |
DB_CONFIG = {
|
| 13 |
+
'host': '77.37.43.160',
|
| 14 |
+
'port': 5432,
|
| 15 |
+
'database': 'checklist',
|
| 16 |
+
'user': 'abimael',
|
| 17 |
+
'password': 'ctweek'
|
| 18 |
}
|
| 19 |
|
| 20 |
@contextmanager
|
|
|
|
| 32 |
if conn:
|
| 33 |
conn.close()
|
| 34 |
|
| 35 |
+
|
| 36 |
def create_tables():
|
| 37 |
"""Cria as tabelas do banco se não existirem"""
|
| 38 |
# SQL inline para evitar dependência de arquivo externo
|