Leteint commited on
Commit
4908f5d
Β·
verified Β·
1 Parent(s): 18b1d96

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -36
app.py CHANGED
@@ -13,7 +13,7 @@ LORA_FACE_ADAPTER = "face_detail"
13
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
14
  DTYPE = torch.float16 if DEVICE == "cuda" else torch.float32
15
 
16
- print("πŸ”₯ SDXL NSFW loading...")
17
  pipe = AutoPipelineForText2Image.from_pretrained(
18
  BASE_MODEL_ID,
19
  torch_dtype=DTYPE,
@@ -23,22 +23,21 @@ pipe = AutoPipelineForText2Image.from_pretrained(
23
  )
24
  pipe.to(DEVICE)
25
 
26
- # BYPASS NSFW total
27
  def dummy_checker(images, **kwargs):
28
  return images, [False] * len(images)
29
  pipe.safety_checker = dummy_checker
30
  pipe.set_progress_bar_config(disable=True)
31
 
32
- print("LoRA face/detail...")
33
  pipe.load_lora_weights(LORA_FACE_REPO, adapter_name=LORA_FACE_ADAPTER)
34
 
35
  os.makedirs("outputs", exist_ok=True)
36
 
37
  @spaces.GPU()
38
  def generate(prompt, negative, seed_str, steps, guidance, width, height, face_weight, filename):
39
- # FIX SEED : Gradio donne str β†’ convert safe
40
  try:
41
- seed = int(float(seed_str)) if seed_str and seed_str.strip() != '' else -1
42
  except:
43
  seed = -1
44
 
@@ -47,8 +46,8 @@ def generate(prompt, negative, seed_str, steps, guidance, width, height, face_we
47
  pipe.set_adapters([LORA_FACE_ADAPTER], adapter_weights=[float(face_weight)])
48
 
49
  result = pipe(
50
- prompt=prompt,
51
- negative_prompt=negative or None,
52
  num_inference_steps=int(steps),
53
  guidance_scale=float(guidance),
54
  width=int(width),
@@ -56,53 +55,45 @@ def generate(prompt, negative, seed_str, steps, guidance, width, height, face_we
56
  generator=generator,
57
  ).images[0]
58
 
59
- metadata = {
60
- "model": BASE_MODEL_ID,
61
- "lora": LORA_FACE_REPO,
62
- "prompt": prompt,
63
- "seed": seed,
64
- "steps": int(steps),
65
- "guidance": float(guidance),
66
- }
67
-
68
  safe_name = filename.strip().replace(" ", "_").replace("/", "_") or "sdxl_nsfw"
69
  img_path = f"outputs/{safe_name}.png"
70
  json_path = f"outputs/{safe_name}.json"
71
 
 
 
72
  pnginfo = PngImagePlugin.PngInfo()
73
  pnginfo.add_text("params", json.dumps(metadata))
74
  result.save(img_path, pnginfo=pnginfo)
75
 
76
- with open(json_path, "w", encoding="utf-8") as f:
77
  json.dump(metadata, f, indent=2)
78
 
79
  return result, json.dumps(metadata, indent=2), json_path
80
 
81
- with gr.Blocks(title="πŸ”₯ SDXL NSFW + Detail LoRA") as demo:
82
- gr.Markdown("# SDXL 1.0 **NSFW UNLOCKED** + Face Detail\nβœ… Safety checker BYPASSED")
83
 
84
  with gr.Row():
85
  with gr.Column():
86
- prompt = gr.Textbox("Prompt", lines=4, value="masterpiece, 1girl nude, detailed anatomy, realistic skin, sharp face, hourglass body")
87
- negative = gr.Textbox("Negative", value="blurry, deformed, ugly, extra limbs, low quality")
88
- seed = gr.Number("Seed (-1=random)", value=-1)
89
- steps = gr.Slider(20, 50, 35, step=1, label="Steps")
90
- guidance = gr.Slider(5.0, 12.0, 7.5, step=0.1, label="Guidance")
91
- width = gr.Slider(512, 1536, 1024, step=64, label="Width")
92
- height = gr.Slider(512, 1536, 1024, step=64, label="Height")
93
- face_weight = gr.Slider(0.0, 1.2, 0.7, step=0.05, label="LoRA Face Weight")
94
- filename = gr.Textbox("Filename", value="nsfw_test")
95
 
96
  with gr.Column():
97
- output_img = gr.Image("Generated Image")
98
- output_json = gr.Textbox("Metadata", lines=8)
99
- output_file = gr.File("Download JSON")
100
 
101
- gr.Button("πŸš€ Generate NSFW", variant="primary", size="lg").click(
102
  generate,
103
- [prompt, negative, seed, steps, guidance, width, height, face_weight, filename],
104
- [output_img, output_json, output_file]
105
  )
106
 
107
- if __name__ == "__main__":
108
- demo.launch()
 
13
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
14
  DTYPE = torch.float16 if DEVICE == "cuda" else torch.float32
15
 
16
+ print("πŸ”₯ SDXL NSFW...")
17
  pipe = AutoPipelineForText2Image.from_pretrained(
18
  BASE_MODEL_ID,
19
  torch_dtype=DTYPE,
 
23
  )
24
  pipe.to(DEVICE)
25
 
 
26
  def dummy_checker(images, **kwargs):
27
  return images, [False] * len(images)
28
  pipe.safety_checker = dummy_checker
29
  pipe.set_progress_bar_config(disable=True)
30
 
31
+ print("LoRA...")
32
  pipe.load_lora_weights(LORA_FACE_REPO, adapter_name=LORA_FACE_ADAPTER)
33
 
34
  os.makedirs("outputs", exist_ok=True)
35
 
36
  @spaces.GPU()
37
  def generate(prompt, negative, seed_str, steps, guidance, width, height, face_weight, filename):
38
+ # SEED SAFE
39
  try:
40
+ seed = int(float(seed_str)) if seed_str.strip() else -1
41
  except:
42
  seed = -1
43
 
 
46
  pipe.set_adapters([LORA_FACE_ADAPTER], adapter_weights=[float(face_weight)])
47
 
48
  result = pipe(
49
+ prompt=prompt or "masterpiece",
50
+ negative_prompt=negative,
51
  num_inference_steps=int(steps),
52
  guidance_scale=float(guidance),
53
  width=int(width),
 
55
  generator=generator,
56
  ).images[0]
57
 
 
 
 
 
 
 
 
 
 
58
  safe_name = filename.strip().replace(" ", "_").replace("/", "_") or "sdxl_nsfw"
59
  img_path = f"outputs/{safe_name}.png"
60
  json_path = f"outputs/{safe_name}.json"
61
 
62
+ metadata = {"prompt": prompt, "seed": seed, "steps": int(steps), "guidance": float(guidance)}
63
+
64
  pnginfo = PngImagePlugin.PngInfo()
65
  pnginfo.add_text("params", json.dumps(metadata))
66
  result.save(img_path, pnginfo=pnginfo)
67
 
68
+ with open(json_path, "w") as f:
69
  json.dump(metadata, f, indent=2)
70
 
71
  return result, json.dumps(metadata, indent=2), json_path
72
 
73
+ with gr.Blocks(title="πŸ”₯ SDXL NSFW") as demo:
74
+ gr.Markdown("# SDXL 1.0 **NSFW** + Face LoRA\nβœ… No Errors")
75
 
76
  with gr.Row():
77
  with gr.Column():
78
+ prompt = gr.Textbox("Prompt", value="1girl nude, masterpiece, detailed skin, sharp face")
79
+ negative = gr.Textbox("Negative", value="blurry, deformed, ugly")
80
+ seed = gr.Number("Seed", value=-1)
81
+ steps = gr.Slider(20, 50, 35, step=1)
82
+ guidance = gr.Slider(5, 12, 7.5, step=0.1)
83
+ width = gr.Slider(512, 1536, 1024, step=64)
84
+ height = gr.Slider(512, 1536, 1024, step=64)
85
+ lora_w = gr.Slider(0, 1.2, 0.7, step=0.05, label="LoRA Weight")
86
+ name = gr.Textbox("Filename", value="test_nsfw")
87
 
88
  with gr.Column():
89
+ img_out = gr.Image(label="Image")
90
+ json_out = gr.Textbox(label="Metadata", lines=8)
91
+ file_out = gr.File(label="Download JSON") # ← FIX: label= au lieu de positional
92
 
93
+ gr.Button("πŸš€ NSFW Generate", variant="primary").click(
94
  generate,
95
+ [prompt, negative, seed, steps, guidance, width, height, lora_w, name],
96
+ [img_out, json_out, file_out]
97
  )
98
 
99
+ demo.launch()