Spaces:
Running
Running
Optimización en uso de segundos de capa gratuita
Browse files- conexion_firebase.py +10 -11
- funciones.py +4 -6
- herramientas.py +9 -22
- test.py +0 -3
conexion_firebase.py
CHANGED
@@ -40,17 +40,16 @@ def creaDato(coleccion, dato, info, contenido):
|
|
40 |
doc_ref = db.collection(coleccion).document(dato)
|
41 |
|
42 |
doc_ref.set({
|
43 |
-
# 'quote': quote,
|
44 |
info: contenido,
|
45 |
})
|
46 |
|
47 |
-
def verificar_token(id_token):
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
40 |
doc_ref = db.collection(coleccion).document(dato)
|
41 |
|
42 |
doc_ref.set({
|
|
|
43 |
info: contenido,
|
44 |
})
|
45 |
|
46 |
+
# def verificar_token(id_token):
|
47 |
+
# """Verifica el token de ID de Firebase."""
|
48 |
+
# try:
|
49 |
+
# # Verifica el token y decodifica la información del usuario
|
50 |
+
# decoded_token = auth.verify_id_token(id_token)
|
51 |
+
# uid = decoded_token['uid']
|
52 |
+
# return uid # Retorna el UID del usuario si el token es válido
|
53 |
+
# except auth.InvalidIdTokenError as e:
|
54 |
+
# print(f"Token inválido: {e}")
|
55 |
+
# return None # Retorna None si el token es inválido
|
funciones.py
CHANGED
@@ -37,8 +37,8 @@ def genera_platillo_gpu(platillo):
|
|
37 |
return result[0]
|
38 |
|
39 |
except Exception as e:
|
40 |
-
print("Excepción
|
41 |
-
# Opción para regresar imagen genérica.
|
42 |
# return "default.png"
|
43 |
return '{"Error 500": e}'
|
44 |
|
@@ -49,7 +49,7 @@ def genera_platillo_inference(platillo):
|
|
49 |
modelo_actual = conexion_firebase.obtenDato('nowme', 'huggingface', 'modelo_actual')
|
50 |
modelo = modelo_actual
|
51 |
|
52 |
-
print("Modelo:", modelo)
|
53 |
|
54 |
prompt = globales.previo + platillo
|
55 |
print("Platillo enviado:", platillo)
|
@@ -66,7 +66,7 @@ def genera_platillo_inference(platillo):
|
|
66 |
)
|
67 |
|
68 |
except Exception as e:
|
69 |
-
print("Excepción
|
70 |
if "Gateway Time-out" in str(e):
|
71 |
print("GATEWAY TIME-OUT 💀")
|
72 |
modelo=globales.inferencia_backup
|
@@ -74,8 +74,6 @@ def genera_platillo_inference(platillo):
|
|
74 |
herramientas.modificaModeloActual(modelo)
|
75 |
return f"Error: {e}"
|
76 |
|
77 |
-
#Cuando es GPU, debe de restar segundos disponibles de HF
|
78 |
-
herramientas.restaSegundosGPU(globales.work_cost)
|
79 |
img_io = io.BytesIO()
|
80 |
image.save(img_io, "PNG")
|
81 |
img_io.seek(0)
|
|
|
37 |
return result[0]
|
38 |
|
39 |
except Exception as e:
|
40 |
+
print("Excepción: ", e)
|
41 |
+
# Opción para regresar imagen genérica. (ya no porque se envía desde backend.)
|
42 |
# return "default.png"
|
43 |
return '{"Error 500": e}'
|
44 |
|
|
|
49 |
modelo_actual = conexion_firebase.obtenDato('nowme', 'huggingface', 'modelo_actual')
|
50 |
modelo = modelo_actual
|
51 |
|
52 |
+
#print("Modelo:", modelo)
|
53 |
|
54 |
prompt = globales.previo + platillo
|
55 |
print("Platillo enviado:", platillo)
|
|
|
66 |
)
|
67 |
|
68 |
except Exception as e:
|
69 |
+
print("Excepción: ", e)
|
70 |
if "Gateway Time-out" in str(e):
|
71 |
print("GATEWAY TIME-OUT 💀")
|
72 |
modelo=globales.inferencia_backup
|
|
|
74 |
herramientas.modificaModeloActual(modelo)
|
75 |
return f"Error: {e}"
|
76 |
|
|
|
|
|
77 |
img_io = io.BytesIO()
|
78 |
image.save(img_io, "PNG")
|
79 |
img_io.seek(0)
|
herramientas.py
CHANGED
@@ -19,23 +19,6 @@ def obtenUltimoTimestamp():
|
|
19 |
resultado = conexion_firebase.obtenDato('nowme', 'huggingface', last_timestamp)
|
20 |
|
21 |
return resultado
|
22 |
-
|
23 |
-
def esNuevoDia():
|
24 |
-
"""
|
25 |
-
Compara dos timestamps (en formato string ISO) y devuelve True si han
|
26 |
-
pasado más de 24 horas entre ellos, False en caso contrario.
|
27 |
-
"""
|
28 |
-
|
29 |
-
timestamp_original = obtenUltimoTimestamp()
|
30 |
-
timestamp_actual = int(time.time())
|
31 |
-
|
32 |
-
try:
|
33 |
-
segundos_en_24_horas = 24 * 60 * 60
|
34 |
-
diferencia_en_segundos = abs(timestamp_actual - timestamp_original)
|
35 |
-
return diferencia_en_segundos > segundos_en_24_horas
|
36 |
-
except ValueError:
|
37 |
-
print("Error: Formato de timestamp incorrecto.")
|
38 |
-
return False
|
39 |
|
40 |
def obtenSegundosDisponibles():
|
41 |
|
@@ -56,6 +39,7 @@ def renuevaSegundosDisponibles():
|
|
56 |
def renuevaTimestampActual():
|
57 |
|
58 |
timestamp_actual = int(time.time())
|
|
|
59 |
conexion_firebase.editaDato('nowme', 'huggingface', last_timestamp, timestamp_actual)
|
60 |
|
61 |
def restaSegundosGPU(cuantos_segundos):
|
@@ -122,16 +106,19 @@ def esDiaSiguiente():
|
|
122 |
timestamp_registro, False si es el mismo día.
|
123 |
"""
|
124 |
|
125 |
-
#
|
126 |
-
fecha_registro_dt = datetime.fromtimestamp(obtenUltimoTimestamp())
|
127 |
-
|
128 |
|
129 |
-
#
|
130 |
fecha_actual_dt = datetime.fromtimestamp(int(time.time()))
|
|
|
131 |
|
132 |
# Extraer solo la fecha de los objetos datetime
|
133 |
fecha_registro = fecha_registro_dt.date()
|
134 |
fecha_actual = fecha_actual_dt.date()
|
135 |
|
136 |
# Verificar si las fechas son diferentes
|
137 |
-
|
|
|
|
|
|
19 |
resultado = conexion_firebase.obtenDato('nowme', 'huggingface', last_timestamp)
|
20 |
|
21 |
return resultado
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
def obtenSegundosDisponibles():
|
24 |
|
|
|
39 |
def renuevaTimestampActual():
|
40 |
|
41 |
timestamp_actual = int(time.time())
|
42 |
+
print("El timestamp que está por escribir como el nuevo timestamp es: ", timestamp_actual)
|
43 |
conexion_firebase.editaDato('nowme', 'huggingface', last_timestamp, timestamp_actual)
|
44 |
|
45 |
def restaSegundosGPU(cuantos_segundos):
|
|
|
106 |
timestamp_registro, False si es el mismo día.
|
107 |
"""
|
108 |
|
109 |
+
#Obtiene el último registro de fecha de la base de firestore.
|
110 |
+
fecha_registro_dt = datetime.fromtimestamp(obtenUltimoTimestamp())
|
111 |
+
#print("Fecha guardada en base: ", fecha_registro_dt)
|
112 |
|
113 |
+
#Timestamp actual
|
114 |
fecha_actual_dt = datetime.fromtimestamp(int(time.time()))
|
115 |
+
#print("Fecha actual now: ", fecha_actual_dt)
|
116 |
|
117 |
# Extraer solo la fecha de los objetos datetime
|
118 |
fecha_registro = fecha_registro_dt.date()
|
119 |
fecha_actual = fecha_actual_dt.date()
|
120 |
|
121 |
# Verificar si las fechas son diferentes
|
122 |
+
resultado = fecha_actual > fecha_registro
|
123 |
+
#print("Resultado de resta de fechas: ", resultado)
|
124 |
+
return resultado
|
test.py
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
import herramientas
|
2 |
-
|
3 |
-
print(herramientas.nuevoDia())
|
|
|
|
|
|
|
|