|
|
|
"""Untitled19.ipynb |
|
|
|
Automatically generated by Colab. |
|
|
|
Original file is located at |
|
https://colab.research.google.com/drive/12FC8IfauEBNv8yXDkOWez5aZ0F6sD5q1 |
|
""" |
|
|
|
import gradio as gr |
|
import csv |
|
import re |
|
from datetime import datetime |
|
from hashlib import sha256 |
|
import os |
|
from PIL import Image |
|
import requests |
|
from io import BytesIO |
|
|
|
|
|
CSV_FILE = "registros_incidencias.csv" |
|
PASSWORD_HASH = "8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918" |
|
|
|
PRESTACIONES = [ |
|
"1. PROFESIONALIZACIÓN", |
|
"2. ESTIMULOS DE PRODUCTIVIDAD", |
|
"3. UNIFORMES", |
|
"4. DESCUENTOS INJUSTIFICADOS", |
|
"5. SEGURO DE VIDA", |
|
"6. AHORRO SOLIDARIO", |
|
"7. OTROS" |
|
] |
|
|
|
REGEX_CURP = re.compile(r'^[A-Z]{4}[0-9]{6}[HM][A-Z]{5}[A-Z0-9]{2}$') |
|
def validar_curp(curp): |
|
return bool(REGEX_CURP.match(curp.upper())) |
|
|
|
def inicializar_csv(): |
|
if not os.path.exists(CSV_FILE): |
|
with open(CSV_FILE, 'w', newline='', encoding='utf-8') as f: |
|
writer = csv.writer(f) |
|
writer.writerow([ |
|
"Fecha_Registro", "Entidad", "Nombre", |
|
"CURP", "Prestacion", "Quincena" |
|
]) |
|
|
|
def guardar_registro(entidad, nombre, curp, prestacion, quincena): |
|
if not all([entidad, nombre, curp, prestacion, quincena]): |
|
return "⚠️ Todos los campos son obligatorios" |
|
|
|
if not validar_curp(curp): |
|
return "⚠️ CURP inválido" |
|
|
|
try: |
|
with open(CSV_FILE, 'a', newline='', encoding='utf-8') as f: |
|
writer = csv.writer(f) |
|
writer.writerow([ |
|
datetime.now().strftime("%Y-%m-%d %H:%M:%S"), |
|
entidad.strip().upper(), |
|
nombre.strip().title(), |
|
curp.upper(), |
|
prestacion, |
|
quincena |
|
]) |
|
return "✅ Registro exitoso" |
|
except Exception as e: |
|
return f"❌ Error: {str(e)}" |
|
|
|
def verificar_credenciales(username, password): |
|
return username == "admin" and sha256(password.encode()).hexdigest() == PASSWORD_HASH |
|
|
|
|
|
with gr.Blocks(title="Sistema de Captura") as app: |
|
|
|
logged_in = gr.State(False) |
|
|
|
|
|
with gr.Column(visible=True) as login_col: |
|
|
|
try: |
|
|
|
response = requests.open("d5bb4c4a-f9e5-4c70-a53c-23b7dc3872a1.jpg") |
|
img = Image.open(BytesIO(response.content)) |
|
login_img = gr.Image(img, label="", interactive=False, show_label=False) |
|
except: |
|
|
|
|
|
login_img = gr.Image("d5bb4c4a-f9e5-4c70-a53c-23b7dc3872a1.jpg", label="", interactive=False, show_label=False) |
|
|
|
gr.Markdown("# Sistema de Captura de Incidencias") |
|
username = gr.Textbox(label="Usuario") |
|
password = gr.Textbox(label="Contraseña", type="password") |
|
login_btn = gr.Button("Ingresar") |
|
login_msg = gr.Textbox(label="Mensaje", interactive=False) |
|
|
|
|
|
with gr.Column(visible=False) as captura_col: |
|
gr.Markdown("## Captura de Datos") |
|
|
|
with gr.Row(): |
|
with gr.Column(): |
|
entidad = gr.Textbox(label="Entidad Federativa") |
|
nombre = gr.Textbox(label="Nombre completo") |
|
curp = gr.Textbox(label="CURP") |
|
prestacion = gr.Dropdown(PRESTACIONES, label="Prestación afectada") |
|
quincena = gr.Textbox(label="Quincena (AAAA-MM-DD)") |
|
submit_btn = gr.Button("Guardar") |
|
|
|
resultado = gr.Textbox(label="Resultado") |
|
|
|
logout_btn = gr.Button("Cerrar sesión") |
|
|
|
|
|
def autenticar(user, pwd): |
|
if verificar_credenciales(user, pwd): |
|
return { |
|
login_col: gr.update(visible=False), |
|
captura_col: gr.update(visible=True), |
|
login_msg: "" |
|
} |
|
return { |
|
login_msg: "⚠️ Credenciales incorrectas" |
|
} |
|
|
|
def cerrar_sesion(): |
|
return { |
|
login_col: gr.update(visible=True), |
|
captura_col: gr.update(visible=False), |
|
login_msg: "" |
|
} |
|
|
|
|
|
login_btn.click( |
|
autenticar, |
|
inputs=[username, password], |
|
outputs=[login_col, captura_col, login_msg] |
|
) |
|
|
|
logout_btn.click( |
|
cerrar_sesion, |
|
outputs=[login_col, captura_col, login_msg] |
|
) |
|
|
|
submit_btn.click( |
|
guardar_registro, |
|
inputs=[entidad, nombre, curp, prestacion, quincena], |
|
outputs=resultado |
|
) |
|
|
|
|
|
inicializar_csv() |
|
app.launch() |