Spaces:
Running
Running
Disponibilidad de Modelos se maneja desde Firebase
Browse files- app.py +21 -21
- funciones.py +22 -15
app.py
CHANGED
@@ -53,27 +53,27 @@ async def genera_imagen(platillo: str = Form(...)):
|
|
53 |
else:
|
54 |
return StreamingResponse(content=resultado, media_type="image/png")
|
55 |
|
56 |
-
@app.post("/procesador-lotes/")
|
57 |
-
async def procesa_lote(platillo: str = Form(...)):
|
58 |
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
53 |
else:
|
54 |
return StreamingResponse(content=resultado, media_type="image/png")
|
55 |
|
56 |
+
# @app.post("/procesador-lotes/")
|
57 |
+
# async def procesa_lote(platillo: str = Form(...)):
|
58 |
|
59 |
+
# print("Servicio Secundario de Procesamiento de Lotes")
|
60 |
+
# seconds_available = herramientas.obtenSegundosDisponibles()
|
61 |
+
# #seconds_available = 0
|
62 |
+
# print(herramientas.imprimeTimeNow())
|
63 |
|
64 |
+
# if seconds_available > globales.work_cost:
|
65 |
+
# print("Usando GPU (capa gratuita)...")
|
66 |
+
# resultado = funciones.genera_platillo_gpu(platillo)
|
67 |
+
# if "Error" in resultado:
|
68 |
+
# return resultado
|
69 |
+
# else:
|
70 |
+
# return FileResponse(resultado, media_type="image/png", filename="imagen.png")
|
71 |
+
# else:
|
72 |
|
73 |
+
# print("Usando Inference...")
|
74 |
+
# resultado = funciones.genera_platillo_inference(platillo)
|
75 |
+
# print("El resultado de inference es: ", resultado)
|
76 |
+
# if type(resultado) is str:
|
77 |
+
# return resultado
|
78 |
+
# else:
|
79 |
+
# return StreamingResponse(content=resultado, media_type="image/png")
|
funciones.py
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
import io
|
|
|
2 |
import globales
|
3 |
-
import espacios
|
4 |
import random
|
5 |
import herramientas
|
6 |
import gradio_client
|
7 |
import conexion_firebase
|
8 |
from fastapi import HTTPException, status
|
9 |
from huggingface_hub import InferenceClient
|
10 |
-
|
11 |
|
12 |
servidor = globales.servidor
|
13 |
|
@@ -25,7 +25,7 @@ def genera_platillo_gpu(platillo):
|
|
25 |
if config.get("habilitado", False) # Usamos .get() para evitar KeyError si 'habilitado' no existe
|
26 |
]
|
27 |
|
28 |
-
print(f"
|
29 |
|
30 |
espacio_aleatorio_elegido = random.choice(espacios_habilitados)
|
31 |
configuracion_espacio = dict_espacios[espacio_aleatorio_elegido]
|
@@ -63,17 +63,26 @@ def genera_platillo_gpu(platillo):
|
|
63 |
)
|
64 |
|
65 |
def genera_platillo_inference(platillo):
|
66 |
-
|
67 |
|
68 |
-
modelo_actual = conexion_firebase.obtenDato('nowme', servidor, 'modelo_actual')
|
69 |
modelo = modelo_actual
|
70 |
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
76 |
|
|
|
|
|
|
|
77 |
#print("Los créditos restantes de hf-inference que tienes son: ", creditos_restantes_inference)
|
78 |
if creditos_restantes_inference > 0:
|
79 |
provedor_seleccionado = globales.proveedor
|
@@ -92,11 +101,11 @@ def genera_platillo_inference(platillo):
|
|
92 |
image = client.text_to_image(
|
93 |
prompt,
|
94 |
#negative_prompt="live animals",
|
95 |
-
model=
|
96 |
width=784, #786
|
97 |
height=560, #568
|
98 |
num_inference_steps=16
|
99 |
-
)
|
100 |
|
101 |
#Detenido momentaneamente por cambio a firebase.
|
102 |
herramientas.restaSegundosInference(globales.inference_cost)
|
@@ -105,15 +114,13 @@ def genera_platillo_inference(platillo):
|
|
105 |
print("Excepción: ", e)
|
106 |
if "Gateway Time-out" in str(e):
|
107 |
print("GATEWAY TIME-OUT 💀")
|
108 |
-
modelo=globales.inferencia_backup
|
109 |
#Escribe en txt el nuevo modelo.
|
110 |
-
herramientas.modificaModeloActual(modelo)
|
111 |
error_impreso = f"Error: {e}"
|
112 |
print(error_impreso)
|
113 |
-
time.sleep(18)
|
114 |
raise HTTPException(
|
115 |
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
116 |
-
#detail='detail'
|
117 |
)
|
118 |
|
119 |
img_io = io.BytesIO()
|
|
|
1 |
import io
|
2 |
+
import time
|
3 |
import globales
|
|
|
4 |
import random
|
5 |
import herramientas
|
6 |
import gradio_client
|
7 |
import conexion_firebase
|
8 |
from fastapi import HTTPException, status
|
9 |
from huggingface_hub import InferenceClient
|
10 |
+
|
11 |
|
12 |
servidor = globales.servidor
|
13 |
|
|
|
25 |
if config.get("habilitado", False) # Usamos .get() para evitar KeyError si 'habilitado' no existe
|
26 |
]
|
27 |
|
28 |
+
print(f"Espacios habilitados: {espacios_habilitados}")
|
29 |
|
30 |
espacio_aleatorio_elegido = random.choice(espacios_habilitados)
|
31 |
configuracion_espacio = dict_espacios[espacio_aleatorio_elegido]
|
|
|
63 |
)
|
64 |
|
65 |
def genera_platillo_inference(platillo):
|
|
|
66 |
|
67 |
+
modelo_actual = conexion_firebase.obtenDato('nowme', servidor, 'modelo_actual') #Forma actual
|
68 |
modelo = modelo_actual
|
69 |
|
70 |
+
dict_modelos = conexion_firebase.obtenDato('nowme', servidor, 'modelos')
|
71 |
+
|
72 |
+
modelos_habilitados = [
|
73 |
+
nombre for nombre, config in dict_modelos.items()
|
74 |
+
if config.get("habilitado", False) # Usamos .get() para evitar KeyError si 'habilitado' no existe
|
75 |
+
]
|
76 |
|
77 |
+
print(f"Modelos habilitados: {modelos_habilitados}")
|
78 |
+
|
79 |
+
modelo_aleatorio_elegido = random.choice(modelos_habilitados)
|
80 |
+
configuracion_modelo = dict_modelos[modelo_aleatorio_elegido]
|
81 |
+
print(f"La configuración completa para '{modelo_aleatorio_elegido}' es: {configuracion_modelo}")
|
82 |
|
83 |
+
|
84 |
+
creditos_restantes_inference = conexion_firebase.obtenDato('nowme', servidor, 'inferencias')
|
85 |
+
|
86 |
#print("Los créditos restantes de hf-inference que tienes son: ", creditos_restantes_inference)
|
87 |
if creditos_restantes_inference > 0:
|
88 |
provedor_seleccionado = globales.proveedor
|
|
|
101 |
image = client.text_to_image(
|
102 |
prompt,
|
103 |
#negative_prompt="live animals",
|
104 |
+
model=modelo_aleatorio_elegido['ruta'],
|
105 |
width=784, #786
|
106 |
height=560, #568
|
107 |
num_inference_steps=16
|
108 |
+
)
|
109 |
|
110 |
#Detenido momentaneamente por cambio a firebase.
|
111 |
herramientas.restaSegundosInference(globales.inference_cost)
|
|
|
114 |
print("Excepción: ", e)
|
115 |
if "Gateway Time-out" in str(e):
|
116 |
print("GATEWAY TIME-OUT 💀")
|
117 |
+
#modelo=globales.inferencia_backup #Con el nuevo paradigma ya no hay cambio de modelo.
|
118 |
#Escribe en txt el nuevo modelo.
|
119 |
+
#herramientas.modificaModeloActual(modelo)
|
120 |
error_impreso = f"Error: {e}"
|
121 |
print(error_impreso)
|
|
|
122 |
raise HTTPException(
|
123 |
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
|
124 |
)
|
125 |
|
126 |
img_io = io.BytesIO()
|