Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ from io import BytesIO
|
|
| 6 |
import concurrent.futures
|
| 7 |
import threading
|
| 8 |
import os
|
| 9 |
-
from openai import OpenAI
|
| 10 |
|
| 11 |
# ============================================
|
| 12 |
# CONFIGURACIÓN SAMBANOVA
|
|
@@ -75,11 +75,13 @@ def generate_single_reve_image(prompt: str, api_key: str, model: str, index: int
|
|
| 75 |
|
| 76 |
resp = requests.post(url, json=payload, headers=headers, timeout=60)
|
| 77 |
if resp.status_code != 200:
|
|
|
|
| 78 |
return
|
| 79 |
|
| 80 |
data = resp.json()
|
| 81 |
img_url = data.get("image")
|
| 82 |
if not img_url:
|
|
|
|
| 83 |
return
|
| 84 |
|
| 85 |
img_data = requests.get(img_url, timeout=30).content
|
|
@@ -90,8 +92,10 @@ def generate_single_reve_image(prompt: str, api_key: str, model: str, index: int
|
|
| 90 |
with lock:
|
| 91 |
results_list.append(temp_path)
|
| 92 |
|
|
|
|
|
|
|
| 93 |
except Exception as e:
|
| 94 |
-
print(f"Error
|
| 95 |
|
| 96 |
def reve_generate_multiple(prompt: str, api_key: str, model: str, num_images: int):
|
| 97 |
if not api_key.strip():
|
|
@@ -104,19 +108,22 @@ def reve_generate_multiple(prompt: str, api_key: str, model: str, num_images: in
|
|
| 104 |
results = []
|
| 105 |
lock = threading.Lock()
|
| 106 |
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
if results:
|
| 117 |
return results, f"✅ {len(results)} imágenes generadas con REVE CREATE"
|
| 118 |
else:
|
| 119 |
-
return None, "❌
|
| 120 |
|
| 121 |
# ============================================
|
| 122 |
# CHATBOT VOYEUR CON SAMBANOVA (INTELIGENTE)
|
|
@@ -230,26 +237,19 @@ def generate_random_voyeur_prompts(num: int = 5):
|
|
| 230 |
return prompts
|
| 231 |
|
| 232 |
# ============================================
|
| 233 |
-
# TEMA OSCURO
|
| 234 |
# ============================================
|
| 235 |
|
| 236 |
-
dark_theme = gr.themes.Soft(
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
font_mono=["IBM Plex Mono", "monospace"]
|
| 241 |
-
).set(
|
| 242 |
-
background_fill_primary="*neutral_900",
|
| 243 |
-
background_fill_secondary="*neutral_800",
|
| 244 |
-
block_background_fill="*neutral_800",
|
| 245 |
-
block_border_width="1px",
|
| 246 |
-
block_border_color="*neutral_600",
|
| 247 |
block_title_text_color="white",
|
| 248 |
block_label_text_color="white",
|
| 249 |
-
block_label_background_fill="
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
button_primary_background_fill="
|
| 253 |
button_primary_text_color="white",
|
| 254 |
)
|
| 255 |
|
|
@@ -266,7 +266,7 @@ with gr.Blocks(title="🦇 BATUTO CREATE IA + SambaNova", theme=dark_theme) as a
|
|
| 266 |
gr.Markdown("#### El más avanzado: prompts voyeur generados con Llama 3.1 en SambaNova")
|
| 267 |
gr.Markdown("Habla en español o inglés • Prompts ultra detallados y artísticos")
|
| 268 |
|
| 269 |
-
chatbot = gr.Chatbot(height=600)
|
| 270 |
msg = gr.Textbox(
|
| 271 |
placeholder="Ej: 'mujer en dormitorio de lujo cambiándose', 'secretaria inclinándose en oficina', 'modelo en probador'...",
|
| 272 |
label="Describe la escena",
|
|
@@ -343,6 +343,6 @@ if __name__ == "__main__":
|
|
| 343 |
app.launch(
|
| 344 |
server_name="0.0.0.0",
|
| 345 |
server_port=7860,
|
| 346 |
-
share=
|
| 347 |
show_error=True
|
| 348 |
)
|
|
|
|
| 6 |
import concurrent.futures
|
| 7 |
import threading
|
| 8 |
import os
|
| 9 |
+
from openai import OpenAI
|
| 10 |
|
| 11 |
# ============================================
|
| 12 |
# CONFIGURACIÓN SAMBANOVA
|
|
|
|
| 75 |
|
| 76 |
resp = requests.post(url, json=payload, headers=headers, timeout=60)
|
| 77 |
if resp.status_code != 200:
|
| 78 |
+
print(f"Error {resp.status_code} al generar imagen {index+1}: {resp.text}")
|
| 79 |
return
|
| 80 |
|
| 81 |
data = resp.json()
|
| 82 |
img_url = data.get("image")
|
| 83 |
if not img_url:
|
| 84 |
+
print(f"No se encontró URL de imagen en la respuesta para la imagen {index+1}")
|
| 85 |
return
|
| 86 |
|
| 87 |
img_data = requests.get(img_url, timeout=30).content
|
|
|
|
| 92 |
with lock:
|
| 93 |
results_list.append(temp_path)
|
| 94 |
|
| 95 |
+
except requests.exceptions.RequestException as e:
|
| 96 |
+
print(f"Error de conexión al generar imagen {index+1}: {e}")
|
| 97 |
except Exception as e:
|
| 98 |
+
print(f"Error inesperado al generar imagen {index+1}: {e}")
|
| 99 |
|
| 100 |
def reve_generate_multiple(prompt: str, api_key: str, model: str, num_images: int):
|
| 101 |
if not api_key.strip():
|
|
|
|
| 108 |
results = []
|
| 109 |
lock = threading.Lock()
|
| 110 |
|
| 111 |
+
try:
|
| 112 |
+
with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor:
|
| 113 |
+
futures = [
|
| 114 |
+
executor.submit(
|
| 115 |
+
generate_single_reve_image, prompt, api_key, model, i, results, lock
|
| 116 |
+
)
|
| 117 |
+
for i in range(num_images)
|
| 118 |
+
]
|
| 119 |
+
concurrent.futures.wait(futures)
|
| 120 |
+
except Exception as e:
|
| 121 |
+
return None, f"❌ Error al generar imágenes: {str(e)}"
|
| 122 |
|
| 123 |
if results:
|
| 124 |
return results, f"✅ {len(results)} imágenes generadas con REVE CREATE"
|
| 125 |
else:
|
| 126 |
+
return None, "❌ No se generaron imágenes. Verifica tu conexión a internet y la API Key de REVE CREATE."
|
| 127 |
|
| 128 |
# ============================================
|
| 129 |
# CHATBOT VOYEUR CON SAMBANOVA (INTELIGENTE)
|
|
|
|
| 237 |
return prompts
|
| 238 |
|
| 239 |
# ============================================
|
| 240 |
+
# TEMA OSCURO MÍNIMO PARA GRADIO
|
| 241 |
# ============================================
|
| 242 |
|
| 243 |
+
dark_theme = gr.themes.Soft().set(
|
| 244 |
+
background_fill_primary_dark="#111111",
|
| 245 |
+
background_fill_secondary="#1e1e1e",
|
| 246 |
+
block_background_fill="#1e1e1e",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 247 |
block_title_text_color="white",
|
| 248 |
block_label_text_color="white",
|
| 249 |
+
block_label_background_fill="#2d2d2d",
|
| 250 |
+
text_color="white",
|
| 251 |
+
input_background_fill="#2d2d2d",
|
| 252 |
+
button_primary_background_fill="#4a4a4a",
|
| 253 |
button_primary_text_color="white",
|
| 254 |
)
|
| 255 |
|
|
|
|
| 266 |
gr.Markdown("#### El más avanzado: prompts voyeur generados con Llama 3.1 en SambaNova")
|
| 267 |
gr.Markdown("Habla en español o inglés • Prompts ultra detallados y artísticos")
|
| 268 |
|
| 269 |
+
chatbot = gr.Chatbot(height=600, type="messages")
|
| 270 |
msg = gr.Textbox(
|
| 271 |
placeholder="Ej: 'mujer en dormitorio de lujo cambiándose', 'secretaria inclinándose en oficina', 'modelo en probador'...",
|
| 272 |
label="Describe la escena",
|
|
|
|
| 343 |
app.launch(
|
| 344 |
server_name="0.0.0.0",
|
| 345 |
server_port=7860,
|
| 346 |
+
share=False, # Cambiado a False ya que no es compatible en Hugging Face Spaces
|
| 347 |
show_error=True
|
| 348 |
)
|