Spaces:
Sleeping
Sleeping
Update generation.py
Browse files- generation.py +9 -11
generation.py
CHANGED
|
@@ -4,31 +4,29 @@ from datetime import datetime
|
|
| 4 |
from typing import Optional
|
| 5 |
from huggingface_hub import InferenceClient
|
| 6 |
|
| 7 |
-
# Directorio donde se guardan las imágenes generadas
|
| 8 |
OUTPUT_DIR = "generated_images"
|
| 9 |
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
# Si tienes un Token de HF en tus Secrets, lo detectará automáticamente
|
| 13 |
client = InferenceClient()
|
| 14 |
|
| 15 |
def generate_image_from_prompt(
|
| 16 |
prompt: str,
|
| 17 |
-
negative_prompt: str = "",
|
| 18 |
-
model_name: str = "
|
| 19 |
seed: Optional[int] = None,
|
| 20 |
) -> tuple[Optional[str], str]:
|
| 21 |
try:
|
| 22 |
if seed is None:
|
| 23 |
seed = random.randint(0, 2_147_483_647)
|
| 24 |
|
| 25 |
-
#
|
| 26 |
image = client.text_to_image(
|
| 27 |
prompt=prompt,
|
| 28 |
model=model_name,
|
| 29 |
-
|
| 30 |
-
num_inference_steps=
|
| 31 |
-
|
| 32 |
)
|
| 33 |
|
| 34 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
@@ -37,9 +35,9 @@ def generate_image_from_prompt(
|
|
| 37 |
|
| 38 |
image.save(file_path)
|
| 39 |
|
| 40 |
-
status = f"✅ ¡Sofía
|
| 41 |
return file_path, status
|
| 42 |
|
| 43 |
except Exception as e:
|
| 44 |
-
error_msg = f"❌ Error
|
| 45 |
return None, error_msg
|
|
|
|
| 4 |
from typing import Optional
|
| 5 |
from huggingface_hub import InferenceClient
|
| 6 |
|
|
|
|
| 7 |
OUTPUT_DIR = "generated_images"
|
| 8 |
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
| 9 |
|
| 10 |
+
# Usaremos un modelo de la comunidad que suele ser gratuito
|
|
|
|
| 11 |
client = InferenceClient()
|
| 12 |
|
| 13 |
def generate_image_from_prompt(
|
| 14 |
prompt: str,
|
| 15 |
+
negative_prompt: str = "blurry, bad quality, distorted, ugly",
|
| 16 |
+
model_name: str = "SG161222/RealVisXL_V4.0_Lightning", # Modelo experto en realismo GRATIS
|
| 17 |
seed: Optional[int] = None,
|
| 18 |
) -> tuple[Optional[str], str]:
|
| 19 |
try:
|
| 20 |
if seed is None:
|
| 21 |
seed = random.randint(0, 2_147_483_647)
|
| 22 |
|
| 23 |
+
# Este modelo funciona de maravilla con InferenceClient
|
| 24 |
image = client.text_to_image(
|
| 25 |
prompt=prompt,
|
| 26 |
model=model_name,
|
| 27 |
+
negative_prompt=negative_prompt,
|
| 28 |
+
num_inference_steps=8, # SDXL Lightning es muy rápido
|
| 29 |
+
guidance_scale=1.5,
|
| 30 |
)
|
| 31 |
|
| 32 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
|
| 35 |
|
| 36 |
image.save(file_path)
|
| 37 |
|
| 38 |
+
status = f"✅ ¡Sofía generada con éxito!\nModelo: RealVisXL (Gratis)\nSeed: {seed}"
|
| 39 |
return file_path, status
|
| 40 |
|
| 41 |
except Exception as e:
|
| 42 |
+
error_msg = f"❌ Error: {str(e)}"
|
| 43 |
return None, error_msg
|