DaniFera commited on
Commit
cbf42ed
verified
1 Parent(s): b06ff62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -1
app.py CHANGED
@@ -1,11 +1,48 @@
1
- # Versi贸n 2.2: Interfaz con Comparador de Texto Mejorado
2
  import gradio as gr
3
  import pandas as pd
4
  import config
 
 
 
5
  from core import PDFEngine
6
 
7
  engine = PDFEngine()
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  # --- WRAPPERS ---
10
  def update_file_list(files):
11
  if not files: return pd.DataFrame(), ""
 
1
+ # Versi贸n 2.5: App con Ciclo de Vida de Seguridad (Auto-borrado)
2
  import gradio as gr
3
  import pandas as pd
4
  import config
5
+ import os
6
+ import time
7
+ import threading
8
  from core import PDFEngine
9
 
10
  engine = PDFEngine()
11
 
12
+ # --- SEGURIDAD: HILO DE LIMPIEZA AUTOM脕TICA ---
13
+ def cleanup_cron():
14
+ """
15
+ Se ejecuta en segundo plano.
16
+ Revisa la carpeta temporal cada 10 minutos y borra archivos
17
+ que tengan m谩s de 20 minutos de antig眉edad.
18
+ """
19
+ while True:
20
+ try:
21
+ # Esperar 10 minutos (600 segundos) antes de la siguiente ronda
22
+ time.sleep(600)
23
+
24
+ now = time.time()
25
+ # Umbral: 20 minutos (1200 segundos)
26
+ cutoff = now - 1200
27
+
28
+ if os.path.exists(config.TEMP_DIR):
29
+ for filename in os.listdir(config.TEMP_DIR):
30
+ filepath = os.path.join(config.TEMP_DIR, filename)
31
+ # Verificar si es un archivo y si es viejo
32
+ if os.path.isfile(filepath):
33
+ t_mod = os.path.getmtime(filepath)
34
+ if t_mod < cutoff:
35
+ try:
36
+ os.remove(filepath)
37
+ print(f"[SEGURIDAD] Archivo expirado eliminado: {filename}")
38
+ except Exception as e:
39
+ print(f"[ERROR] No se pudo borrar {filename}: {e}")
40
+ except Exception as e:
41
+ print(f"[ERROR CR脥TICO] Fallo en el hilo de limpieza: {e}")
42
+
43
+ # Iniciar el conserje en un hilo separado (Daemon para que muera si la app muere)
44
+ threading.Thread(target=cleanup_cron, daemon=True).start()
45
+
46
  # --- WRAPPERS ---
47
  def update_file_list(files):
48
  if not files: return pd.DataFrame(), ""