Mbeheshtii commited on
Commit
860b46c
·
verified ·
1 Parent(s): cd0d0e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -29
app.py CHANGED
@@ -2,44 +2,47 @@ import gradio as gr
2
  from diffusers import StableDiffusionImg2ImgPipeline
3
  import torch
4
 
5
- pipe = StableDiffusionImg2ImgPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
6
- pipe = pipe.to("cuda")
 
 
 
 
 
7
 
8
- def generate(image, prompt, negative_prompt="", steps=45, strength=0.25, cfg=5.0, lora_path=None, lora_strength=0.5):
9
- if lora_path:
10
- pipe.load_lora_weights(lora_path)
11
- pipe.fuse_lora(lora_strength=lora_strength)
12
-
13
- result = pipe(
14
- prompt=prompt,
15
- negative_prompt=negative_prompt,
16
- image=image,
17
- num_inference_steps=steps,
18
- strength=strength,
19
- guidance_scale=cfg
20
- ).images[0]
21
-
22
- if lora_path:
23
- pipe.unfuse_lora()
24
-
25
- return result
26
 
27
  with gr.Blocks() as demo:
28
- gr.Markdown("## NSFW Image-to-Image with Grool LoRA")
29
  with gr.Row():
30
  with gr.Column():
31
  input_img = gr.Image(type="pil", label="Upload Face Photo")
32
- prompt = gr.Textbox(label="Prompt", lines=4, value="photorealistic 8k, nude girl sitting on bed in bright bedroom, legs open, wearing ultra-narrow lace micro-thong with transparent mesh, small delicate pink vulva and anus completely visible through lace, tiny entrance, petite labia, wetness, face locked to input image --ar 2:3")
33
- neg_prompt = gr.Textbox(label="Negative", value="large vulva, thick lines, deformed, plastic, child")
34
- steps = gr.Slider(20, 100, 45)
35
- strength = gr.Slider(0, 1, 0.25, label="Denoising Strength")
36
- cfg = gr.Slider(1, 20, 5.0)
37
  lora_file = gr.File(label="Upload LoRA")
38
- lora_strength = gr.Slider(0, 1, 0.5)
39
- btn = gr.Button("Generate")
40
  with gr.Column():
41
  output = gr.Image(label="Result")
42
 
43
- btn.click(generate, [input_img, prompt, neg_prompt, steps, strength, cfg, lora_file, lora_strength], output)
44
 
45
  demo.launch()
 
2
  from diffusers import StableDiffusionImg2ImgPipeline
3
  import torch
4
 
5
+ # فقط CPU
6
+ pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
7
+ "runwayml/stable-diffusion-v1-5",
8
+ torch_dtype=torch.float32, # float16 روی CPU نمی‌شه
9
+ safety_checker=None,
10
+ requires_safety_checker=False
11
+ )
12
 
13
+ def generate(image, prompt, negative_prompt="", steps=20, strength=0.3, cfg=7.0, lora_path=None, lora_strength=0.6):
14
+ try:
15
+ if lora_path:
16
+ pipe.load_lora_weights(lora_path)
17
+
18
+ result = pipe(
19
+ prompt=prompt,
20
+ negative_prompt=negative_prompt,
21
+ image=image,
22
+ num_inference_steps=steps,
23
+ strength=strength,
24
+ guidance_scale=cfg
25
+ ).images[0]
26
+
27
+ return result
28
+ except Exception as e:
29
+ return f"Error: {str(e)}"
 
30
 
31
  with gr.Blocks() as demo:
32
+ gr.Markdown("## NSFW Image-to-Image (CPU Only)")
33
  with gr.Row():
34
  with gr.Column():
35
  input_img = gr.Image(type="pil", label="Upload Face Photo")
36
+ prompt = gr.Textbox(label="Prompt", lines=3, value="nude girl in bedroom, wearing tiny lace thong, small vulva visible, face locked to input image")
37
+ neg_prompt = gr.Textbox(label="Negative", value="deformed, large vulva, child")
38
+ steps = gr.Slider(10, 30, 20, label="Steps (کم = سریع‌تر)")
39
+ strength = gr.Slider(0.1, 0.5, 0.3, label="Strength")
40
+ cfg = gr.Slider(5, 10, 7.0, label="CFG")
41
  lora_file = gr.File(label="Upload LoRA")
42
+ btn = gr.Button("Generate (30–60s)")
 
43
  with gr.Column():
44
  output = gr.Image(label="Result")
45
 
46
+ btn.click(generate, [input_img, prompt, neg_prompt, steps, strength, cfg, lora_file], output)
47
 
48
  demo.launch()