| import gradio as gr |
| import torch |
| from diffusers import StableDiffusionInpaintPipeline |
| from PIL import Image |
| import numpy as np |
| import cv2 |
|
|
| |
| device = "cuda" if torch.cuda.is_available() else "cpu" |
| print(f"Usando: {device}") |
|
|
| pipe = StableDiffusionInpaintPipeline.from_pretrained( |
| "runwayml/stable-diffusion-inpainting", |
| torch_dtype=torch.float32 if device == "cpu" else torch.float16, |
| safety_checker=None, |
| requires_safety_checker=False |
| ).to(device) |
|
|
| def create_mask(img): |
| img_np = np.array(img) |
| h, w = img_np.shape[:2] |
| mask = np.zeros((h, w), dtype=np.uint8) |
| |
| cv2.rectangle(mask, (w//4, h//3), (3*w//4, h-50), 255, -1) |
| cv2.ellipse(mask, (w//2, h//2), (w//3, h//3), 0, 0, 360, 255, -1) |
| return Image.fromarray(mask) |
|
|
| def generate_nude(input_img, prompt="realistic nude woman, perfect anatomy, detailed skin, high quality, 8k"): |
| if input_img is None: |
| return None |
| mask = create_mask(input_img) |
| result = pipe( |
| prompt, |
| image=input_img, |
| mask_image=mask, |
| num_inference_steps=15, |
| guidance_scale=7.5, |
| width=512, |
| height=768 |
| ).images[0] |
| return result |
|
|
| |
| with gr.Blocks(title="DeepNude Gratis") as demo: |
| gr.Markdown("# 🖤 DeepNude GRATIS ILIMITADO - HF Spaces") |
| with gr.Row(): |
| with gr.Column(): |
| input_img = gr.Image(type="pil", label="📸 Foto con ropa") |
| prompt = gr.Textbox("nude realistic body, detailed skin", label="✨ Prompt") |
| btn = gr.Button("🔥 Generar Nude", variant="primary") |
| output_img = gr.Image(label="🎨 Resultado DeepNude") |
| |
| btn.click(generate_nude, inputs=[input_img, prompt], outputs=output_img) |
| gr.Examples( |
| examples=[], |
| inputs=[input_img, prompt] |
| ) |
|
|
| demo.launch(server_name="0.0.0.0", server_port=7860, share=True) |
|
|