GoGma commited on
Commit
e002fe9
·
verified ·
1 Parent(s): 47c57f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -29
app.py CHANGED
@@ -3,78 +3,96 @@ import os
3
  import random
4
  from datetime import datetime
5
  from huggingface_hub import InferenceClient
6
-
7
  # Configuración
8
  OUTPUT_DIR = "generated_images"
9
  os.makedirs(OUTPUT_DIR, exist_ok=True)
10
- client = InferenceClient()
11
-
12
- # Identidad de Sofía Rivera
 
 
 
13
  SOFIA_CORE = (
14
  "sofia rivera, a beautiful 25-year-old latina cuban-american woman, "
15
  "long dark wavy hair, mesmerizing hazel eyes, toned athletic fitness body, "
16
- "natural radiant skin, miami influencer aesthetic"
17
  )
18
-
19
  CATEGORIES = {
20
  "Fitness - Gym": {
21
- "prompt": f"full body mirror selfie of {SOFIA_CORE}, wearing black sports bra and leggings, modern miami gym background, 8k, photorealistic",
22
  "desc": "### 🏋️ Pilar Fitness\nIdeal para Lunes, Miércoles y Viernes."
23
  },
24
  "Lifestyle - Beach": {
25
- "prompt": f"candid photo of {SOFIA_CORE}, tropical outfit, miami beach sunset, cinematic lighting, vibrant colors",
26
  "desc": "### 🌴 Pilar Lifestyle\nIdeal para Martes y Jueves."
27
  },
28
  "Lifestyle - Luxury": {
29
- "prompt": f"portrait of {SOFIA_CORE}, luxury miami apartment, morning light, natural makeup, authentic vibe",
30
  "desc": "### ☕ Pilar Personal\nIdeal para Sábados."
31
  },
32
  "Premium - Elegant": {
33
- "prompt": f"tasteful photography of {SOFIA_CORE}, elegant black lace, soft moody lighting, professional aesthetic",
34
  "desc": "### 💎 Pilar Premium\nIdeal para Domingos."
35
  }
36
  }
37
-
38
  def generate(category_name, tweak, model_id, steps, cfg, seed):
39
  try:
 
 
 
40
  cat = CATEGORIES[category_name]
41
  prompt = f"{cat['prompt']}, {tweak}" if tweak else cat['prompt']
42
- seed = random.randint(0, 2**32 - 1) if seed == -1 else int(seed)
 
 
43
 
44
  image = client.text_to_image(
45
  prompt=prompt,
46
  model=model_id,
47
  num_inference_steps=int(steps),
48
  guidance_scale=float(cfg),
49
- seed=seed
50
  )
51
- return image, f"✅ Generada: {category_name} | Seed: {seed}"
52
  except Exception as e:
53
  return None, f"❌ Error: {str(e)}"
54
-
55
  def create_interface():
56
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
57
  gr.Markdown("# 🌴 Sofia Rivera AI Workspace")
58
- with gr.Tab("🎨 Generador"):
 
 
59
  with gr.Row():
60
  with gr.Column(scale=1):
61
- cat_drop = gr.Dropdown(choices=list(CATEGORIES.keys()), label="Pilar", value="Fitness - Gym")
62
  cat_info = gr.Markdown(CATEGORIES["Fitness - Gym"]["desc"])
63
- tweak = gr.Textbox(label="Detalles extra", placeholder="ej: wearing sunglasses...")
64
- with gr.Accordion("Avanzado", open=False):
65
- model = gr.Dropdown(choices=["black-forest-labs/FLUX.1-dev", "black-forest-labs/FLUX.1-schnell"], label="Modelo", value="black-forest-labs/FLUX.1-dev")
66
- steps = gr.Slider(1, 50, 28, label="Pasos")
67
- cfg = gr.Slider(1, 20, 7, label="Realismo")
68
- seed = gr.Number(-1, label="Seed")
69
- btn = gr.Button("🚀 Generar", variant="primary")
 
 
 
 
 
 
 
 
70
  with gr.Column(scale=2):
71
- out_img = gr.Image(label="Sofía Rivera")
72
- out_log = gr.Textbox(label="Estado", interactive=False)
73
 
74
  cat_drop.change(lambda x: CATEGORIES[x]["desc"], inputs=[cat_drop], outputs=[cat_info])
75
  btn.click(generate, [cat_drop, tweak, model, steps, cfg, seed], [out_img, out_log])
 
76
  return demo
77
-
78
- if __name__ == "__main__":
79
- create_interface().launch()
80
 
 
 
 
3
  import random
4
  from datetime import datetime
5
  from huggingface_hub import InferenceClient
6
+
7
  # Configuración
8
  OUTPUT_DIR = "generated_images"
9
  os.makedirs(OUTPUT_DIR, exist_ok=True)
10
+
11
+ # Usamos el Token de los Secrets del Space
12
+ HF_TOKEN = os.getenv("HUGGINGFACE_TOKEN") or os.getenv("HF_TOKEN")
13
+ client = InferenceClient(token=HF_TOKEN)
14
+
15
+ # Identidad de Sofía Rivera (Optimizada para realismo)
16
  SOFIA_CORE = (
17
  "sofia rivera, a beautiful 25-year-old latina cuban-american woman, "
18
  "long dark wavy hair, mesmerizing hazel eyes, toned athletic fitness body, "
19
+ "natural radiant skin, miami influencer aesthetic, hyperrealistic, 8k"
20
  )
21
+
22
  CATEGORIES = {
23
  "Fitness - Gym": {
24
+ "prompt": f"full body mirror selfie of {SOFIA_CORE}, wearing black sports bra and leggings, modern miami gym background, cinematic lighting",
25
  "desc": "### 🏋️ Pilar Fitness\nIdeal para Lunes, Miércoles y Viernes."
26
  },
27
  "Lifestyle - Beach": {
28
+ "prompt": f"candid photo of {SOFIA_CORE}, tropical outfit, miami beach sunset, vibrant colors, bokeh background",
29
  "desc": "### 🌴 Pilar Lifestyle\nIdeal para Martes y Jueves."
30
  },
31
  "Lifestyle - Luxury": {
32
+ "prompt": f"portrait of {SOFIA_CORE}, luxury miami apartment balcony, morning light, natural makeup, authentic vibe",
33
  "desc": "### ☕ Pilar Personal\nIdeal para Sábados."
34
  },
35
  "Premium - Elegant": {
36
+ "prompt": f"tasteful photography of {SOFIA_CORE}, elegant black lace outfit, soft moody lighting, professional studio aesthetic",
37
  "desc": "### 💎 Pilar Premium\nIdeal para Domingos."
38
  }
39
  }
40
+
41
  def generate(category_name, tweak, model_id, steps, cfg, seed):
42
  try:
43
+ if not HF_TOKEN:
44
+ return None, "❌ Error: No se encontró el HUGGINGFACE_TOKEN en los Secrets del Space."
45
+
46
  cat = CATEGORIES[category_name]
47
  prompt = f"{cat['prompt']}, {tweak}" if tweak else cat['prompt']
48
+
49
+ # Gestión de la Seed
50
+ final_seed = random.randint(0, 2**32 - 1) if seed == -1 else int(seed)
51
 
52
  image = client.text_to_image(
53
  prompt=prompt,
54
  model=model_id,
55
  num_inference_steps=int(steps),
56
  guidance_scale=float(cfg),
57
+ seed=final_seed
58
  )
59
+ return image, f"✅ Generada con {model_id} | Seed: {final_seed}"
60
  except Exception as e:
61
  return None, f"❌ Error: {str(e)}"
62
+
63
  def create_interface():
64
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
65
  gr.Markdown("# 🌴 Sofia Rivera AI Workspace")
66
+ gr.Markdown("Generador de contenido oficial para la agencia de Sofía.")
67
+
68
+ with gr.Tab("🎨 Generador de Imágenes"):
69
  with gr.Row():
70
  with gr.Column(scale=1):
71
+ cat_drop = gr.Dropdown(choices=list(CATEGORIES.keys()), label="Selecciona el Pilar de Contenido", value="Fitness - Gym")
72
  cat_info = gr.Markdown(CATEGORIES["Fitness - Gym"]["desc"])
73
+ tweak = gr.Textbox(label="Detalles extra (opcional)", placeholder="ej: holding a coffee, sunset, smiling...")
74
+
75
+ with gr.Accordion("Ajustes Técnicos (Avanzado)", open=True):
76
+ # CAMBIO CLAVE: 'schnell' es el modelo gratuito y r��pido
77
+ model = gr.Dropdown(
78
+ choices=["black-forest-labs/FLUX.1-schnell", "black-forest-labs/FLUX.1-dev"],
79
+ label="Modelo (Schnell = Gratis)",
80
+ value="black-forest-labs/FLUX.1-schnell"
81
+ )
82
+ steps = gr.Slider(1, 12, 4, label="Pasos (Schnell funciona mejor con 4-8)")
83
+ cfg = gr.Slider(1, 20, 3.5, label="Guidance Scale")
84
+ seed = gr.Number(-1, label="Seed (-1 para aleatorio)")
85
+
86
+ btn = gr.Button("🚀 Generar Imagen de Sofía", variant="primary")
87
+
88
  with gr.Column(scale=2):
89
+ out_img = gr.Image(label="Vista previa de Sofía")
90
+ out_log = gr.Textbox(label="Log de Estado", interactive=False)
91
 
92
  cat_drop.change(lambda x: CATEGORIES[x]["desc"], inputs=[cat_drop], outputs=[cat_info])
93
  btn.click(generate, [cat_drop, tweak, model, steps, cfg, seed], [out_img, out_log])
94
+
95
  return demo
 
 
 
96
 
97
+ if __name__ == "__main__":
98
+ create_interface().launch()