Spaces:
Running
Running
Renovación de segundos disponibles correcta
Browse files- conexion_firebase.py +3 -2
- funciones.py +3 -3
- herramientas.py +15 -30
conexion_firebase.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
import firebase_admin
|
| 2 |
from firebase_admin import firestore
|
| 3 |
from firebase_admin import auth
|
| 4 |
-
import globales
|
| 5 |
from firebase_admin import credentials
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
firebase_cred = credentials.Certificate('config.json')
|
|
@@ -25,9 +25,10 @@ def obtenDato(coleccion, dato, info):
|
|
| 25 |
return diccionario.get(info)
|
| 26 |
|
| 27 |
def editaDato(coleccion, dato, info, contenido):
|
| 28 |
-
|
| 29 |
#Primero debemos definir la referencia al documento, o sea a la hoja de usuario.
|
| 30 |
doc_ref = db.collection(coleccion).document(dato)
|
|
|
|
| 31 |
|
| 32 |
doc_ref.update({
|
| 33 |
# 'quote': quote,
|
|
|
|
| 1 |
import firebase_admin
|
| 2 |
from firebase_admin import firestore
|
| 3 |
from firebase_admin import auth
|
|
|
|
| 4 |
from firebase_admin import credentials
|
| 5 |
+
import time
|
| 6 |
|
| 7 |
|
| 8 |
firebase_cred = credentials.Certificate('config.json')
|
|
|
|
| 25 |
return diccionario.get(info)
|
| 26 |
|
| 27 |
def editaDato(coleccion, dato, info, contenido):
|
| 28 |
+
|
| 29 |
#Primero debemos definir la referencia al documento, o sea a la hoja de usuario.
|
| 30 |
doc_ref = db.collection(coleccion).document(dato)
|
| 31 |
+
print("Doc ref es: ", doc_ref)
|
| 32 |
|
| 33 |
doc_ref.update({
|
| 34 |
# 'quote': quote,
|
funciones.py
CHANGED
|
@@ -18,13 +18,13 @@ def genera_platillo_gpu(platillo):
|
|
| 18 |
try:
|
| 19 |
|
| 20 |
client = gradio_client.Client(globales.espacio, hf_token=globales.llave)
|
| 21 |
-
result = client.predict(**kwargs
|
| 22 |
# prompt=prompt,
|
| 23 |
# negative_prompt="",
|
| 24 |
# seed=42,
|
| 25 |
# randomize_seed=True,
|
| 26 |
-
|
| 27 |
-
|
| 28 |
# guidance_scale=3.5,
|
| 29 |
# num_inference_steps=28,
|
| 30 |
# api_name="/infer"
|
|
|
|
| 18 |
try:
|
| 19 |
|
| 20 |
client = gradio_client.Client(globales.espacio, hf_token=globales.llave)
|
| 21 |
+
result = client.predict(**kwargs,
|
| 22 |
# prompt=prompt,
|
| 23 |
# negative_prompt="",
|
| 24 |
# seed=42,
|
| 25 |
# randomize_seed=True,
|
| 26 |
+
width=786,
|
| 27 |
+
height=568,
|
| 28 |
# guidance_scale=3.5,
|
| 29 |
# num_inference_steps=28,
|
| 30 |
# api_name="/infer"
|
herramientas.py
CHANGED
|
@@ -1,22 +1,22 @@
|
|
| 1 |
import time
|
| 2 |
from datetime import datetime
|
| 3 |
-
from datetime import datetime
|
| 4 |
import conexion_firebase
|
| 5 |
import globales
|
| 6 |
|
| 7 |
if globales.servidor == "moibe":
|
| 8 |
segundos = "segundos_dev"
|
|
|
|
| 9 |
else:
|
| 10 |
segundos = "segundos_prod"
|
|
|
|
| 11 |
|
| 12 |
def obtenUltimoTimestamp():
|
| 13 |
"""
|
| 14 |
Obtiene el último timestamp de renovación guardado.
|
| 15 |
"""
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
resultado = conexion_firebase.obtenDato('nowme', 'huggingface', 'last_timestamp')
|
| 20 |
return resultado
|
| 21 |
|
| 22 |
|
|
@@ -39,15 +39,14 @@ def esNuevoDia():
|
|
| 39 |
|
| 40 |
def obtenSegundosDisponibles():
|
| 41 |
|
| 42 |
-
print("
|
| 43 |
|
| 44 |
-
if esDiaSiguiente() == True:
|
| 45 |
renuevaSegundosDisponibles()
|
| 46 |
renuevaModeloPrincipal()
|
| 47 |
|
| 48 |
#Finalmente obten los segundos disponibles después de las operaciones.
|
| 49 |
return conexion_firebase.obtenDato('nowme', 'huggingface', segundos)
|
| 50 |
-
|
| 51 |
|
| 52 |
def renuevaSegundosDisponibles():
|
| 53 |
|
|
@@ -56,19 +55,11 @@ def renuevaSegundosDisponibles():
|
|
| 56 |
conexion_firebase.editaDato('nowme', 'huggingface', segundos, quota_total)
|
| 57 |
renuevaTimestampActual()
|
| 58 |
|
| 59 |
-
# Guardar el nuevo número en el archivo
|
| 60 |
-
# try:
|
| 61 |
-
# archivo_ruta = "archivos/seconds_available.txt"
|
| 62 |
-
# with open(archivo_ruta, 'w') as archivo:
|
| 63 |
-
# archivo.write(str(quota_total))
|
| 64 |
-
# print(f"Se renovaron los {quota_total} segundos disponibles.")
|
| 65 |
-
# except Exception as e:
|
| 66 |
-
# print(f"Error al escribir en el archivo '{archivo_ruta}': {e}")
|
| 67 |
|
| 68 |
def renuevaTimestampActual():
|
| 69 |
|
| 70 |
timestamp_actual = int(time.time())
|
| 71 |
-
conexion_firebase.editaDato('nowme', 'huggingface',
|
| 72 |
|
| 73 |
def restaSegundosGPU(cuantos_segundos):
|
| 74 |
"""
|
|
@@ -76,9 +67,6 @@ def restaSegundosGPU(cuantos_segundos):
|
|
| 76 |
resta los segundos dados como parámetro y guarda el nuevo valor en el archivo.
|
| 77 |
"""
|
| 78 |
|
| 79 |
-
print("Estoy en resta segundos...")
|
| 80 |
-
print("El parámetro recibido es segundos: ", cuantos_segundos)
|
| 81 |
-
print("Y su tipo es: ", type(cuantos_segundos))
|
| 82 |
segundos_disponibles = obtenSegundosDisponibles()
|
| 83 |
print("Los segundos obtenidos de obtenSegundosDisponibles son: ", segundos_disponibles)
|
| 84 |
|
|
@@ -88,14 +76,6 @@ def restaSegundosGPU(cuantos_segundos):
|
|
| 88 |
|
| 89 |
conexion_firebase.editaDato('nowme', 'huggingface', segundos, nuevos_segundos_disponibles)
|
| 90 |
|
| 91 |
-
# # Guardar el nuevo número en el archivo
|
| 92 |
-
# try:
|
| 93 |
-
# archivo_ruta = "archivos/seconds_available.txt"
|
| 94 |
-
# with open(archivo_ruta, 'w') as archivo:
|
| 95 |
-
# archivo.write(str(nuevos_segundos_disponibles))
|
| 96 |
-
# print(f"Se restaron {segundos} segundos. Ahora quedan {nuevos_segundos_disponibles} segundos disponibles.")
|
| 97 |
-
# except Exception as e:
|
| 98 |
-
# print(f"Error al escribir en el archivo '{archivo_ruta}': {e}")
|
| 99 |
|
| 100 |
def modificaModeloActual(nuevo_modelo):
|
| 101 |
"""
|
|
@@ -134,15 +114,20 @@ def esDiaSiguiente():
|
|
| 134 |
timestamp_registro, False si es el mismo día.
|
| 135 |
"""
|
| 136 |
|
| 137 |
-
print("Estoy en esDiaSiguiente...")
|
| 138 |
# Convertir los timestamps Unix a objetos datetime (zona horaria local)
|
| 139 |
fecha_registro_dt = datetime.fromtimestamp(obtenUltimoTimestamp())
|
| 140 |
-
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
# Extraer solo la fecha de los objetos datetime
|
| 143 |
fecha_registro = fecha_registro_dt.date()
|
| 144 |
fecha_actual = fecha_actual_dt.date()
|
| 145 |
|
|
|
|
|
|
|
| 146 |
# Verificar si las fechas son diferentes
|
| 147 |
return fecha_actual > fecha_registro
|
| 148 |
|
|
|
|
| 1 |
import time
|
| 2 |
from datetime import datetime
|
| 3 |
+
from datetime import datetime
|
| 4 |
import conexion_firebase
|
| 5 |
import globales
|
| 6 |
|
| 7 |
if globales.servidor == "moibe":
|
| 8 |
segundos = "segundos_dev"
|
| 9 |
+
last_timestamp = "last_timestamp_dev"
|
| 10 |
else:
|
| 11 |
segundos = "segundos_prod"
|
| 12 |
+
last_timestamp = "last_timestamp_prod"
|
| 13 |
|
| 14 |
def obtenUltimoTimestamp():
|
| 15 |
"""
|
| 16 |
Obtiene el último timestamp de renovación guardado.
|
| 17 |
"""
|
| 18 |
|
| 19 |
+
resultado = conexion_firebase.obtenDato('nowme', 'huggingface', last_timestamp)
|
|
|
|
|
|
|
| 20 |
return resultado
|
| 21 |
|
| 22 |
|
|
|
|
| 39 |
|
| 40 |
def obtenSegundosDisponibles():
|
| 41 |
|
| 42 |
+
print("Obteniendo segundos disponibles...")
|
| 43 |
|
| 44 |
+
if esDiaSiguiente() == True:
|
| 45 |
renuevaSegundosDisponibles()
|
| 46 |
renuevaModeloPrincipal()
|
| 47 |
|
| 48 |
#Finalmente obten los segundos disponibles después de las operaciones.
|
| 49 |
return conexion_firebase.obtenDato('nowme', 'huggingface', segundos)
|
|
|
|
| 50 |
|
| 51 |
def renuevaSegundosDisponibles():
|
| 52 |
|
|
|
|
| 55 |
conexion_firebase.editaDato('nowme', 'huggingface', segundos, quota_total)
|
| 56 |
renuevaTimestampActual()
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
def renuevaTimestampActual():
|
| 60 |
|
| 61 |
timestamp_actual = int(time.time())
|
| 62 |
+
conexion_firebase.editaDato('nowme', 'huggingface', last_timestamp, timestamp_actual)
|
| 63 |
|
| 64 |
def restaSegundosGPU(cuantos_segundos):
|
| 65 |
"""
|
|
|
|
| 67 |
resta los segundos dados como parámetro y guarda el nuevo valor en el archivo.
|
| 68 |
"""
|
| 69 |
|
|
|
|
|
|
|
|
|
|
| 70 |
segundos_disponibles = obtenSegundosDisponibles()
|
| 71 |
print("Los segundos obtenidos de obtenSegundosDisponibles son: ", segundos_disponibles)
|
| 72 |
|
|
|
|
| 76 |
|
| 77 |
conexion_firebase.editaDato('nowme', 'huggingface', segundos, nuevos_segundos_disponibles)
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
def modificaModeloActual(nuevo_modelo):
|
| 81 |
"""
|
|
|
|
| 114 |
timestamp_registro, False si es el mismo día.
|
| 115 |
"""
|
| 116 |
|
|
|
|
| 117 |
# Convertir los timestamps Unix a objetos datetime (zona horaria local)
|
| 118 |
fecha_registro_dt = datetime.fromtimestamp(obtenUltimoTimestamp())
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
#fecha_actual_dt = datetime.fromtimestamp(int(time.time())) #Timestamp actual.
|
| 122 |
+
fecha_actual_dt = datetime.fromtimestamp(int(time.time()))
|
| 123 |
+
|
| 124 |
+
|
| 125 |
# Extraer solo la fecha de los objetos datetime
|
| 126 |
fecha_registro = fecha_registro_dt.date()
|
| 127 |
fecha_actual = fecha_actual_dt.date()
|
| 128 |
|
| 129 |
+
print(f"Estoy comparando fecha registro {fecha_registro} con fecha actual {fecha_actual}...")
|
| 130 |
+
|
| 131 |
# Verificar si las fechas son diferentes
|
| 132 |
return fecha_actual > fecha_registro
|
| 133 |
|