panelforge commited on
Commit
1b50d93
·
verified ·
1 Parent(s): 96cb575

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -157
app.py CHANGED
@@ -1,7 +1,7 @@
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, role_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
@@ -15,25 +15,25 @@ else:
15
  torch_dtype = torch.float32
16
 
17
  pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
18
- pipe = pipe.to(device)
19
 
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_role_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
-
34
- elif active_tab == "Straight" :
35
- # Use tags from the "Gay" tab
36
- selected_tags = (
37
  [participant_tags[tag] for tag in selected_participant_tags] +
38
  [tribe_tags[tag] for tag in selected_tribe_tags] +
39
  [role_tags[tag] for tag in selected_role_tags] +
@@ -50,63 +50,16 @@ def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance
50
  [camera_tags[tag] for tag in selected_camera_tags] +
51
  [atmosphere_tags[tag] for tag in selected_atmosphere_tags]
52
  )
53
- tags_text = ', '.join(selected_tags)
54
- final_prompt = f'score_9, score_8_up, score_7_up, source_anime, {tags_text}'
55
 
56
- elif active_tab == "Gay" :
57
- # Use tags from the "Gay" tab
58
- selected_tags = (
59
- [participant_tags[tag] for tag in selected_participant_tags] +
60
- [tribe_tags[tag] for tag in selected_tribe_tags] +
61
- [role_tags[tag] for tag in selected_role_tags] +
62
- [skin_tone_tags[tag] for tag in selected_skin_tone_tags] +
63
- [body_type_tags[tag] for tag in selected_body_type_tags] +
64
- [tattoo_tags[tag] for tag in selected_tattoo_tags] +
65
- [piercing_tags[tag] for tag in selected_piercing_tags] +
66
- [expression_tags[tag] for tag in selected_expression_tags] +
67
- [eye_tags[tag] for tag in selected_eye_tags] +
68
- [hair_style_tags[tag] for tag in selected_hair_style_tags] +
69
- [position_tags[tag] for tag in selected_position_tags] +
70
- [fetish_tags[tag] for tag in selected_fetish_tags] +
71
- [location_tags[tag] for tag in selected_location_tags] +
72
- [camera_tags[tag] for tag in selected_camera_tags] +
73
- [atmosphere_tags[tag] for tag in selected_atmosphere_tags]
74
- )
75
- tags_text = ', '.join(selected_tags)
76
- final_prompt = f'score_9, score_8_up, score_7_up, source_anime, {tags_text}'
77
-
78
- elif active_tab == "Lesbian" :
79
- # Use tags from the "Lesbien" tab
80
- selected_tags = (
81
- [participant_tags[tag] for tag in selected_participant_tags] +
82
- [tribe_tags[tag] for tag in selected_tribe_tags] +
83
- [role_tags[tag] for tag in selected_role_tags] +
84
- [skin_tone_tags[tag] for tag in selected_skin_tone_tags] +
85
- [body_type_tags[tag] for tag in selected_body_type_tags] +
86
- [tattoo_tags[tag] for tag in selected_tattoo_tags] +
87
- [piercing_tags[tag] for tag in selected_piercing_tags] +
88
- [expression_tags[tag] for tag in selected_expression_tags] +
89
- [eye_tags[tag] for tag in selected_eye_tags] +
90
- [hair_style_tags[tag] for tag in selected_hair_style_tags] +
91
- [position_tags[tag] for tag in selected_position_tags] +
92
- [fetish_tags[tag] for tag in selected_fetish_tags] +
93
- [location_tags[tag] for tag in selected_location_tags] +
94
- [camera_tags[tag] for tag in selected_camera_tags] +
95
- [atmosphere_tags[tag] for tag in selected_atmosphere_tags]
96
- )
97
- tags_text = ', '.join(selected_tags)
98
- final_prompt = f'score_9, score_8_up, score_7_up, source_anime, {tags_text}'
99
-
100
- # Concatenate user-provided negative prompt with additional restrictions
101
  additional_negatives = "worst quality, bad quality, jpeg artifacts, source_cartoon, 3d, (censor), monochrome, blurry, lowres, watermark"
102
  full_negative_prompt = f"{additional_negatives}, {negative_prompt}"
103
 
104
  if randomize_seed:
105
  seed = random.randint(0, MAX_SEED)
 
106
 
107
- generator = torch.Generator().manual_seed(seed)
108
-
109
- # Generate the image with the final prompts
110
  image = pipe(
111
  prompt=final_prompt,
112
  negative_prompt=full_negative_prompt,
@@ -117,54 +70,32 @@ def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance
117
  generator=generator
118
  ).images[0]
119
 
120
- # Return image, seed, and the used prompts
121
- return image, seed, f"Prompt used: {final_prompt}\nNegative prompt used: {full_negative_prompt}"
122
-
123
 
124
- examples = [
125
- "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
126
- "An astronaut riding a green horse",
127
- "A delicious ceviche cheesecake slice",
128
- ]
129
 
130
  css = """
131
  #col-container {
132
  margin: 0 auto;
133
  max-width: 640px;
134
  }
135
- #run-button {
136
- width: 100%;
137
- }
138
  """
139
 
140
  with gr.Blocks(css=css) as demo:
141
-
142
  with gr.Column(elem_id="col-container"):
143
- gr.Markdown("""# Rainbow Media X""")
144
 
145
- # Display result image at the top
146
  result = gr.Image(label="Result", show_label=False)
147
-
148
- # Add a textbox to display the prompts used for generation
149
  prompt_info = gr.Textbox(label="Prompts Used", lines=3, interactive=False)
150
-
151
- # State to track active tab
152
  active_tab = gr.State("Prompt Input")
153
 
154
- # Tabbed interface to select either Prompt or Tags
155
  with gr.Tabs() as tabs:
156
- with gr.TabItem("Prompt Input") as prompt_tab:
157
- prompt = gr.Textbox(
158
- label="Prompt",
159
- show_label=False,
160
- max_lines=1,
161
- placeholder="Enter your prompt",
162
- container=False,
163
- )
164
- prompt_tab.select(lambda: "Prompt Input", inputs=None, outputs=active_tab)
165
 
166
- with gr.TabItem("Straight") as straight_tag_tab:
167
- # Tag selection checkboxes for each tag group
168
  selected_participant_tags = gr.CheckboxGroup(choices=list(participant_tags.keys()), label="Participant Tags")
169
  selected_tribe_tags = gr.CheckboxGroup(choices=list(tribe_tags.keys()), label="Tribe Tags")
170
  selected_role_tags = gr.CheckboxGroup(choices=list(role_tags.keys()), label="Role Tags")
@@ -180,11 +111,10 @@ with gr.Blocks(css=css) as demo:
180
  selected_location_tags = gr.CheckboxGroup(choices=list(location_tags.keys()), label="Location Tags")
181
  selected_camera_tags = gr.CheckboxGroup(choices=list(camera_tags.keys()), label="Camera Tags")
182
  selected_atmosphere_tags = gr.CheckboxGroup(choices=list(atmosphere_tags.keys()), label="Atmosphere Tags")
183
- straight_tag_tab.select(lambda: "Straight", inputs=None, outputs=active_tab)
184
-
185
-
186
- with gr.TabItem("Gay") as gay_tag_tab:
187
- # Tag selection checkboxes for each tag group
188
  selected_participant_tags = gr.CheckboxGroup(choices=list(participant_tags.keys()), label="Participant Tags")
189
  selected_tribe_tags = gr.CheckboxGroup(choices=list(tribe_tags.keys()), label="Tribe Tags")
190
  selected_role_tags = gr.CheckboxGroup(choices=list(role_tags.keys()), label="Role Tags")
@@ -200,10 +130,10 @@ with gr.Blocks(css=css) as demo:
200
  selected_location_tags = gr.CheckboxGroup(choices=list(location_tags.keys()), label="Location Tags")
201
  selected_camera_tags = gr.CheckboxGroup(choices=list(camera_tags.keys()), label="Camera Tags")
202
  selected_atmosphere_tags = gr.CheckboxGroup(choices=list(atmosphere_tags.keys()), label="Atmosphere Tags")
203
- gay_tag_tab.select(lambda: "Gay", inputs=None, outputs=active_tab)
204
 
205
- with gr.TabItem("Lesbian") as lesbian_tag_tab:
206
- # Tag selection checkboxes for each tag group
207
  selected_participant_tags = gr.CheckboxGroup(choices=list(participant_tags.keys()), label="Participant Tags")
208
  selected_tribe_tags = gr.CheckboxGroup(choices=list(tribe_tags.keys()), label="Tribe Tags")
209
  selected_role_tags = gr.CheckboxGroup(choices=list(role_tags.keys()), label="Role Tags")
@@ -219,68 +149,23 @@ with gr.Blocks(css=css) as demo:
219
  selected_location_tags = gr.CheckboxGroup(choices=list(location_tags.keys()), label="Location Tags")
220
  selected_camera_tags = gr.CheckboxGroup(choices=list(camera_tags.keys()), label="Camera Tags")
221
  selected_atmosphere_tags = gr.CheckboxGroup(choices=list(atmosphere_tags.keys()), label="Atmosphere Tags")
222
- lesbian_tag_tab.select(lambda: "Lesbian", inputs=None, outputs=active_tab)
223
-
224
- # Full-width "Run" button
225
- run_button = gr.Button("Run", scale=0, elem_id="run-button")
226
 
 
227
  with gr.Accordion("Advanced Settings", open=False):
228
- negative_prompt = gr.Textbox(
229
- label="Negative prompt",
230
- max_lines=1,
231
- placeholder="Enter a negative prompt",
232
- visible=True,
233
- )
234
-
235
- seed = gr.Slider(
236
- label="Seed",
237
- minimum=0,
238
- maximum=MAX_SEED,
239
- step=1,
240
- value=0,
241
- )
242
-
243
- randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
244
 
245
  with gr.Row():
246
- width = gr.Slider(
247
- label="Width",
248
- minimum=256,
249
- maximum=MAX_IMAGE_SIZE,
250
- step=32,
251
- value=1024,
252
- )
253
-
254
- height = gr.Slider(
255
- label="Height",
256
- minimum=256,
257
- maximum=MAX_IMAGE_SIZE,
258
- step=32,
259
- value=1024,
260
- )
261
 
262
  with gr.Row():
263
- guidance_scale = gr.Slider(
264
- label="Guidance scale",
265
- minimum=0.0,
266
- maximum=10.0,
267
- step=0.1,
268
- value=7,
269
- )
270
-
271
- num_inference_steps = gr.Slider(
272
- label="Number of inference steps",
273
- minimum=1,
274
- maximum=50,
275
- step=1,
276
- value=35,
277
- )
278
-
279
- gr.Examples(
280
- examples=examples,
281
- inputs=[prompt]
282
- )
283
 
 
284
  run_button.click(
285
  infer,
286
  inputs=[prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps,
 
1
  import gradio as gr
2
  import numpy as np
3
  import random
4
+ import spaces # Uncomment if you're using ZeroGPU
5
  from diffusers import DiffusionPipeline
6
  import torch
7
  from tags import participant_tags, tribe_tags, role_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
 
15
  torch_dtype = torch.float32
16
 
17
  pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
18
+ pipe.to(device)
19
 
20
  MAX_SEED = np.iinfo(np.int32).max
21
  MAX_IMAGE_SIZE = 1024
22
 
 
 
 
 
 
 
23
 
24
+ @spaces.GPU # Uncomment if using ZeroGPU
25
+ def infer(
26
+ prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps,
27
+ selected_participant_tags, selected_tribe_tags, selected_role_tags, selected_skin_tone_tags, selected_body_type_tags,
28
+ selected_tattoo_tags, selected_piercing_tags, selected_expression_tags, selected_eye_tags, selected_hair_style_tags,
29
+ selected_position_tags, selected_fetish_tags, selected_location_tags, selected_camera_tags, selected_atmosphere_tags,
30
+ active_tab, progress=gr.Progress(track_tqdm=True)
31
+ ):
32
+ # Handle the active tab and generate the prompt accordingly
33
  if active_tab == "Prompt Input":
34
+ final_prompt = f"score_9, score_8_up, score_7_up, source_anime, {prompt}"
35
+ else:
36
+ tag_list = (
 
 
 
37
  [participant_tags[tag] for tag in selected_participant_tags] +
38
  [tribe_tags[tag] for tag in selected_tribe_tags] +
39
  [role_tags[tag] for tag in selected_role_tags] +
 
50
  [camera_tags[tag] for tag in selected_camera_tags] +
51
  [atmosphere_tags[tag] for tag in selected_atmosphere_tags]
52
  )
53
+ final_prompt = f"score_9, score_8_up, score_7_up, source_anime, {', '.join(tag_list)}"
 
54
 
55
+ # Concatenate additional negative prompts
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  additional_negatives = "worst quality, bad quality, jpeg artifacts, source_cartoon, 3d, (censor), monochrome, blurry, lowres, watermark"
57
  full_negative_prompt = f"{additional_negatives}, {negative_prompt}"
58
 
59
  if randomize_seed:
60
  seed = random.randint(0, MAX_SEED)
61
+ generator = torch.Generator(device=device).manual_seed(seed)
62
 
 
 
 
63
  image = pipe(
64
  prompt=final_prompt,
65
  negative_prompt=full_negative_prompt,
 
70
  generator=generator
71
  ).images[0]
72
 
73
+ return image, seed, f"Prompt: {final_prompt}\nNegative Prompt: {full_negative_prompt}"
 
 
74
 
 
 
 
 
 
75
 
76
  css = """
77
  #col-container {
78
  margin: 0 auto;
79
  max-width: 640px;
80
  }
 
 
 
81
  """
82
 
83
  with gr.Blocks(css=css) as demo:
 
84
  with gr.Column(elem_id="col-container"):
85
+ gr.Markdown("# Image Generator with Tags and Prompts")
86
 
 
87
  result = gr.Image(label="Result", show_label=False)
 
 
88
  prompt_info = gr.Textbox(label="Prompts Used", lines=3, interactive=False)
 
 
89
  active_tab = gr.State("Prompt Input")
90
 
 
91
  with gr.Tabs() as tabs:
92
+ # Prompt Input Tab
93
+ with gr.TabItem("Prompt Input"):
94
+ prompt = gr.Textbox(label="Prompt", placeholder="Enter your custom prompt")
95
+ tabs.select(lambda: "Prompt Input", inputs=None, outputs=active_tab)
 
 
 
 
 
96
 
97
+ # Straight Tab
98
+ with gr.TabItem("Straight"):
99
  selected_participant_tags = gr.CheckboxGroup(choices=list(participant_tags.keys()), label="Participant Tags")
100
  selected_tribe_tags = gr.CheckboxGroup(choices=list(tribe_tags.keys()), label="Tribe Tags")
101
  selected_role_tags = gr.CheckboxGroup(choices=list(role_tags.keys()), label="Role Tags")
 
111
  selected_location_tags = gr.CheckboxGroup(choices=list(location_tags.keys()), label="Location Tags")
112
  selected_camera_tags = gr.CheckboxGroup(choices=list(camera_tags.keys()), label="Camera Tags")
113
  selected_atmosphere_tags = gr.CheckboxGroup(choices=list(atmosphere_tags.keys()), label="Atmosphere Tags")
114
+ tabs.select(lambda: "Straight", inputs=None, outputs=active_tab)
115
+
116
+ # Gay Tab
117
+ with gr.TabItem("Gay"):
 
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")
120
  selected_role_tags = gr.CheckboxGroup(choices=list(role_tags.keys()), label="Role Tags")
 
130
  selected_location_tags = gr.CheckboxGroup(choices=list(location_tags.keys()), label="Location Tags")
131
  selected_camera_tags = gr.CheckboxGroup(choices=list(camera_tags.keys()), label="Camera Tags")
132
  selected_atmosphere_tags = gr.CheckboxGroup(choices=list(atmosphere_tags.keys()), label="Atmosphere Tags")
133
+ tabs.select(lambda: "Gay", inputs=None, outputs=active_tab)
134
 
135
+ # Lesbian Tab
136
+ with gr.TabItem("Lesbian"):
137
  selected_participant_tags = gr.CheckboxGroup(choices=list(participant_tags.keys()), label="Participant Tags")
138
  selected_tribe_tags = gr.CheckboxGroup(choices=list(tribe_tags.keys()), label="Tribe Tags")
139
  selected_role_tags = gr.CheckboxGroup(choices=list(role_tags.keys()), label="Role Tags")
 
149
  selected_location_tags = gr.CheckboxGroup(choices=list(location_tags.keys()), label="Location Tags")
150
  selected_camera_tags = gr.CheckboxGroup(choices=list(camera_tags.keys()), label="Camera Tags")
151
  selected_atmosphere_tags = gr.CheckboxGroup(choices=list(atmosphere_tags.keys()), label="Atmosphere Tags")
152
+ tabs.select(lambda: "Lesbian", inputs=None, outputs=active_tab)
 
 
 
153
 
154
+ # Advanced Settings
155
  with gr.Accordion("Advanced Settings", open=False):
156
+ negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="Enter negative prompt")
157
+ seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0)
158
+ randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
159
 
160
  with gr.Row():
161
+ width = gr.Slider(label="Width", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=1024)
162
+ height = gr.Slider(label="Height", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=1024)
 
 
 
 
 
 
 
 
 
 
 
 
 
163
 
164
  with gr.Row():
165
+ guidance_scale = gr.Slider(label="Guidance Scale", minimum=0.0, maximum=10.0, step=0.1, value=7)
166
+ num_inference_steps = gr.Slider(label="Number of Inference Steps", minimum=1, maximum=50, step=1, value=35)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
 
168
+ run_button = gr.Button("Run")
169
  run_button.click(
170
  infer,
171
  inputs=[prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps,