Leteint commited on
Commit
18b1d96
Β·
verified Β·
1 Parent(s): 99d8afc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -23
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,23 +23,28 @@ pipe = AutoPipelineForText2Image.from_pretrained(
23
  )
24
  pipe.to(DEVICE)
25
 
26
- # MONKEY PATCH NSFW
27
  def dummy_checker(images, **kwargs):
28
  return images, [False] * len(images)
29
  pipe.safety_checker = dummy_checker
30
-
31
  pipe.set_progress_bar_config(disable=True)
32
 
33
- print("LoRA face...")
34
  pipe.load_lora_weights(LORA_FACE_REPO, adapter_name=LORA_FACE_ADAPTER)
35
 
36
  os.makedirs("outputs", exist_ok=True)
37
 
38
  @spaces.GPU()
39
- def generate(prompt, negative, seed, steps, guidance, width, height, face_weight, name):
40
- generator = torch.Generator(DEVICE).manual_seed(int(seed)) if seed >= 0 else torch.Generator(DEVICE)
 
 
 
 
 
 
41
 
42
- pipe.set_adapters([LORA_FACE_ADAPTER], adapter_weights=[face_weight])
43
 
44
  result = pipe(
45
  prompt=prompt,
@@ -55,12 +60,12 @@ def generate(prompt, negative, seed, steps, guidance, width, height, face_weight
55
  "model": BASE_MODEL_ID,
56
  "lora": LORA_FACE_REPO,
57
  "prompt": prompt,
58
- "seed": int(seed),
59
  "steps": int(steps),
60
  "guidance": float(guidance),
61
  }
62
 
63
- safe_name = name.strip().replace(" ", "_") or "sdxl_nsfw"
64
  img_path = f"outputs/{safe_name}.png"
65
  json_path = f"outputs/{safe_name}.json"
66
 
@@ -71,28 +76,32 @@ def generate(prompt, negative, seed, steps, guidance, width, height, face_weight
71
  with open(json_path, "w", encoding="utf-8") as f:
72
  json.dump(metadata, f, indent=2)
73
 
74
- return result, json.dumps(metadata, indent=2), json_path # ← chemin relatif OK pour gr.File
75
 
76
- with gr.Blocks(title="πŸ”₯ SDXL NSFW Unlocked") as demo:
77
- gr.Markdown("# SDXL 1.0 NSFW + Face Detail LoRA\nβœ… Safety checker BYPASSED")
78
 
79
  with gr.Row():
80
- with gr.Column(scale=1):
81
- prompt = gr.Textbox("Prompt", lines=4, value="1girl nude, masterpiece, detailed anatomy, realistic skin, sharp face")
82
- negative = gr.Textbox("Negative", value="blurry, deformed, ugly, low quality")
83
- seed = gr.Number("Seed", value=-1)
84
- steps = gr.Slider(20, 50, 35, step=1)
85
- guidance = gr.Slider(5, 12, 7.5, step=0.1)
86
- width = gr.Slider(512, 1536, 1024, step=64)
87
- height = gr.Slider(512, 1536, 1024, step=64)
88
- face_weight = gr.Slider(0, 1.2, 0.7, step=0.05, label="LoRA Weight")
89
  filename = gr.Textbox("Filename", value="nsfw_test")
90
 
91
- with gr.Column(scale=1):
 
 
 
 
92
  gr.Button("πŸš€ Generate NSFW", variant="primary", size="lg").click(
93
  generate,
94
  [prompt, negative, seed, steps, guidance, width, height, face_weight, filename],
95
- [gr.Image(label="Generated Image"), gr.Textbox(label="Metadata JSON"), gr.File(label="Download JSON")] # ← FIX ICI
96
  )
97
 
98
  if __name__ == "__main__":
 
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
  )
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
+
45
+ generator = torch.Generator(DEVICE).manual_seed(seed) if seed >= 0 else torch.Generator(DEVICE)
46
 
47
+ pipe.set_adapters([LORA_FACE_ADAPTER], adapter_weights=[float(face_weight)])
48
 
49
  result = pipe(
50
  prompt=prompt,
 
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
 
 
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__":