Delete app.py
Browse files
app.py
DELETED
@@ -1,152 +0,0 @@
|
|
1 |
-
# -*- coding: utf-8 -*-
|
2 |
-
"""Untitled19.ipynb
|
3 |
-
|
4 |
-
Automatically generated by Colab.
|
5 |
-
|
6 |
-
Original file is located at
|
7 |
-
https://colab.research.google.com/drive/12FC8IfauEBNv8yXDkOWez5aZ0F6sD5q1
|
8 |
-
"""
|
9 |
-
|
10 |
-
import gradio as gr
|
11 |
-
import csv
|
12 |
-
import re
|
13 |
-
from datetime import datetime
|
14 |
-
from hashlib import sha256
|
15 |
-
import os
|
16 |
-
from PIL import Image
|
17 |
-
import requests
|
18 |
-
from io import BytesIO
|
19 |
-
|
20 |
-
# Configuración
|
21 |
-
CSV_FILE = "registros_incidencias.csv"
|
22 |
-
PASSWORD_HASH = "8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918" # Hash de "admin"
|
23 |
-
|
24 |
-
PRESTACIONES = [
|
25 |
-
"1. PROFESIONALIZACIÓN",
|
26 |
-
"2. ESTIMULOS DE PRODUCTIVIDAD",
|
27 |
-
"3. UNIFORMES",
|
28 |
-
"4. DESCUENTOS INJUSTIFICADOS",
|
29 |
-
"5. SEGURO DE VIDA",
|
30 |
-
"6. AHORRO SOLIDARIO",
|
31 |
-
"7. OTROS"
|
32 |
-
]
|
33 |
-
|
34 |
-
REGEX_CURP = re.compile(r'^[A-Z]{4}[0-9]{6}[HM][A-Z]{5}[A-Z0-9]{2}$')
|
35 |
-
def validar_curp(curp):
|
36 |
-
return bool(REGEX_CURP.match(curp.upper()))
|
37 |
-
|
38 |
-
def inicializar_csv():
|
39 |
-
if not os.path.exists(CSV_FILE):
|
40 |
-
with open(CSV_FILE, 'w', newline='', encoding='utf-8') as f:
|
41 |
-
writer = csv.writer(f)
|
42 |
-
writer.writerow([
|
43 |
-
"Fecha_Registro", "Entidad", "Nombre",
|
44 |
-
"CURP", "Prestacion", "Quincena"
|
45 |
-
])
|
46 |
-
|
47 |
-
def guardar_registro(entidad, nombre, curp, prestacion, quincena):
|
48 |
-
if not all([entidad, nombre, curp, prestacion, quincena]):
|
49 |
-
return "⚠️ Todos los campos son obligatorios"
|
50 |
-
|
51 |
-
if not validar_curp(curp):
|
52 |
-
return "⚠️ CURP inválido"
|
53 |
-
|
54 |
-
try:
|
55 |
-
with open(CSV_FILE, 'a', newline='', encoding='utf-8') as f:
|
56 |
-
writer = csv.writer(f)
|
57 |
-
writer.writerow([
|
58 |
-
datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
59 |
-
entidad.strip().upper(),
|
60 |
-
nombre.strip().title(),
|
61 |
-
curp.upper(),
|
62 |
-
prestacion,
|
63 |
-
quincena
|
64 |
-
])
|
65 |
-
return "✅ Registro exitoso"
|
66 |
-
except Exception as e:
|
67 |
-
return f"❌ Error: {str(e)}"
|
68 |
-
|
69 |
-
def verificar_credenciales(username, password):
|
70 |
-
return username == "admin" and sha256(password.encode()).hexdigest() == PASSWORD_HASH
|
71 |
-
|
72 |
-
# Interfaz principal
|
73 |
-
with gr.Blocks(title="Sistema de Captura") as app:
|
74 |
-
# Estado de la aplicación
|
75 |
-
logged_in = gr.State(False)
|
76 |
-
|
77 |
-
# Interfaz de login
|
78 |
-
with gr.Column(visible=True) as login_col:
|
79 |
-
# Agrega la imagen aquí (puede ser desde URL o archivo local)
|
80 |
-
try:
|
81 |
-
# Ejemplo con imagen desde URL
|
82 |
-
response = requests.open("d5bb4c4a-f9e5-4c70-a53c-23b7dc3872a1.jpg")
|
83 |
-
img = Image.open(BytesIO(response.content))
|
84 |
-
login_img = gr.Image(img, label="", interactive=False, show_label=False)
|
85 |
-
except:
|
86 |
-
# Si falla la carga, puedes usar una imagen local
|
87 |
-
# Coloca tu imagen en el mismo directorio que el script
|
88 |
-
login_img = gr.Image("d5bb4c4a-f9e5-4c70-a53c-23b7dc3872a1.jpg", label="", interactive=False, show_label=False)
|
89 |
-
|
90 |
-
gr.Markdown("# Sistema de Captura de Incidencias")
|
91 |
-
username = gr.Textbox(label="Usuario")
|
92 |
-
password = gr.Textbox(label="Contraseña", type="password")
|
93 |
-
login_btn = gr.Button("Ingresar")
|
94 |
-
login_msg = gr.Textbox(label="Mensaje", interactive=False)
|
95 |
-
|
96 |
-
# Interfaz de captura
|
97 |
-
with gr.Column(visible=False) as captura_col:
|
98 |
-
gr.Markdown("## Captura de Datos")
|
99 |
-
|
100 |
-
with gr.Row():
|
101 |
-
with gr.Column():
|
102 |
-
entidad = gr.Textbox(label="Entidad Federativa")
|
103 |
-
nombre = gr.Textbox(label="Nombre completo")
|
104 |
-
curp = gr.Textbox(label="CURP")
|
105 |
-
prestacion = gr.Dropdown(PRESTACIONES, label="Prestación afectada")
|
106 |
-
quincena = gr.Textbox(label="Quincena (AAAA-MM-DD)")
|
107 |
-
submit_btn = gr.Button("Guardar")
|
108 |
-
|
109 |
-
resultado = gr.Textbox(label="Resultado")
|
110 |
-
|
111 |
-
logout_btn = gr.Button("Cerrar sesión")
|
112 |
-
|
113 |
-
# Funciones de control
|
114 |
-
def autenticar(user, pwd):
|
115 |
-
if verificar_credenciales(user, pwd):
|
116 |
-
return {
|
117 |
-
login_col: gr.update(visible=False),
|
118 |
-
captura_col: gr.update(visible=True),
|
119 |
-
login_msg: ""
|
120 |
-
}
|
121 |
-
return {
|
122 |
-
login_msg: "⚠️ Credenciales incorrectas"
|
123 |
-
}
|
124 |
-
|
125 |
-
def cerrar_sesion():
|
126 |
-
return {
|
127 |
-
login_col: gr.update(visible=True),
|
128 |
-
captura_col: gr.update(visible=False),
|
129 |
-
login_msg: ""
|
130 |
-
}
|
131 |
-
|
132 |
-
# Eventos
|
133 |
-
login_btn.click(
|
134 |
-
autenticar,
|
135 |
-
inputs=[username, password],
|
136 |
-
outputs=[login_col, captura_col, login_msg]
|
137 |
-
)
|
138 |
-
|
139 |
-
logout_btn.click(
|
140 |
-
cerrar_sesion,
|
141 |
-
outputs=[login_col, captura_col, login_msg]
|
142 |
-
)
|
143 |
-
|
144 |
-
submit_btn.click(
|
145 |
-
guardar_registro,
|
146 |
-
inputs=[entidad, nombre, curp, prestacion, quincena],
|
147 |
-
outputs=resultado
|
148 |
-
)
|
149 |
-
|
150 |
-
# Inicializar
|
151 |
-
inicializar_csv()
|
152 |
-
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|