Spaces:
Running
Running
| import gradio as gr | |
| from diffusers import StableDiffusionImg2ImgPipeline | |
| import torch | |
| # فقط CPU + float32 + بدون LoRA + مدل کوچکتر | |
| pipe = StableDiffusionImg2ImgPipeline.from_pretrained( | |
| "runwayml/stable-diffusion-v1-5", | |
| torch_dtype=torch.float32, | |
| safety_checker=None, | |
| variant="fp16", # مدل کوچیکتر | |
| use_safetensors=True | |
| ) | |
| def generate(image, prompt, negative_prompt="", steps=15, strength=0.35): | |
| try: | |
| result = pipe( | |
| prompt=prompt, | |
| negative_prompt=negative_prompt, | |
| image=image, | |
| num_inference_steps=steps, | |
| strength=strength, | |
| guidance_scale=7.0 | |
| ).images[0] | |
| return result | |
| except Exception as e: | |
| return f"Error: {str(e)}" | |
| with gr.Blocks() as demo: | |
| gr.Markdown("## NSFW Face Swap (CPU Only - No LoRA)") | |
| with gr.Row(): | |
| with gr.Column(): | |
| input_img = gr.Image(type="pil", label="Upload Face Photo") | |
| prompt = gr.Textbox( | |
| label="Prompt", | |
| lines=3, | |
| value="photorealistic, nude girl sitting on bed, wearing tiny lace thong, small pink vulva visible, wet, face locked to input image" | |
| ) | |
| neg_prompt = gr.Textbox( | |
| label="Negative", | |
| value="large vulva, deformed, plastic, child, extra limbs" | |
| ) | |
| steps = gr.Slider(10, 25, 15, label="Steps (کم = سریعتر)") | |
| strength = gr.Slider(0.2, 0.5, 0.35, label="Strength") | |
| btn = gr.Button("Generate (20-40s)") | |
| with gr.Column(): | |
| output = gr.Image(label="Result") | |
| btn.click(generate, [input_img, prompt, neg_prompt, steps, strength], output) | |
| demo.launch() |