Spaces:
Running
Running
Mejoras en gestión de segundos disponibles
Browse files- app.py +1 -0
- archivos/last_timestamp.txt +1 -1
- archivos/seconds_available.txt +1 -1
- herramientas.py +36 -6
- nextTest.py +4 -0
app.py
CHANGED
@@ -24,6 +24,7 @@ async def genera_imagen(platillo: str = Form(...)):
|
|
24 |
#Obtengo los segundos disponibles de procesamiento para saber si tengo GPU disponible de la capa gratuita o me voy a método cobrado.
|
25 |
seconds_available = herramientas.obtenSegundosDisponibles()
|
26 |
print("Los segundos de procesamiento disponibles el día de hoy son: ", seconds_available)
|
|
|
27 |
|
28 |
if seconds_available > globales.work_cost:
|
29 |
print("Usando GPU (capa gratuita)...")
|
|
|
24 |
#Obtengo los segundos disponibles de procesamiento para saber si tengo GPU disponible de la capa gratuita o me voy a método cobrado.
|
25 |
seconds_available = herramientas.obtenSegundosDisponibles()
|
26 |
print("Los segundos de procesamiento disponibles el día de hoy son: ", seconds_available)
|
27 |
+
print(herramientas.imprimeTime())
|
28 |
|
29 |
if seconds_available > globales.work_cost:
|
30 |
print("Usando GPU (capa gratuita)...")
|
archivos/last_timestamp.txt
CHANGED
@@ -1 +1 @@
|
|
1 |
-
|
|
|
1 |
+
1746553638
|
archivos/seconds_available.txt
CHANGED
@@ -1 +1 @@
|
|
1 |
-
|
|
|
1 |
+
90
|
herramientas.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
import os
|
2 |
import time
|
3 |
import socket
|
|
|
|
|
4 |
|
5 |
def obtenAccesoHF():
|
6 |
if local_check():
|
@@ -10,8 +12,6 @@ def obtenAccesoHF():
|
|
10 |
else:
|
11 |
print("Estoy en entorno Remoto...")
|
12 |
llave = os.getenv("llave")
|
13 |
-
print("Ésto es llave:", llave)
|
14 |
-
|
15 |
return llave
|
16 |
|
17 |
def local_check():
|
@@ -54,7 +54,8 @@ def esNuevoDia():
|
|
54 |
"""
|
55 |
|
56 |
timestamp_original = obtenUltimoTimestamp()
|
57 |
-
timestamp_actual = int(time.time())
|
|
|
58 |
|
59 |
try:
|
60 |
segundos_en_24_horas = 24 * 60 * 60
|
@@ -66,9 +67,7 @@ def esNuevoDia():
|
|
66 |
|
67 |
def obtenSegundosDisponibles():
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
if esNuevoDia() == True:
|
72 |
renuevaSegundosDisponibles()
|
73 |
|
74 |
archivo_ruta = "archivos/seconds_available.txt"
|
@@ -214,3 +213,34 @@ def renuevaModeloPrincipal():
|
|
214 |
except Exception as e:
|
215 |
print(f"Error al escribir en el archivo '{archivo_ruta}': {e}")
|
216 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
import time
|
3 |
import socket
|
4 |
+
from datetime import datetime
|
5 |
+
from datetime import datetime, date, timedelta
|
6 |
|
7 |
def obtenAccesoHF():
|
8 |
if local_check():
|
|
|
12 |
else:
|
13 |
print("Estoy en entorno Remoto...")
|
14 |
llave = os.getenv("llave")
|
|
|
|
|
15 |
return llave
|
16 |
|
17 |
def local_check():
|
|
|
54 |
"""
|
55 |
|
56 |
timestamp_original = obtenUltimoTimestamp()
|
57 |
+
timestamp_actual = int(time.time())
|
58 |
+
|
59 |
|
60 |
try:
|
61 |
segundos_en_24_horas = 24 * 60 * 60
|
|
|
67 |
|
68 |
def obtenSegundosDisponibles():
|
69 |
|
70 |
+
if esDiaSiguiente() == True:
|
|
|
|
|
71 |
renuevaSegundosDisponibles()
|
72 |
|
73 |
archivo_ruta = "archivos/seconds_available.txt"
|
|
|
213 |
except Exception as e:
|
214 |
print(f"Error al escribir en el archivo '{archivo_ruta}': {e}")
|
215 |
|
216 |
+
def imprimeTime():
|
217 |
+
timestamp_actual = int(time.time())
|
218 |
+
fecha_hora = datetime.fromtimestamp(timestamp_actual)
|
219 |
+
fecha_hora_legible = fecha_hora.strftime('%Y-%m-%d %H:%M:%S')
|
220 |
+
|
221 |
+
return fecha_hora_legible
|
222 |
+
|
223 |
+
def esDiaSiguiente(timestamp_ultimo_registro):
|
224 |
+
"""
|
225 |
+
Compara dos timestamps Unix y devuelve True si el día de timestamp_actual
|
226 |
+
es diferente al día de timestamp_registro.
|
227 |
+
|
228 |
+
Args:
|
229 |
+
timestamp_registro (int): Timestamp Unix del registro original (en segundos).
|
230 |
+
timestamp_actual (int): Timestamp Unix actual (en segundos).
|
231 |
+
|
232 |
+
Returns:
|
233 |
+
bool: True si el día de timestamp_actual es diferente al día de
|
234 |
+
timestamp_registro, False si es el mismo día.
|
235 |
+
"""
|
236 |
+
# Convertir los timestamps Unix a objetos datetime (zona horaria local)
|
237 |
+
fecha_registro_dt = datetime.fromtimestamp(timestamp_ultimo_registro)
|
238 |
+
fecha_actual_dt = datetime.fromtimestamp(int(time.time())) #Timestamp actual.
|
239 |
+
|
240 |
+
# Extraer solo la fecha de los objetos datetime
|
241 |
+
fecha_registro = fecha_registro_dt.date()
|
242 |
+
fecha_actual = fecha_actual_dt.date()
|
243 |
+
|
244 |
+
# Verificar si las fechas son diferentes
|
245 |
+
return fecha_actual > fecha_registro
|
246 |
+
|
nextTest.py
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import herramientas
|
2 |
+
|
3 |
+
print("Resultado: ")
|
4 |
+
print(herramientas.esDiaSiguiente(1746553638))
|