Spaces:
Running
Running
Diccionario de Modelos Disponibles
Browse files- app.py +0 -2
- espacios.py +41 -0
- funciones.py +20 -12
- globales.py +26 -2
- herramientas.py +13 -15
app.py
CHANGED
@@ -34,8 +34,6 @@ async def genera_imagen(platillo: str = Form(...)):
|
|
34 |
|
35 |
seconds_available = herramientas.obtenSegundosDisponibles()
|
36 |
|
37 |
-
#seconds_available = 0
|
38 |
-
|
39 |
print(herramientas.imprimeTimeNow())
|
40 |
|
41 |
if seconds_available > globales.work_cost:
|
|
|
34 |
|
35 |
seconds_available = herramientas.obtenSegundosDisponibles()
|
36 |
|
|
|
|
|
37 |
print(herramientas.imprimeTimeNow())
|
38 |
|
39 |
if seconds_available > globales.work_cost:
|
espacios.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import herramientas
|
2 |
+
|
3 |
+
server = herramientas.getFluxServer()
|
4 |
+
print("Server elegido: ", server)
|
5 |
+
print("El type es: ", type(server))
|
6 |
+
|
7 |
+
espacio = [
|
8 |
+
{
|
9 |
+
"id": "black-forest-labs/FLUX.1-dev",
|
10 |
+
"static_kwargs": {
|
11 |
+
"api_name": "/infer",
|
12 |
+
}
|
13 |
+
},
|
14 |
+
# {
|
15 |
+
# "id": "black-forest-labs/FLUX.1-schnell",
|
16 |
+
# "static_kwargs": {
|
17 |
+
# "api_name": "/infer",
|
18 |
+
# }
|
19 |
+
# },
|
20 |
+
# {
|
21 |
+
# "id": "NihalGazi/FLUX-Pro-Unlimited",
|
22 |
+
# "static_kwargs": {
|
23 |
+
# "api_name": "/generate_image",
|
24 |
+
# "server_choice": server,
|
25 |
+
# }
|
26 |
+
# },
|
27 |
+
# {
|
28 |
+
# "id": "HiDream-ai/HiDream-I1-Dev",
|
29 |
+
# "static_kwargs": {
|
30 |
+
# "api_name": "/infer",
|
31 |
+
#
|
32 |
+
# }
|
33 |
+
# },
|
34 |
+
# {
|
35 |
+
# "id": "stabilityai/stable-diffusion",
|
36 |
+
# "static_kwargs": {
|
37 |
+
# "api_name": "/generate",
|
38 |
+
#
|
39 |
+
# }
|
40 |
+
# }
|
41 |
+
]
|
funciones.py
CHANGED
@@ -1,25 +1,33 @@
|
|
1 |
import io
|
2 |
import globales
|
|
|
3 |
import herramientas
|
4 |
import gradio_client
|
5 |
from huggingface_hub import InferenceClient
|
6 |
import conexion_firebase
|
|
|
|
|
7 |
|
8 |
def genera_platillo_gpu(platillo):
|
9 |
|
10 |
prompt = globales.previo + platillo
|
11 |
-
print("Platillo enviado:", platillo)
|
12 |
-
|
13 |
-
kwargs = {
|
14 |
-
"prompt": prompt,
|
15 |
-
"api_name": "/infer"
|
16 |
-
}
|
17 |
|
18 |
try:
|
19 |
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
result = client.predict(**kwargs,
|
22 |
-
|
23 |
# negative_prompt="",
|
24 |
# seed=42,
|
25 |
# randomize_seed=True,
|
@@ -30,6 +38,8 @@ def genera_platillo_gpu(platillo):
|
|
30 |
# api_name="/infer"
|
31 |
)
|
32 |
|
|
|
|
|
33 |
#Cuando es GPU, debe de restar segundos disponibles de HF
|
34 |
herramientas.restaSegundosGPU(globales.work_cost)
|
35 |
|
@@ -37,7 +47,7 @@ def genera_platillo_gpu(platillo):
|
|
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}'
|
@@ -49,15 +59,13 @@ def genera_platillo_inference(platillo):
|
|
49 |
modelo_actual = conexion_firebase.obtenDato('nowme', 'huggingface', 'modelo_actual')
|
50 |
modelo = modelo_actual
|
51 |
|
52 |
-
#modelo = globales.inferencia
|
53 |
-
|
54 |
print("Modelo:", modelo)
|
55 |
|
56 |
#Elegir proveedor de inferencia
|
57 |
creditos_restantes_inference = conexion_firebase.obtenDato('nowme', 'huggingface', 'hfInference')
|
58 |
#creditos_restantes_inference = 5000
|
59 |
|
60 |
-
print("Los créditos restantes de hf-inference que tienes son: ", creditos_restantes_inference)
|
61 |
if creditos_restantes_inference > 0:
|
62 |
provedor_seleccionado = globales.proveedor
|
63 |
else:
|
|
|
1 |
import io
|
2 |
import globales
|
3 |
+
import espacios
|
4 |
import herramientas
|
5 |
import gradio_client
|
6 |
from huggingface_hub import InferenceClient
|
7 |
import conexion_firebase
|
8 |
+
import random
|
9 |
+
import time
|
10 |
|
11 |
def genera_platillo_gpu(platillo):
|
12 |
|
13 |
prompt = globales.previo + platillo
|
14 |
+
print("Platillo enviado:", platillo)
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
try:
|
17 |
|
18 |
+
selected_space_config = random.choice(espacios.espacio)
|
19 |
+
|
20 |
+
client = gradio_client.Client(selected_space_config['id'], hf_token=globales.llave)
|
21 |
+
|
22 |
+
# kwargs = {
|
23 |
+
# "prompt": prompt,
|
24 |
+
# "api_name": "/infer"
|
25 |
+
# }
|
26 |
+
|
27 |
+
kwargs = selected_space_config['static_kwargs']
|
28 |
+
|
29 |
result = client.predict(**kwargs,
|
30 |
+
prompt=prompt,
|
31 |
# negative_prompt="",
|
32 |
# seed=42,
|
33 |
# randomize_seed=True,
|
|
|
38 |
# api_name="/infer"
|
39 |
)
|
40 |
|
41 |
+
#print("Result inmediato es: ", result)
|
42 |
+
|
43 |
#Cuando es GPU, debe de restar segundos disponibles de HF
|
44 |
herramientas.restaSegundosGPU(globales.work_cost)
|
45 |
|
|
|
47 |
return result[0]
|
48 |
|
49 |
except Exception as e:
|
50 |
+
print("Excepción: ", e)
|
51 |
# Opción para regresar imagen genérica. (ya no porque se envía desde backend.)
|
52 |
# return "default.png"
|
53 |
return '{"Error 500": e}'
|
|
|
59 |
modelo_actual = conexion_firebase.obtenDato('nowme', 'huggingface', 'modelo_actual')
|
60 |
modelo = modelo_actual
|
61 |
|
|
|
|
|
62 |
print("Modelo:", modelo)
|
63 |
|
64 |
#Elegir proveedor de inferencia
|
65 |
creditos_restantes_inference = conexion_firebase.obtenDato('nowme', 'huggingface', 'hfInference')
|
66 |
#creditos_restantes_inference = 5000
|
67 |
|
68 |
+
#print("Los créditos restantes de hf-inference que tienes son: ", creditos_restantes_inference)
|
69 |
if creditos_restantes_inference > 0:
|
70 |
provedor_seleccionado = globales.proveedor
|
71 |
else:
|
globales.py
CHANGED
@@ -1,10 +1,21 @@
|
|
1 |
import autenticacion
|
2 |
-
version = "0.0.
|
3 |
|
4 |
#previo = "Una fotografía de un plato blanco con "
|
5 |
previo = "A photograph of a white plate with "
|
6 |
llave, servidor = autenticacion.defineAmbiente()
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
#espacio = "black-forest-labs/FLUX.1-dev"
|
9 |
inferencia = "black-forest-labs/FLUX.1-dev"
|
10 |
inferencia_backup = "black-forest-labs/FLUX.1-schnell"
|
@@ -13,3 +24,16 @@ proveedor_back = "fal-ai"
|
|
13 |
work_cost = 1 #Los segundos que cuesta la generación de una imagen, para control de la capa gratuita.
|
14 |
inference_cost = 1
|
15 |
quota = 1500
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import autenticacion
|
2 |
+
version = "0.0.1"
|
3 |
|
4 |
#previo = "Una fotografía de un plato blanco con "
|
5 |
previo = "A photograph of a white plate with "
|
6 |
llave, servidor = autenticacion.defineAmbiente()
|
7 |
+
|
8 |
+
|
9 |
+
# espacio = [
|
10 |
+
# "black-forest-labs/FLUX.1-dev",
|
11 |
+
# #"black-forest-labs/FLUX.1-schnell",
|
12 |
+
# "NihalGazi/FLUX-Pro-Unlimited",
|
13 |
+
# #"HiDream-ai/HiDream-I1-Dev",
|
14 |
+
# #"stabilityai/stable-diffusion"
|
15 |
+
|
16 |
+
# ]
|
17 |
+
|
18 |
+
|
19 |
#espacio = "black-forest-labs/FLUX.1-dev"
|
20 |
inferencia = "black-forest-labs/FLUX.1-dev"
|
21 |
inferencia_backup = "black-forest-labs/FLUX.1-schnell"
|
|
|
24 |
work_cost = 1 #Los segundos que cuesta la generación de una imagen, para control de la capa gratuita.
|
25 |
inference_cost = 1
|
26 |
quota = 1500
|
27 |
+
|
28 |
+
|
29 |
+
SERVER_NAMES = {
|
30 |
+
"google_us": "Google US Server",
|
31 |
+
#"azure_lite": "Azure Lite Supercomputer Server",
|
32 |
+
#"artemis" : "Artemis GPU Super cluster",
|
33 |
+
#"nb_dr" : "NebulaDrive Tensor Server",
|
34 |
+
#"pixelnet" : "PixelNet NPU Server",
|
35 |
+
#"nsfw_core" : "NSFW-Core: Uncensored Server",
|
36 |
+
#"nsfw_core_2" : "NSFW-Core: Uncensored Server 2",
|
37 |
+
#"nsfw_core_3" : "NSFW-Core: Uncensored Server 3",
|
38 |
+
#"nsfw_core_4" : "NSFW-Core: Uncensored Server 4",
|
39 |
+
}
|
herramientas.py
CHANGED
@@ -4,6 +4,7 @@ import conexion_firebase
|
|
4 |
import globales
|
5 |
import pytz
|
6 |
import time
|
|
|
7 |
|
8 |
if globales.servidor == "moibe":
|
9 |
segundos = "segundos_dev"
|
@@ -17,7 +18,7 @@ def obtenUltimoTimestamp():
|
|
17 |
Obtiene el último timestamp de renovación guardado.
|
18 |
"""
|
19 |
resultado = conexion_firebase.obtenDato('nowme', 'huggingface', last_timestamp)
|
20 |
-
print("Obten último timestamp obtenido: ", resultado)
|
21 |
|
22 |
return resultado
|
23 |
|
@@ -30,16 +31,6 @@ def obtenSegundosDisponibles():
|
|
30 |
#Finalmente obten los segundos disponibles después de las operaciones.
|
31 |
return conexion_firebase.obtenDato('nowme', 'huggingface', segundos)
|
32 |
|
33 |
-
def obtenSegundosDisponibles():
|
34 |
-
|
35 |
-
if esDiaSiguiente() == True:
|
36 |
-
renuevaSegundosDisponibles()
|
37 |
-
renuevaModeloPrincipal()
|
38 |
-
|
39 |
-
#Finalmente obten los segundos disponibles después de las operaciones.
|
40 |
-
return conexion_firebase.obtenDato('nowme', 'huggingface', segundos)
|
41 |
-
|
42 |
-
|
43 |
def obtenSegundosDisponiblesInference():
|
44 |
|
45 |
# if esDiaSiguiente() == True:
|
@@ -73,7 +64,7 @@ def restaSegundosGPU(cuantos_segundos):
|
|
73 |
|
74 |
# Restar los segundos
|
75 |
nuevos_segundos_disponibles = segundos_disponibles - cuantos_segundos
|
76 |
-
|
77 |
conexion_firebase.editaDato('nowme', 'huggingface', segundos, nuevos_segundos_disponibles)
|
78 |
|
79 |
def restaSegundosInference(cuantos_segundos):
|
@@ -83,7 +74,7 @@ def restaSegundosInference(cuantos_segundos):
|
|
83 |
"""
|
84 |
|
85 |
segundos_disponibles = obtenSegundosDisponiblesInference()
|
86 |
-
print("Segundos disponibles Inference: ", segundos_disponibles)
|
87 |
|
88 |
# Restar los segundos
|
89 |
nuevos_segundos_disponibles = segundos_disponibles - cuantos_segundos
|
@@ -207,7 +198,14 @@ def esDiaSiguiente():
|
|
207 |
|
208 |
# Verificar si las fechas son diferentes
|
209 |
resultado = fecha_actual > fecha_registro
|
210 |
-
print("Resultado de resta de fechas: ", resultado)
|
211 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
212 |
|
213 |
-
return
|
|
|
4 |
import globales
|
5 |
import pytz
|
6 |
import time
|
7 |
+
import random
|
8 |
|
9 |
if globales.servidor == "moibe":
|
10 |
segundos = "segundos_dev"
|
|
|
18 |
Obtiene el último timestamp de renovación guardado.
|
19 |
"""
|
20 |
resultado = conexion_firebase.obtenDato('nowme', 'huggingface', last_timestamp)
|
21 |
+
#print("Obten último timestamp obtenido: ", resultado)
|
22 |
|
23 |
return resultado
|
24 |
|
|
|
31 |
#Finalmente obten los segundos disponibles después de las operaciones.
|
32 |
return conexion_firebase.obtenDato('nowme', 'huggingface', segundos)
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
def obtenSegundosDisponiblesInference():
|
35 |
|
36 |
# if esDiaSiguiente() == True:
|
|
|
64 |
|
65 |
# Restar los segundos
|
66 |
nuevos_segundos_disponibles = segundos_disponibles - cuantos_segundos
|
67 |
+
Segundos disponibles ahora: ", nuevos_segundos_disponibles)
|
68 |
conexion_firebase.editaDato('nowme', 'huggingface', segundos, nuevos_segundos_disponibles)
|
69 |
|
70 |
def restaSegundosInference(cuantos_segundos):
|
|
|
74 |
"""
|
75 |
|
76 |
segundos_disponibles = obtenSegundosDisponiblesInference()
|
77 |
+
#print("Segundos disponibles Inference: ", segundos_disponibles)
|
78 |
|
79 |
# Restar los segundos
|
80 |
nuevos_segundos_disponibles = segundos_disponibles - cuantos_segundos
|
|
|
198 |
|
199 |
# Verificar si las fechas son diferentes
|
200 |
resultado = fecha_actual > fecha_registro
|
201 |
+
print("Resultado de resta de fechas: ", resultado)
|
202 |
|
203 |
+
return resultado
|
204 |
+
|
205 |
+
def getFluxServer():
|
206 |
+
print("In getFluxServer...")
|
207 |
+
server_keys = list(globales.SERVER_NAMES.values())
|
208 |
+
random_value = random.choice(server_keys)
|
209 |
+
print("Random key: ", random_value)
|
210 |
|
211 |
+
return random_value
|