import random import gradio as gr from data import fashion_elements, PhotoReal negative_prompt_fusion = "blurry, deformed, ugly, mutilated, disfigured, extra limbs, extra fingers, poorly drawn hands, poorly drawn feet, mutated hands, mutation, deformed, bad anatomy, bad proportions, extra arms, extra legs, fused fingers, too many fingers, long neck, username, watermark, signature, overexposed, underexposed, bad lighting, distorted face, low quality, artifacts" class FashionPromptGenerator: def __init__(self): self.previous_prompts = set() self.photo_real = PhotoReal() self._ensure_attributes() def _ensure_attributes(self): if not hasattr(self.photo_real, 'STOCKINGS'): self.photo_real.STOCKINGS = "realistic sheer stockings with authentic fabric weave" if not hasattr(self.photo_real, 'HEELS'): self.photo_real.HEELS = "classic black leather heels" if not hasattr(self.photo_real, 'CAMERA'): self.photo_real.CAMERA = "photorealistic 8K vertical capture 9:16 aspect" if not hasattr(self.photo_real, 'SENSUAL_POSES'): self.photo_real.SENSUAL_POSES = [ {"pose": "standing confidently", "view": "frontal"}, {"pose": "leaning forward", "view": "frontal"} ] def generate_unique_prompts(self, subject_name, num_prompts=5): if not subject_name or subject_name.isspace(): subject_name = "a beautiful woman" prompts = [] attempts = 0 max_attempts = num_prompts * 10 while len(prompts) < num_prompts and attempts < max_attempts: prompt = self._build_fused_prompt(subject_name) prompt_hash = hash(prompt) if prompt_hash not in self.previous_prompts: self.previous_prompts.add(prompt_hash) prompts.append(prompt) attempts += 1 while len(prompts) < num_prompts: prompts.append(self._build_fused_prompt(subject_name)) return prompts def _build_fused_prompt(self, subject_name): try: role = random.choice(self.photo_real.ROLES) body = random.choice(self.photo_real.BODY) skin = random.choice(self.photo_real.SKIN) hair = random.choice(self.photo_real.HAIR) expression = random.choice(self.photo_real.EXPRESSION) sensual_pose = random.choice(self.photo_real.SENSUAL_POSES) primary_color = random.choice(fashion_elements["colors"]) discovery_moment = random.choice(fashion_elements["discovery_moments"]) reveal_action = random.choice(fashion_elements["lingerie_reveal_actions"]) background = random.choice(fashion_elements["backgrounds"]) lighting = random.choice(fashion_elements["lighting"]) prompt = ( f"Photorealistic portrait of {subject_name} as a {role['role']}, " f"captured from an extreme low angle, floor-level perspective, shooting upward. " f"The composition focuses on a moment of discovery, {discovery_moment}. " f"She is {reveal_action}, creating a natural and unposed exposure.\n\n" f"**Body & Appearance:**\n" f"- **Physique:** {body} with {skin}.\n" f"- **Hair:** {hair}.\n" f"- **Expression:** {expression}.\n" f"- **Outfit:** She wears {role['outfit']} over {primary_color} lingerie. " f"Complemented by {self.photo_real.STOCKINGS} and {self.photo_real.HEELS}.\n\n" f"**Scene & Atmosphere:**\n" f"- **Setting:** {background} with {lighting}.\n" f"- **Pose:** {sensual_pose['pose']} ({sensual_pose['view']} view).\n" f"- **Mood:** Intimate, sensual, and elegantly composed.\n\n" f"**Technical Details:**\n" f"- **Camera:** {self.photo_real.CAMERA}.\n" f"- **Quality:** Ultra HD, professional retouching.\n\n" f"--ar 9:16 --v 6 --q 2 --style raw --stylize 100" ) return prompt.strip() except Exception: return f"Photorealistic portrait of {subject_name} in an elegant setting --ar 9:16 --v 6" def clear_history(self): self.previous_prompts.clear() def create_gradio_interface(): generator = FashionPromptGenerator() with gr.Blocks() as demo: gr.Markdown(""" # 🎭 Advanced Fashion Prompt Generator """) with gr.Row(): with gr.Column(scale=2): celebrity_input = gr.Textbox( label="Celebrity Name (Optional)", placeholder="Enter a name or leave blank for 'a beautiful woman'", value="" ) num_prompts_slider = gr.Slider( minimum=1, maximum=10, value=5, step=1, label="Number of Prompts to Generate" ) with gr.Column(scale=1): generate_btn = gr.Button("✨ Generate Prompts", variant="primary") clear_btn = gr.Button("🗑️ Clear History", variant="secondary") gr.Markdown("---") with gr.Row(): with gr.Column(): gr.Markdown("### Negative Prompt") negative_prompt_output = gr.Textbox( value=negative_prompt_fusion, lines=4, interactive=False ) gr.Markdown("## Generated Prompts") output_columns = [] output_prompts = [] # ------------------------- # PROMPTS + BOTÓN COPIAR # ------------------------- for i in range(10): with gr.Column(visible=(i < 5)) as col: gr.Markdown(f"### 🎯 Prompt {i+1}") prompt_output = gr.Textbox( label="", lines=12, interactive=False, elem_id=f"prompt_box_{i}" ) copy_btn = gr.Button("📋 Copiar", elem_id=f"copy_btn_{i}") copy_btn.click( None, [], [], _js=f""" () => {{ const text = document.querySelector('#prompt_box_{i} textarea').value; navigator.clipboard.writeText(text); alert('Prompt copiado 👍'); }} """ ) output_columns.append(col) output_prompts.append(prompt_output) # Generar prompts def generate_and_display(celebrity_name, num_prompts): prompts = generator.generate_unique_prompts(celebrity_name, int(num_prompts)) updates = [] for i in range(10): if i < num_prompts: updates.append(gr.update(visible=True)) updates.append(gr.update(value=prompts[i])) else: updates.append(gr.update(visible=False)) updates.append(gr.update(value="")) return updates flat_outputs = [] for i in range(10): flat_outputs.append(output_columns[i]) flat_outputs.append(output_prompts[i]) generate_btn.click( generate_and_display, [celebrity_input, num_prompts_slider], flat_outputs ) # Clear def clear_history_and_outputs(): generator.clear_history() updates = [] for i in range(10): updates.append(gr.update(visible=(i < 5))) updates.append(gr.update(value="")) return updates clear_btn.click( clear_history_and_outputs, None, flat_outputs ) return demo if __name__ == "__main__": demo = create_gradio_interface() demo.launch( share=True, server_name="0.0.0.0", server_port=7860 )