import gradio as gr import numpy as np from PIL import Image, ImageDraw def undress_image(image, penis_size): # Convert the image to PIL if it's a numpy array or file path if isinstance(image, str): img = Image.open(image) elif isinstance(image, np.ndarray): img = Image.fromarray(image) else: raise ValueError("Unsupported image type") # Convert to RGB if necessary if img.mode != 'RGB': img = img.convert('RGB') # For simulation: we'll draw a rectangle in the lower middle part of the image # The size of the rectangle will depend on the choice draw = ImageDraw.Draw(img) width, height = img.size # Define rectangle dimensions based on choice if penis_size == "Small": rect_height = height // 10 rect_width = width // 15 else: # Large rect_height = height // 6 rect_width = width // 8 # Position: centered horizontally, near the bottom left = (width - rect_width) // 2 top = height - rect_height - 20 # 20 pixels from bottom right = left + rect_width bottom = top + rect_height # Draw a rectangle (in red for simulation, but in reality you'd use skin tone or inpainting) draw.rectangle([left, top, right, bottom], fill="red") # Convert back to numpy array for Gradio return np.array(img) # Gradio app with gr.Blocks() as demo: gr.Markdown("# Male Undressing App") gr.Markdown("Upload a male photo and choose the penis size for the generated image. This app is for personal use only.") gr.Markdown("Built with [anycoder](https://huggingface.co/spaces/akhaliq/anycoder)") with gr.Row(): with gr.Column(): image_input = gr.Image(type="filepath", label="Upload Photo") size_choice = gr.Radio(choices=["Small", "Large"], label="Penis Size", value="Small") button = gr.Button("Generate Undressed Image") with gr.Column(): image_output = gr.Image(label="Result") button.click( fn=undress_image, inputs=[image_input, size_choice], outputs=image_output ) # Launch with a theme and other parameters in the launch method demo.launch(theme=gr.themes.Soft())