panelforge commited on
Commit
c8b9716
·
verified ·
1 Parent(s): e91b926

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -37
app.py CHANGED
@@ -1,13 +1,13 @@
1
  import gradio as gr
2
- import spaces
3
- import torch
4
- from diffusers import DiffusionPipeline
5
  import numpy as np
6
  import random
 
 
 
7
  from tags import participant_tags, tribe_tags, skin_tone_tags, body_type_tags, tattoo_tags, piercing_tags, expression_tags, eye_tags, hair_style_tags, position_tags, fetish_tags, location_tags, camera_tags, atmosphere_tags
8
 
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
- model_repo_id = "John6666/wai-ani-nsfw-ponyxl-v8-sdxl" # Default model version
11
 
12
  if torch.cuda.is_available():
13
  torch_dtype = torch.float16
@@ -20,7 +20,7 @@ pipe = pipe.to(device)
20
  MAX_SEED = np.iinfo(np.int32).max
21
  MAX_IMAGE_SIZE = 1024
22
 
23
- @spaces.GPU
24
  def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps,
25
  selected_participant_tags, selected_tribe_tags, selected_skin_tone_tags, selected_body_type_tags,
26
  selected_tattoo_tags, selected_piercing_tags, selected_expression_tags, selected_eye_tags,
@@ -28,8 +28,10 @@ def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance
28
  selected_camera_tags, selected_atmosphere_tags, active_tab, progress=gr.Progress(track_tqdm=True)):
29
 
30
  if active_tab == "Prompt Input":
 
31
  final_prompt = f'score_9, score_8_up, score_7_up, source_anime, {prompt}'
32
  else:
 
33
  selected_tags = (
34
  [participant_tags[tag] for tag in selected_participant_tags] +
35
  [tribe_tags[tag] for tag in selected_tribe_tags] +
@@ -49,6 +51,7 @@ def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance
49
  tags_text = ', '.join(selected_tags)
50
  final_prompt = f'score_9, score_8_up, score_7_up, source_anime, {tags_text}'
51
 
 
52
  additional_negatives = "worst quality, bad quality, jpeg artifacts, source_cartoon, 3d, (censor), monochrome, blurry, lowres, watermark"
53
  full_negative_prompt = f"{additional_negatives}, {negative_prompt}"
54
 
@@ -57,6 +60,7 @@ def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance
57
 
58
  generator = torch.Generator().manual_seed(seed)
59
 
 
60
  image = pipe(
61
  prompt=final_prompt,
62
  negative_prompt=full_negative_prompt,
@@ -67,6 +71,7 @@ def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance
67
  generator=generator
68
  ).images[0]
69
 
 
70
  return image, seed, f"Prompt used: {final_prompt}\nNegative prompt used: {full_negative_prompt}"
71
 
72
 
@@ -125,9 +130,13 @@ with gr.Blocks(css=css) as demo:
125
  with gr.Column(elem_id="left-column"):
126
  gr.Markdown("""# Rainbow Media X""")
127
 
 
128
  result = gr.Image(label="Result", show_label=False, elem_id="result")
 
 
129
  prompt_info = gr.Textbox(label="Prompts Used", lines=3, interactive=False, elem_id="prompt-info")
130
 
 
131
  with gr.Accordion("Advanced Settings", open=False):
132
  negative_prompt = gr.Textbox(
133
  label="Negative prompt",
@@ -180,11 +189,15 @@ with gr.Blocks(css=css) as demo:
180
  value=35,
181
  )
182
 
 
183
  run_button = gr.Button("Run", elem_id="run-button")
184
 
185
  with gr.Column(elem_id="right-column"):
 
 
186
  active_tab = gr.State("Prompt Input")
187
 
 
188
  with gr.Tabs() as tabs:
189
  with gr.TabItem("Prompt Input") as prompt_tab:
190
  prompt = gr.Textbox(
@@ -198,6 +211,7 @@ with gr.Blocks(css=css) as demo:
198
  prompt_tab.select(lambda: "Prompt Input", inputs=None, outputs=active_tab)
199
 
200
  with gr.TabItem("Tag Selection") as tag_tab:
 
201
  selected_participant_tags = gr.CheckboxGroup(choices=list(participant_tags.keys()), label="Participant Tags")
202
  selected_tribe_tags = gr.CheckboxGroup(choices=list(tribe_tags.keys()), label="Tribe Tags")
203
  selected_skin_tone_tags = gr.CheckboxGroup(choices=list(skin_tone_tags.keys()), label="Skin Tone Tags")
@@ -214,37 +228,6 @@ with gr.Blocks(css=css) as demo:
214
  selected_atmosphere_tags = gr.CheckboxGroup(choices=list(atmosphere_tags.keys()), label="Atmosphere Tags")
215
  tag_tab.select(lambda: "Tag Selection", inputs=None, outputs=active_tab)
216
 
217
- # Model version buttons
218
- link_button_v7 = gr.Button("Use Model V7")
219
- link_button_v8 = gr.Button("Use Model V8")
220
- link_button_v11 = gr.Button("Use Model V11")
221
-
222
- def update_model_version_v7():
223
- global model_repo_id
224
- model_repo_id = "John6666/wai-ani-nsfw-ponyxl-v7-sdxl"
225
- global pipe
226
- pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
227
- pipe = pipe.to(device)
228
-
229
- def update_model_version_v8():
230
- global model_repo_id
231
- model_repo_id = "John6666/wai-ani-nsfw-ponyxl-v8-sdxl"
232
- global pipe
233
- pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
234
- pipe = pipe.to(device)
235
-
236
- def update_model_version_v11():
237
- global model_repo_id
238
- model_repo_id = "John6666/wai-ani-nsfw-ponyxl-v11-sdxl"
239
- global pipe
240
- pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
241
- pipe = pipe.to(device)
242
-
243
- # Link button actions
244
- link_button_v7.click(update_model_version_v7)
245
- link_button_v8.click(update_model_version_v8)
246
- link_button_v11.click(update_model_version_v11)
247
-
248
  run_button.click(
249
  infer,
250
  inputs=[prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps,
@@ -255,4 +238,4 @@ with gr.Blocks(css=css) as demo:
255
  outputs=[result, seed, prompt_info]
256
  )
257
 
258
- demo.queue()
 
1
  import gradio as gr
 
 
 
2
  import numpy as np
3
  import random
4
+ import spaces # [uncomment to use ZeroGPU]
5
+ from diffusers import DiffusionPipeline
6
+ import torch
7
  from tags import participant_tags, tribe_tags, skin_tone_tags, body_type_tags, tattoo_tags, piercing_tags, expression_tags, eye_tags, hair_style_tags, position_tags, fetish_tags, location_tags, camera_tags, atmosphere_tags
8
 
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
+ model_repo_id = "John6666/wai-ani-nsfw-ponyxl-v8-sdxl" # Replace with your desired model
11
 
12
  if torch.cuda.is_available():
13
  torch_dtype = torch.float16
 
20
  MAX_SEED = np.iinfo(np.int32).max
21
  MAX_IMAGE_SIZE = 1024
22
 
23
+ @spaces.GPU # [uncomment to use ZeroGPU]
24
  def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps,
25
  selected_participant_tags, selected_tribe_tags, selected_skin_tone_tags, selected_body_type_tags,
26
  selected_tattoo_tags, selected_piercing_tags, selected_expression_tags, selected_eye_tags,
 
28
  selected_camera_tags, selected_atmosphere_tags, active_tab, progress=gr.Progress(track_tqdm=True)):
29
 
30
  if active_tab == "Prompt Input":
31
+ # Use the user-provided prompt
32
  final_prompt = f'score_9, score_8_up, score_7_up, source_anime, {prompt}'
33
  else:
34
+ # Use tags from the "Tag Selection" tab
35
  selected_tags = (
36
  [participant_tags[tag] for tag in selected_participant_tags] +
37
  [tribe_tags[tag] for tag in selected_tribe_tags] +
 
51
  tags_text = ', '.join(selected_tags)
52
  final_prompt = f'score_9, score_8_up, score_7_up, source_anime, {tags_text}'
53
 
54
+ # Concatenate user-provided negative prompt with additional restrictions
55
  additional_negatives = "worst quality, bad quality, jpeg artifacts, source_cartoon, 3d, (censor), monochrome, blurry, lowres, watermark"
56
  full_negative_prompt = f"{additional_negatives}, {negative_prompt}"
57
 
 
60
 
61
  generator = torch.Generator().manual_seed(seed)
62
 
63
+ # Generate the image with the final prompts
64
  image = pipe(
65
  prompt=final_prompt,
66
  negative_prompt=full_negative_prompt,
 
71
  generator=generator
72
  ).images[0]
73
 
74
+ # Return image, seed, and the used prompts
75
  return image, seed, f"Prompt used: {final_prompt}\nNegative prompt used: {full_negative_prompt}"
76
 
77
 
 
130
  with gr.Column(elem_id="left-column"):
131
  gr.Markdown("""# Rainbow Media X""")
132
 
133
+ # Display result image at the top
134
  result = gr.Image(label="Result", show_label=False, elem_id="result")
135
+
136
+ # Add a textbox to display the prompts used for generation
137
  prompt_info = gr.Textbox(label="Prompts Used", lines=3, interactive=False, elem_id="prompt-info")
138
 
139
+ # Advanced Settings and Run Button
140
  with gr.Accordion("Advanced Settings", open=False):
141
  negative_prompt = gr.Textbox(
142
  label="Negative prompt",
 
189
  value=35,
190
  )
191
 
192
+ # Full-width "Run" button
193
  run_button = gr.Button("Run", elem_id="run-button")
194
 
195
  with gr.Column(elem_id="right-column"):
196
+ # Removed the Prompt / Tag Input title here
197
+ # State to track active tab
198
  active_tab = gr.State("Prompt Input")
199
 
200
+ # Tabbed interface to select either Prompt or Tags
201
  with gr.Tabs() as tabs:
202
  with gr.TabItem("Prompt Input") as prompt_tab:
203
  prompt = gr.Textbox(
 
211
  prompt_tab.select(lambda: "Prompt Input", inputs=None, outputs=active_tab)
212
 
213
  with gr.TabItem("Tag Selection") as tag_tab:
214
+ # Tag selection checkboxes for each tag group
215
  selected_participant_tags = gr.CheckboxGroup(choices=list(participant_tags.keys()), label="Participant Tags")
216
  selected_tribe_tags = gr.CheckboxGroup(choices=list(tribe_tags.keys()), label="Tribe Tags")
217
  selected_skin_tone_tags = gr.CheckboxGroup(choices=list(skin_tone_tags.keys()), label="Skin Tone Tags")
 
228
  selected_atmosphere_tags = gr.CheckboxGroup(choices=list(atmosphere_tags.keys()), label="Atmosphere Tags")
229
  tag_tab.select(lambda: "Tag Selection", inputs=None, outputs=active_tab)
230
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  run_button.click(
232
  infer,
233
  inputs=[prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps,
 
238
  outputs=[result, seed, prompt_info]
239
  )
240
 
241
+ demo.queue().launch()