Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,12 +8,9 @@ class FashionPromptGenerator:
|
|
| 8 |
def __init__(self):
|
| 9 |
self.previous_prompts = set()
|
| 10 |
self.photo_real = PhotoReal()
|
| 11 |
-
|
| 12 |
-
# Asegurarse de que todos los atributos necesarios existan
|
| 13 |
self._ensure_attributes()
|
| 14 |
|
| 15 |
def _ensure_attributes(self):
|
| 16 |
-
"""Asegura que todos los atributos necesarios existan en photo_real"""
|
| 17 |
if not hasattr(self.photo_real, 'STOCKINGS'):
|
| 18 |
self.photo_real.STOCKINGS = "realistic sheer stockings with authentic fabric weave"
|
| 19 |
if not hasattr(self.photo_real, 'HEELS'):
|
|
@@ -27,13 +24,12 @@ class FashionPromptGenerator:
|
|
| 27 |
]
|
| 28 |
|
| 29 |
def generate_unique_prompts(self, subject_name, num_prompts=5):
|
| 30 |
-
"""Genera una lista de prompts 煤nicos."""
|
| 31 |
if not subject_name or subject_name.isspace():
|
| 32 |
subject_name = "a beautiful woman"
|
| 33 |
|
| 34 |
prompts = []
|
| 35 |
-
max_attempts = num_prompts * 10
|
| 36 |
attempts = 0
|
|
|
|
| 37 |
|
| 38 |
while len(prompts) < num_prompts and attempts < max_attempts:
|
| 39 |
prompt = self._build_fused_prompt(subject_name)
|
|
@@ -43,32 +39,26 @@ class FashionPromptGenerator:
|
|
| 43 |
prompts.append(prompt)
|
| 44 |
attempts += 1
|
| 45 |
|
| 46 |
-
# Si no se logran suficientes prompts 煤nicos, rellena con algunos aleatorios
|
| 47 |
while len(prompts) < num_prompts:
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
return prompts
|
| 52 |
|
| 53 |
def _build_fused_prompt(self, subject_name):
|
| 54 |
-
"""Construye un prompt fusionando los estilos photorealistic y voyeuristic."""
|
| 55 |
try:
|
| 56 |
-
# --- Elementos de Photorealistic ---
|
| 57 |
role = random.choice(self.photo_real.ROLES)
|
| 58 |
body = random.choice(self.photo_real.BODY)
|
| 59 |
skin = random.choice(self.photo_real.SKIN)
|
| 60 |
hair = random.choice(self.photo_real.HAIR)
|
| 61 |
expression = random.choice(self.photo_real.EXPRESSION)
|
| 62 |
sensual_pose = random.choice(self.photo_real.SENSUAL_POSES)
|
| 63 |
-
|
| 64 |
-
# --- Elementos de Voyeuristic ---
|
| 65 |
primary_color = random.choice(fashion_elements["colors"])
|
| 66 |
discovery_moment = random.choice(fashion_elements["discovery_moments"])
|
| 67 |
reveal_action = random.choice(fashion_elements["lingerie_reveal_actions"])
|
| 68 |
background = random.choice(fashion_elements["backgrounds"])
|
| 69 |
lighting = random.choice(fashion_elements["lighting"])
|
| 70 |
-
|
| 71 |
-
# --- Construcci贸n del Prompt ---
|
| 72 |
prompt = (
|
| 73 |
f"Photorealistic portrait of {subject_name} as a {role['role']}, "
|
| 74 |
f"captured from an extreme low angle, floor-level perspective, shooting upward. "
|
|
@@ -82,23 +72,23 @@ class FashionPromptGenerator:
|
|
| 82 |
f"Complemented by {self.photo_real.STOCKINGS} and {self.photo_real.HEELS}.\n\n"
|
| 83 |
f"**Scene & Atmosphere:**\n"
|
| 84 |
f"- **Setting:** {background} with {lighting}.\n"
|
| 85 |
-
f"- **Pose:** {sensual_pose['pose']} ({sensual_pose['view']} view)
|
| 86 |
f"- **Mood:** Intimate, sensual, and elegantly composed.\n\n"
|
| 87 |
f"**Technical Details:**\n"
|
| 88 |
f"- **Camera:** {self.photo_real.CAMERA}.\n"
|
| 89 |
-
f"- **Quality:** Ultra HD, professional retouching
|
| 90 |
-
f"The image captures a fleeting, intimate moment that feels both spontaneous and beautifully composed, emphasizing the sensual discovery of hidden lingerie through natural movement and expert framing. "
|
| 91 |
f"--ar 9:16 --v 6 --q 2 --style raw --stylize 100"
|
| 92 |
)
|
|
|
|
| 93 |
return prompt.strip()
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
return f"Photorealistic portrait of {subject_name} in an elegant setting
|
| 97 |
|
| 98 |
def clear_history(self):
|
| 99 |
-
"""Limpia el historial de prompts generados."""
|
| 100 |
self.previous_prompts.clear()
|
| 101 |
|
|
|
|
| 102 |
def create_gradio_interface():
|
| 103 |
generator = FashionPromptGenerator()
|
| 104 |
|
|
@@ -106,7 +96,6 @@ def create_gradio_interface():
|
|
| 106 |
|
| 107 |
gr.Markdown("""
|
| 108 |
# 馃幁 Advanced Fashion Prompt Generator
|
| 109 |
-
*Create photorealistic, discovery-focused prompts with a single, powerful style.*
|
| 110 |
""")
|
| 111 |
|
| 112 |
with gr.Row():
|
|
@@ -131,7 +120,6 @@ def create_gradio_interface():
|
|
| 131 |
gr.Markdown("### Negative Prompt")
|
| 132 |
negative_prompt_output = gr.Textbox(
|
| 133 |
value=negative_prompt_fusion,
|
| 134 |
-
label="",
|
| 135 |
lines=4,
|
| 136 |
interactive=False
|
| 137 |
)
|
|
@@ -140,68 +128,83 @@ def create_gradio_interface():
|
|
| 140 |
|
| 141 |
output_columns = []
|
| 142 |
output_prompts = []
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
#
|
|
|
|
| 146 |
for i in range(10):
|
| 147 |
-
with gr.Column(visible=(i < 5)) as col:
|
| 148 |
-
gr.Markdown(f"### 馃幆 Prompt {i+1}")
|
| 149 |
|
|
|
|
|
|
|
| 150 |
prompt_output = gr.Textbox(
|
| 151 |
-
label="",
|
| 152 |
lines=12,
|
| 153 |
interactive=False,
|
| 154 |
-
|
| 155 |
)
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
output_columns.append(col)
|
| 158 |
output_prompts.append(prompt_output)
|
| 159 |
|
|
|
|
| 160 |
def generate_and_display(celebrity_name, num_prompts):
|
| 161 |
-
|
| 162 |
-
prompts = generator.generate_unique_prompts(celebrity_name, num_prompts)
|
| 163 |
|
| 164 |
updates = []
|
| 165 |
for i in range(10):
|
| 166 |
if i < num_prompts:
|
| 167 |
-
# Mostrar columna y establecer valor
|
| 168 |
updates.append(gr.update(visible=True))
|
| 169 |
updates.append(gr.update(value=prompts[i]))
|
| 170 |
else:
|
| 171 |
-
# Ocultar columna y limpiar valor
|
| 172 |
updates.append(gr.update(visible=False))
|
| 173 |
updates.append(gr.update(value=""))
|
| 174 |
-
|
| 175 |
return updates
|
| 176 |
|
| 177 |
-
# Aplanar la lista de outputs para Gradio
|
| 178 |
flat_outputs = []
|
| 179 |
for i in range(10):
|
| 180 |
flat_outputs.append(output_columns[i])
|
| 181 |
flat_outputs.append(output_prompts[i])
|
| 182 |
|
| 183 |
generate_btn.click(
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
)
|
| 188 |
-
|
|
|
|
| 189 |
def clear_history_and_outputs():
|
| 190 |
generator.clear_history()
|
| 191 |
updates = []
|
| 192 |
for i in range(10):
|
| 193 |
-
updates.append(gr.update(visible=(i < 5)))
|
| 194 |
updates.append(gr.update(value=""))
|
| 195 |
return updates
|
| 196 |
|
| 197 |
clear_btn.click(
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
)
|
| 202 |
|
| 203 |
return demo
|
| 204 |
|
|
|
|
| 205 |
if __name__ == "__main__":
|
| 206 |
demo = create_gradio_interface()
|
| 207 |
demo.launch(
|
|
|
|
| 8 |
def __init__(self):
|
| 9 |
self.previous_prompts = set()
|
| 10 |
self.photo_real = PhotoReal()
|
|
|
|
|
|
|
| 11 |
self._ensure_attributes()
|
| 12 |
|
| 13 |
def _ensure_attributes(self):
|
|
|
|
| 14 |
if not hasattr(self.photo_real, 'STOCKINGS'):
|
| 15 |
self.photo_real.STOCKINGS = "realistic sheer stockings with authentic fabric weave"
|
| 16 |
if not hasattr(self.photo_real, 'HEELS'):
|
|
|
|
| 24 |
]
|
| 25 |
|
| 26 |
def generate_unique_prompts(self, subject_name, num_prompts=5):
|
|
|
|
| 27 |
if not subject_name or subject_name.isspace():
|
| 28 |
subject_name = "a beautiful woman"
|
| 29 |
|
| 30 |
prompts = []
|
|
|
|
| 31 |
attempts = 0
|
| 32 |
+
max_attempts = num_prompts * 10
|
| 33 |
|
| 34 |
while len(prompts) < num_prompts and attempts < max_attempts:
|
| 35 |
prompt = self._build_fused_prompt(subject_name)
|
|
|
|
| 39 |
prompts.append(prompt)
|
| 40 |
attempts += 1
|
| 41 |
|
|
|
|
| 42 |
while len(prompts) < num_prompts:
|
| 43 |
+
prompts.append(self._build_fused_prompt(subject_name))
|
| 44 |
+
|
|
|
|
| 45 |
return prompts
|
| 46 |
|
| 47 |
def _build_fused_prompt(self, subject_name):
|
|
|
|
| 48 |
try:
|
|
|
|
| 49 |
role = random.choice(self.photo_real.ROLES)
|
| 50 |
body = random.choice(self.photo_real.BODY)
|
| 51 |
skin = random.choice(self.photo_real.SKIN)
|
| 52 |
hair = random.choice(self.photo_real.HAIR)
|
| 53 |
expression = random.choice(self.photo_real.EXPRESSION)
|
| 54 |
sensual_pose = random.choice(self.photo_real.SENSUAL_POSES)
|
| 55 |
+
|
|
|
|
| 56 |
primary_color = random.choice(fashion_elements["colors"])
|
| 57 |
discovery_moment = random.choice(fashion_elements["discovery_moments"])
|
| 58 |
reveal_action = random.choice(fashion_elements["lingerie_reveal_actions"])
|
| 59 |
background = random.choice(fashion_elements["backgrounds"])
|
| 60 |
lighting = random.choice(fashion_elements["lighting"])
|
| 61 |
+
|
|
|
|
| 62 |
prompt = (
|
| 63 |
f"Photorealistic portrait of {subject_name} as a {role['role']}, "
|
| 64 |
f"captured from an extreme low angle, floor-level perspective, shooting upward. "
|
|
|
|
| 72 |
f"Complemented by {self.photo_real.STOCKINGS} and {self.photo_real.HEELS}.\n\n"
|
| 73 |
f"**Scene & Atmosphere:**\n"
|
| 74 |
f"- **Setting:** {background} with {lighting}.\n"
|
| 75 |
+
f"- **Pose:** {sensual_pose['pose']} ({sensual_pose['view']} view).\n"
|
| 76 |
f"- **Mood:** Intimate, sensual, and elegantly composed.\n\n"
|
| 77 |
f"**Technical Details:**\n"
|
| 78 |
f"- **Camera:** {self.photo_real.CAMERA}.\n"
|
| 79 |
+
f"- **Quality:** Ultra HD, professional retouching.\n\n"
|
|
|
|
| 80 |
f"--ar 9:16 --v 6 --q 2 --style raw --stylize 100"
|
| 81 |
)
|
| 82 |
+
|
| 83 |
return prompt.strip()
|
| 84 |
+
|
| 85 |
+
except Exception:
|
| 86 |
+
return f"Photorealistic portrait of {subject_name} in an elegant setting --ar 9:16 --v 6"
|
| 87 |
|
| 88 |
def clear_history(self):
|
|
|
|
| 89 |
self.previous_prompts.clear()
|
| 90 |
|
| 91 |
+
|
| 92 |
def create_gradio_interface():
|
| 93 |
generator = FashionPromptGenerator()
|
| 94 |
|
|
|
|
| 96 |
|
| 97 |
gr.Markdown("""
|
| 98 |
# 馃幁 Advanced Fashion Prompt Generator
|
|
|
|
| 99 |
""")
|
| 100 |
|
| 101 |
with gr.Row():
|
|
|
|
| 120 |
gr.Markdown("### Negative Prompt")
|
| 121 |
negative_prompt_output = gr.Textbox(
|
| 122 |
value=negative_prompt_fusion,
|
|
|
|
| 123 |
lines=4,
|
| 124 |
interactive=False
|
| 125 |
)
|
|
|
|
| 128 |
|
| 129 |
output_columns = []
|
| 130 |
output_prompts = []
|
| 131 |
+
|
| 132 |
+
# -------------------------
|
| 133 |
+
# PROMPTS + BOT脫N COPIAR
|
| 134 |
+
# -------------------------
|
| 135 |
for i in range(10):
|
| 136 |
+
with gr.Column(visible=(i < 5)) as col:
|
|
|
|
| 137 |
|
| 138 |
+
gr.Markdown(f"### 馃幆 Prompt {i+1}")
|
| 139 |
+
|
| 140 |
prompt_output = gr.Textbox(
|
| 141 |
+
label="",
|
| 142 |
lines=12,
|
| 143 |
interactive=False,
|
| 144 |
+
elem_id=f"prompt_box_{i}"
|
| 145 |
)
|
| 146 |
+
|
| 147 |
+
copy_btn = gr.Button("馃搵 Copiar", elem_id=f"copy_btn_{i}")
|
| 148 |
+
|
| 149 |
+
copy_btn.click(
|
| 150 |
+
None,
|
| 151 |
+
[],
|
| 152 |
+
[],
|
| 153 |
+
_js=f"""
|
| 154 |
+
() => {{
|
| 155 |
+
const text = document.querySelector('#prompt_box_{i} textarea').value;
|
| 156 |
+
navigator.clipboard.writeText(text);
|
| 157 |
+
alert('Prompt copiado 馃憤');
|
| 158 |
+
}}
|
| 159 |
+
"""
|
| 160 |
+
)
|
| 161 |
+
|
| 162 |
output_columns.append(col)
|
| 163 |
output_prompts.append(prompt_output)
|
| 164 |
|
| 165 |
+
# Generar prompts
|
| 166 |
def generate_and_display(celebrity_name, num_prompts):
|
| 167 |
+
prompts = generator.generate_unique_prompts(celebrity_name, int(num_prompts))
|
|
|
|
| 168 |
|
| 169 |
updates = []
|
| 170 |
for i in range(10):
|
| 171 |
if i < num_prompts:
|
|
|
|
| 172 |
updates.append(gr.update(visible=True))
|
| 173 |
updates.append(gr.update(value=prompts[i]))
|
| 174 |
else:
|
|
|
|
| 175 |
updates.append(gr.update(visible=False))
|
| 176 |
updates.append(gr.update(value=""))
|
|
|
|
| 177 |
return updates
|
| 178 |
|
|
|
|
| 179 |
flat_outputs = []
|
| 180 |
for i in range(10):
|
| 181 |
flat_outputs.append(output_columns[i])
|
| 182 |
flat_outputs.append(output_prompts[i])
|
| 183 |
|
| 184 |
generate_btn.click(
|
| 185 |
+
generate_and_display,
|
| 186 |
+
[celebrity_input, num_prompts_slider],
|
| 187 |
+
flat_outputs
|
| 188 |
)
|
| 189 |
+
|
| 190 |
+
# Clear
|
| 191 |
def clear_history_and_outputs():
|
| 192 |
generator.clear_history()
|
| 193 |
updates = []
|
| 194 |
for i in range(10):
|
| 195 |
+
updates.append(gr.update(visible=(i < 5)))
|
| 196 |
updates.append(gr.update(value=""))
|
| 197 |
return updates
|
| 198 |
|
| 199 |
clear_btn.click(
|
| 200 |
+
clear_history_and_outputs,
|
| 201 |
+
None,
|
| 202 |
+
flat_outputs
|
| 203 |
)
|
| 204 |
|
| 205 |
return demo
|
| 206 |
|
| 207 |
+
|
| 208 |
if __name__ == "__main__":
|
| 209 |
demo = create_gradio_interface()
|
| 210 |
demo.launch(
|