Spaces:
Running
Running
Manejo de errores
Browse files- app.py +12 -3
- archivos/last_timestamp.txt +1 -1
- archivos/seconds_available.txt +1 -1
- funciones.py +10 -7
- globales.py +2 -0
- herramientas.py +2 -2
app.py
CHANGED
@@ -22,12 +22,21 @@ async def genera_imagen(platillo: str = Form(...)):
|
|
22 |
seconds_available = herramientas.obtenSegundosDisponibles()
|
23 |
print("Los segundos disponibles obtenidos son: ", seconds_available)
|
24 |
|
25 |
-
|
26 |
if seconds_available > globales.work_cost:
|
27 |
print("GPU...")
|
28 |
resultado = funciones.genera_platillo_gpu(platillo)
|
29 |
-
|
|
|
|
|
|
|
30 |
else:
|
31 |
print("Inference...")
|
32 |
resultado = funciones.genera_platillo_inference(platillo)
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
seconds_available = herramientas.obtenSegundosDisponibles()
|
23 |
print("Los segundos disponibles obtenidos son: ", seconds_available)
|
24 |
|
|
|
25 |
if seconds_available > globales.work_cost:
|
26 |
print("GPU...")
|
27 |
resultado = funciones.genera_platillo_gpu(platillo)
|
28 |
+
if "Error" in resultado:
|
29 |
+
return resultado
|
30 |
+
else:
|
31 |
+
return FileResponse(resultado, media_type="image/png", filename="imagen.png")
|
32 |
else:
|
33 |
print("Inference...")
|
34 |
resultado = funciones.genera_platillo_inference(platillo)
|
35 |
+
print("El resultado de inference es: ", resultado)
|
36 |
+
print("Y su type es: ", type(resultado))
|
37 |
+
if type(resultado) is str:
|
38 |
+
return '{"Error":"500"}'
|
39 |
+
else:
|
40 |
+
return StreamingResponse(content=resultado, media_type="image/png")
|
41 |
+
|
42 |
+
|
archivos/last_timestamp.txt
CHANGED
@@ -1 +1 @@
|
|
1 |
-
|
|
|
1 |
+
1744734269
|
archivos/seconds_available.txt
CHANGED
@@ -1 +1 @@
|
|
1 |
-
|
|
|
1 |
+
288
|
funciones.py
CHANGED
@@ -35,14 +35,15 @@ def genera_platillo_gpu(platillo):
|
|
35 |
#Cuando es GPU, debe de restar segundos disponibles de HF
|
36 |
herramientas.restaSegundosGPU(globales.work_cost)
|
37 |
|
38 |
-
print("
|
39 |
-
time.sleep(18)
|
40 |
|
41 |
return result[0]
|
42 |
|
43 |
except Exception as e:
|
44 |
print("Excepción es: ", e)
|
45 |
-
return "default.png"
|
|
|
|
|
46 |
|
47 |
|
48 |
def genera_platillo_inference(platillo):
|
@@ -74,7 +75,9 @@ def genera_platillo_inference(platillo):
|
|
74 |
|
75 |
except Exception as e:
|
76 |
print("Excepción es: ", e)
|
77 |
-
with open("default.png", "rb") as default_image_file:
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
|
35 |
#Cuando es GPU, debe de restar segundos disponibles de HF
|
36 |
herramientas.restaSegundosGPU(globales.work_cost)
|
37 |
|
38 |
+
print("Lo que estoy regresando es result[0] o sea: ", result[0])
|
|
|
39 |
|
40 |
return result[0]
|
41 |
|
42 |
except Exception as e:
|
43 |
print("Excepción es: ", e)
|
44 |
+
# return "default.png"
|
45 |
+
return '{"Error":"500"}'
|
46 |
+
return "Hola, error gpu..."
|
47 |
|
48 |
|
49 |
def genera_platillo_inference(platillo):
|
|
|
75 |
|
76 |
except Exception as e:
|
77 |
print("Excepción es: ", e)
|
78 |
+
# with open("default.png", "rb") as default_image_file:
|
79 |
+
# img_io_default = io.BytesIO(default_image_file.read())
|
80 |
+
# img_io_default.seek(0)
|
81 |
+
# return img_io_default
|
82 |
+
return '{"Error":"500"}'
|
83 |
+
return "Hola error inference..."
|
globales.py
CHANGED
@@ -10,3 +10,5 @@ inferencia = "black-forest-labs/FLUX.1-dev"
|
|
10 |
proveedor = "hf-inference"
|
11 |
|
12 |
work_cost = 12
|
|
|
|
|
|
10 |
proveedor = "hf-inference"
|
11 |
|
12 |
work_cost = 12
|
13 |
+
|
14 |
+
quota = 300
|
herramientas.py
CHANGED
@@ -95,8 +95,8 @@ def renuevaSegundosDisponibles():
|
|
95 |
# Guardar el nuevo número en el archivo
|
96 |
try:
|
97 |
with open(archivo_ruta, 'w') as archivo:
|
98 |
-
archivo.write(str(
|
99 |
-
print(f"Se renovaron los
|
100 |
renuevaTimestampActual()
|
101 |
except Exception as e:
|
102 |
print(f"Error al escribir en el archivo '{archivo_ruta}': {e}")
|
|
|
95 |
# Guardar el nuevo número en el archivo
|
96 |
try:
|
97 |
with open(archivo_ruta, 'w') as archivo:
|
98 |
+
archivo.write(str(globales.quota))
|
99 |
+
print(f"Se renovaron los {globales.quota} segundos disponibles.")
|
100 |
renuevaTimestampActual()
|
101 |
except Exception as e:
|
102 |
print(f"Error al escribir en el archivo '{archivo_ruta}': {e}")
|