Optimización de estimación de cuota GPU - timeout 30s y estimación precisa
Browse files
app.py
CHANGED
@@ -22,6 +22,10 @@ print("🚀 Iniciando NTIA Space con ZeroGPU H200...")
|
|
22 |
print(f"📁 Directorio actual: {os.getcwd()}")
|
23 |
print(f"🐍 Python version: {os.sys.version}")
|
24 |
|
|
|
|
|
|
|
|
|
25 |
# Optimización para ZeroGPU H200
|
26 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
27 |
print(f"🖥️ Dispositivo detectado: {device}")
|
@@ -731,9 +735,9 @@ def generate_text(prompt, model_name, max_length=100):
|
|
731 |
except Exception as e:
|
732 |
return f"Error generando texto: {str(e)}"
|
733 |
|
734 |
-
@spaces.GPU #
|
735 |
def generate_image(prompt, model_name, negative_prompt="", seed=0, width=1024, height=1024, guidance_scale=7.5, num_inference_steps=20):
|
736 |
-
"""Generar imagen optimizada para H200"""
|
737 |
try:
|
738 |
print(f"\n🎨 Iniciando generación de imagen con H200...")
|
739 |
print(f"📝 Prompt: {prompt}")
|
@@ -744,6 +748,19 @@ def generate_image(prompt, model_name, negative_prompt="", seed=0, width=1024, h
|
|
744 |
print(f"📐 Dimensiones: {width}x{height}")
|
745 |
print(f"🎯 Guidance scale: {guidance_scale}")
|
746 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
747 |
start_time = time.time()
|
748 |
|
749 |
# Convertir parámetros a tipos correctos
|
|
|
22 |
print(f"📁 Directorio actual: {os.getcwd()}")
|
23 |
print(f"🐍 Python version: {os.sys.version}")
|
24 |
|
25 |
+
# Configuración específica para optimizar estimación de cuota
|
26 |
+
os.environ["SPACES_GPU_TIMEOUT"] = "30" # Máximo 30 segundos por request
|
27 |
+
os.environ["SPACES_GPU_MEMORY"] = "8" # Máximo 8GB de memoria GPU
|
28 |
+
|
29 |
# Optimización para ZeroGPU H200
|
30 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
31 |
print(f"🖥️ Dispositivo detectado: {device}")
|
|
|
735 |
except Exception as e:
|
736 |
return f"Error generando texto: {str(e)}"
|
737 |
|
738 |
+
@spaces.GPU(compute_unit="gpu.t4.micro", timeout=30) # Estimación más precisa: máximo 30 segundos
|
739 |
def generate_image(prompt, model_name, negative_prompt="", seed=0, width=1024, height=1024, guidance_scale=7.5, num_inference_steps=20):
|
740 |
+
"""Generar imagen optimizada para H200 con estimación precisa de cuota"""
|
741 |
try:
|
742 |
print(f"\n🎨 Iniciando generación de imagen con H200...")
|
743 |
print(f"📝 Prompt: {prompt}")
|
|
|
748 |
print(f"📐 Dimensiones: {width}x{height}")
|
749 |
print(f"🎯 Guidance scale: {guidance_scale}")
|
750 |
|
751 |
+
# Estimación precisa de tiempo basada en parámetros
|
752 |
+
estimated_time = 5 # Base de 5 segundos
|
753 |
+
if "turbo" in model_name.lower():
|
754 |
+
estimated_time = 2 # Modelos turbo son muy rápidos
|
755 |
+
elif "ldm-text2im" in model_name.lower():
|
756 |
+
estimated_time = 8 # LDM es más lento
|
757 |
+
elif num_inference_steps > 20:
|
758 |
+
estimated_time += (num_inference_steps - 20) * 0.2 # 0.2 segundos por paso adicional
|
759 |
+
elif width > 512 or height > 512:
|
760 |
+
estimated_time += 2 # Resoluciones grandes toman más tiempo
|
761 |
+
|
762 |
+
print(f"⏱️ Tiempo estimado: {estimated_time:.1f} segundos")
|
763 |
+
|
764 |
start_time = time.time()
|
765 |
|
766 |
# Convertir parámetros a tipos correctos
|