panelforge commited on
Commit
66d1fcc
·
verified ·
1 Parent(s): 12fceeb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -20
app.py CHANGED
@@ -2,9 +2,9 @@ import gradio as gr
2
  import numpy as np
3
  import random
4
  import spaces # [uncomment to use ZeroGPU]
5
- from diffusers import DiffusionPipeline, DPMSolverSDEScheduler
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 # Import tags here
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
@@ -22,13 +22,16 @@ 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,
27
- selected_hair_style_tags, selected_position_tags, selected_fetish_tags, selected_location_tags,
28
- selected_camera_tags, selected_atmosphere_tags, use_tags, progress=gr.Progress(track_tqdm=True)):
29
 
30
- # Construct final prompt using selected tags if `use_tags` is True
31
- if use_tags:
 
 
 
32
  selected_tags = (
33
  [participant_tags[tag] for tag in selected_participant_tags] +
34
  [tribe_tags[tag] for tag in selected_tribe_tags] +
@@ -47,8 +50,6 @@ def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance
47
  )
48
  tags_text = ', '.join(selected_tags)
49
  final_prompt = f'score_9, score_8_up, score_7_up, source_anime, {tags_text}'
50
- else:
51
- final_prompt = f'score_9, score_8_up, score_7_up, source_anime, {prompt}'
52
 
53
  # Concatenate user-provided negative prompt with additional restrictions
54
  additional_negatives = "worst quality, bad quality, jpeg artifacts, source_cartoon, 3d, (censor), monochrome, blurry, lowres, watermark"
@@ -103,7 +104,7 @@ with gr.Blocks(css=css) as demo:
103
 
104
  # Tabbed interface to select either Prompt or Tags
105
  with gr.Tabs() as tabs:
106
- with gr.TabItem("Prompt Input"):
107
  prompt = gr.Textbox(
108
  label="Prompt",
109
  show_label=False,
@@ -111,9 +112,8 @@ with gr.Blocks(css=css) as demo:
111
  placeholder="Enter your prompt",
112
  container=False,
113
  )
114
- use_tags = gr.State(False)
115
 
116
- with gr.TabItem("Tag Selection"):
117
  # Tag selection checkboxes for each tag group
118
  selected_participant_tags = gr.CheckboxGroup(choices=list(participant_tags.keys()), label="Participant Tags")
119
  selected_tribe_tags = gr.CheckboxGroup(choices=list(tribe_tags.keys()), label="Tribe Tags")
@@ -130,8 +130,6 @@ with gr.Blocks(css=css) as demo:
130
  selected_camera_tags = gr.CheckboxGroup(choices=list(camera_tags.keys()), label="Camera Tags")
131
  selected_atmosphere_tags = gr.CheckboxGroup(choices=list(atmosphere_tags.keys()), label="Atmosphere Tags")
132
 
133
- use_tags = gr.State(True)
134
-
135
  # Full-width "Run" button
136
  run_button = gr.Button("Run", scale=0, elem_id="run-button")
137
 
@@ -194,11 +192,11 @@ with gr.Blocks(css=css) as demo:
194
 
195
  run_button.click(
196
  infer,
197
- inputs=[prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps,
198
- selected_participant_tags, selected_tribe_tags, selected_skin_tone_tags, selected_body_type_tags,
199
- selected_tattoo_tags, selected_piercing_tags, selected_expression_tags, selected_eye_tags,
200
- selected_hair_style_tags, selected_position_tags, selected_fetish_tags, selected_location_tags,
201
- selected_camera_tags, selected_atmosphere_tags, use_tags],
202
  outputs=[result, seed, prompt_info]
203
  )
204
 
 
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
 
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,
27
+ selected_hair_style_tags, selected_position_tags, selected_fetish_tags, selected_location_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] +
 
50
  )
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"
 
104
 
105
  # Tabbed interface to select either Prompt or Tags
106
  with gr.Tabs() as tabs:
107
+ with gr.TabItem("Prompt Input") as prompt_tab:
108
  prompt = gr.Textbox(
109
  label="Prompt",
110
  show_label=False,
 
112
  placeholder="Enter your prompt",
113
  container=False,
114
  )
 
115
 
116
+ with gr.TabItem("Tag Selection") as tag_tab:
117
  # Tag selection checkboxes for each tag group
118
  selected_participant_tags = gr.CheckboxGroup(choices=list(participant_tags.keys()), label="Participant Tags")
119
  selected_tribe_tags = gr.CheckboxGroup(choices=list(tribe_tags.keys()), label="Tribe Tags")
 
130
  selected_camera_tags = gr.CheckboxGroup(choices=list(camera_tags.keys()), label="Camera Tags")
131
  selected_atmosphere_tags = gr.CheckboxGroup(choices=list(atmosphere_tags.keys()), label="Atmosphere Tags")
132
 
 
 
133
  # Full-width "Run" button
134
  run_button = gr.Button("Run", scale=0, elem_id="run-button")
135
 
 
192
 
193
  run_button.click(
194
  infer,
195
+ inputs=[prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps,
196
+ selected_participant_tags, selected_tribe_tags, selected_skin_tone_tags, selected_body_type_tags,
197
+ selected_tattoo_tags, selected_piercing_tags, selected_expression_tags, selected_eye_tags,
198
+ selected_hair_style_tags, selected_position_tags, selected_fetish_tags, selected_location_tags,
199
+ selected_camera_tags, selected_atmosphere_tags, tabs],
200
  outputs=[result, seed, prompt_info]
201
  )
202