Spaces:
Sleeping
Sleeping
File size: 5,527 Bytes
4d14f77 1c76985 4d14f77 1c76985 4d14f77 1c76985 4d14f77 1c76985 4d14f77 1c76985 4d14f77 1c76985 4d14f77 1c76985 4d14f77 1c76985 4d14f77 1c76985 4d14f77 1c76985 4d14f77 1c76985 4d14f77 | 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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | import gradio as gr
import requests
from datetime import datetime
import csv
import io
def limpiar_cedula(cedula):
"""Limpia la cédula: quita comas, puntos, espacios"""
if not cedula:
return ""
cedula_limpia = ''.join(filter(str.isdigit, str(cedula)))
return cedula_limpia
def buscar_cliente(cedula):
if not cedula or not cedula.strip():
return "**💫 Vas a llegar a la comisión de tus sueños. Piensa en tus metas.**"
try:
sheets_url = "https://docs.google.com/spreadsheets/d/1Blec5K6L6ks1Xl14iqIhcB955Fafbv3EUcXysrDGjcE/export?format=csv"
response = requests.get(sheets_url, timeout=10)
content = response.content.decode('utf-8')
csv_reader = csv.DictReader(io.StringIO(content))
cedula_limpia = limpiar_cedula(cedula)
for fila in csv_reader:
# Buscar en todas las columnas que puedan contener cédulas
for columna, valor in fila.items():
if valor and cedula_limpia == limpiar_cedula(valor):
# Formato de tablita vertical bonita
return f"""
<div style='
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 15px;
border-radius: 10px;
margin-bottom: 15px;
'>
<h3>✅ CLIENTE ENCONTRADO</h3>
</div>
<div style='
background: #f8f9fa;
border-left: 4px solid #667eea;
padding: 15px;
border-radius: 5px;
font-family: Arial, sans-serif;
'>
<table style="width: 100%; border-collapse: collapse;">
<tr><td style="padding: 8px; border-bottom: 1px solid #eee; width: 30%;"><strong>👤 Nombre:</strong></td><td style="padding: 8px; border-bottom: 1px solid #eee;">{fila.get('NOMBRE', 'N/A')}</td></tr>
<tr><td style="padding: 8px; border-bottom: 1px solid #eee;"><strong>📋 Cédula:</strong></td><td style="padding: 8px; border-bottom: 1px solid #eee;">{valor}</td></tr>
<tr><td style="padding: 8px; border-bottom: 1px solid #eee;"><strong>🏦 Pagaduría:</strong></td><td style="padding: 8px; border-bottom: 1px solid #eee;">{fila.get('Pagaduría', 'N/A')}</td></tr>
<tr><td style="padding: 8px; border-bottom: 1px solid #eee;"><strong>💰 Financiera:</strong></td><td style="padding: 8px; border-bottom: 1px solid #eee;">{fila.get('Financiera', 'N/A')}</td></tr>
<tr><td style="padding: 8px; border-bottom: 1px solid #eee;"><strong>💵 Valor:</strong></td><td style="padding: 8px; border-bottom: 1px solid #eee;">{fila.get('Valor', 'N/A')}</td></tr>
<tr><td style="padding: 8px; border-bottom: 1px solid #eee;"><strong>👨💼 Analista:</strong></td><td style="padding: 8px; border-bottom: 1px solid #eee;">{fila.get('Analista', 'N/A')}</td></tr>
<tr><td style="padding: 8px; border-bottom: 1px solid #eee;"><strong>💬 Observaciones:</strong></td><td style="padding: 8px; border-bottom: 1px solid #eee;">{fila.get('Observaciones', 'N/A')}</td></tr>
<tr><td style="padding: 8px;"><strong>🕐 Actualizado:</strong></td><td style="padding: 8px;">{fila.get('FechaActualización', 'N/A')}</td></tr>
</table>
</div>
<div style='
background: #e8f5e8;
padding: 10px;
border-radius: 5px;
margin-top: 10px;
font-size: 12px;
color: #2d5016;
'>
🕐 Consulta: {datetime.now().strftime("%Y-%m-%d %H:%M")}
</div>
"""
# Mensaje cuando NO encuentra
return f"""
<div style='
background: #fff3cd;
border-left: 4px solid #ffc107;
padding: 20px;
border-radius: 5px;
text-align: center;
'>
<h3>❌ CLIENTE NO ENCONTRADO</h3>
<p><strong>Cédula buscada:</strong> {cedula}</p>
<p>Verifique el número o contacte al administrador.</p>
</div>
"""
except Exception as e:
return f"""
<div style='
background: #f8d7da;
border-left: 4px solid #dc3545;
padding: 20px;
border-radius: 5px;
text-align: center;
'>
<h3>⚠️ ERROR TEMPORAL</h3>
<p>Error: {str(e)}</p>
<p>Estamos solucionando el problema técnico.</p>
</div>
"""
# Interfaz más elegante
with gr.Blocks(
theme="soft",
css="""
.gradio-container { max-width: 800px; margin: 0 auto; }
.header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 25px;
border-radius: 10px;
text-align: center;
margin-bottom: 20px;
}
"""
) as demo:
gr.Markdown("""
<div class="header">
<h1>🔍 CONSULTA DE ESTADO</h1>
<p><strong>Vas a llegar a la comisión de tus sueños. Piensa en tus metas. 💫</strong></p>
</div>
""")
with gr.Row():
cedula_input = gr.Textbox(
label="**INGRESE LA CÉDULA DEL CLIENTE**",
placeholder="Ej: 1000000001, 444343, 8568...",
max_lines=1,
elem_id="cedula_input"
)
buscar_btn = gr.Button("🔍 CONSULTAR ESTADO", variant="primary", size="lg")
gr.Markdown("---")
resultado = gr.HTML(
value="""
<div style='
background: #f8f9fa;
padding: 20px;
border-radius: 5px;
text-align: center;
border: 2px dashed #ddd;
'>
<h3>👋 BIENVENIDO/A</h3>
<p>Ingrese una cédula para consultar el estado del crédito.</p>
</div>
"""
)
buscar_btn.click(buscar_cliente, inputs=cedula_input, outputs=resultado)
cedula_input.submit(buscar_cliente, inputs=cedula_input, outputs=resultado)
if __name__ == "__main__":
demo.launch() |