Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -141,72 +141,78 @@ def main():
|
|
141 |
|
142 |
predefined_tags = ["loli", "oppai_loli", "minigirl", "babydoll", "monochrome", "grayscale", "speech_bubble", "english_text", "copyright_name", "twitter_username", "artist_name", "watermark", "censored", "bar_censor", "blank_censor", "blur_censor", "light_censor", "mosaic_censoring"] # Default tags to filter out
|
143 |
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
)
|
153 |
-
|
154 |
-
|
155 |
-
model_repo = gr.Dropdown(
|
156 |
-
model_repos,
|
157 |
-
value=VIT_MODEL_DSV3_REPO,
|
158 |
-
label="Select Model",
|
159 |
-
)
|
160 |
-
general_thresh = gr.Slider(
|
161 |
-
0, 1, step=args.score_slider_step, value=args.score_general_threshold, label="General Tags Threshold"
|
162 |
-
)
|
163 |
-
character_thresh = gr.Slider(
|
164 |
-
0, 1, step=args.score_slider_step, value=args.score_character_threshold, label="Character Tags Threshold"
|
165 |
-
)
|
166 |
-
filter_tags = gr.Textbox(
|
167 |
-
value=", ".join(predefined_tags),
|
168 |
-
label="Filter Tags (comma-separated)",
|
169 |
-
placeholder="Add tags to filter out (e.g., winter, red, from above)",
|
170 |
-
lines=3
|
171 |
-
)
|
172 |
-
|
173 |
-
submit = gr.Button(value="Process Images", variant="primary")
|
174 |
-
|
175 |
-
with gr.Column():
|
176 |
-
outputs = gr.Column()
|
177 |
-
|
178 |
-
def process_images(files, model_repo, general_thresh, character_thresh, filter_tags):
|
179 |
-
images = [Image.open(file.name) for file in files]
|
180 |
-
results = predictor.predict(images, model_repo, general_thresh, character_thresh)
|
181 |
-
|
182 |
-
filter_set = set(tag.strip().lower() for tag in filter_tags.split(","))
|
183 |
-
|
184 |
-
prompts = []
|
185 |
-
for i, (general_tags, character_tags) in enumerate(results):
|
186 |
-
character_part = ", ".join(
|
187 |
-
tag.replace('_', ' ') for tag in character_tags if tag.lower() not in filter_set
|
188 |
)
|
189 |
-
|
190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
)
|
192 |
-
if character_part:
|
193 |
-
prompts.append(f"{character_part}, {general_part}")
|
194 |
-
else:
|
195 |
-
prompts.append(general_part)
|
196 |
-
|
197 |
-
# Return a list of prompts for each output
|
198 |
-
return [gr.Textbox.update(value=prompt, visible=True) for prompt in prompts]
|
199 |
-
|
200 |
-
submit.click(
|
201 |
-
process_images,
|
202 |
-
inputs=[image_files, model_repo, general_thresh, character_thresh, filter_tags],
|
203 |
-
outputs=[gr.Textbox(visible=False, label=f"Output {i + 1}") for i in range(10)],
|
204 |
-
)
|
205 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
)
|
207 |
|
208 |
demo.queue(max_size=10)
|
209 |
demo.launch()
|
210 |
|
211 |
if __name__ == "__main__":
|
212 |
-
main()
|
|
|
141 |
|
142 |
predefined_tags = ["loli", "oppai_loli", "minigirl", "babydoll", "monochrome", "grayscale", "speech_bubble", "english_text", "copyright_name", "twitter_username", "artist_name", "watermark", "censored", "bar_censor", "blank_censor", "blur_censor", "light_censor", "mosaic_censoring"] # Default tags to filter out
|
143 |
|
144 |
+
with gr.Blocks(title=TITLE) as demo:
|
145 |
+
gr.Markdown(f"<h1 style='text-align: center;'>{TITLE}</h1>")
|
146 |
+
gr.Markdown(DESCRIPTION)
|
147 |
+
|
148 |
+
with gr.Row():
|
149 |
+
with gr.Column():
|
150 |
+
image_files = gr.File(
|
151 |
+
file_types=["image"], label="Upload Images", file_count="multiple",
|
152 |
+
)
|
153 |
+
|
154 |
+
# Wrap the model selection and sliders in an Accordion
|
155 |
+
with gr.Accordion("Advanced Settings", open=False): # Collapsible by default
|
156 |
+
model_repo = gr.Dropdown(
|
157 |
+
model_repos,
|
158 |
+
value=VIT_MODEL_DSV3_REPO,
|
159 |
+
label="Select Model",
|
160 |
)
|
161 |
+
general_thresh = gr.Slider(
|
162 |
+
0, 1, step=args.score_slider_step, value=args.score_general_threshold, label="General Tags Threshold"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
)
|
164 |
+
character_thresh = gr.Slider(
|
165 |
+
0, 1, step=args.score_slider_step, value=args.score_character_threshold, label="Character Tags Threshold"
|
166 |
+
)
|
167 |
+
filter_tags = gr.Textbox(
|
168 |
+
value=", ".join(predefined_tags),
|
169 |
+
label="Filter Tags (comma-separated)",
|
170 |
+
placeholder="Add tags to filter out (e.g., winter, red, from above)",
|
171 |
+
lines=3
|
172 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
|
174 |
+
submit = gr.Button(
|
175 |
+
value="Process Images", variant="primary"
|
176 |
+
)
|
177 |
+
|
178 |
+
with gr.Column():
|
179 |
+
output = gr.Textbox(label="Output", lines=10)
|
180 |
+
|
181 |
+
def process_images(files, model_repo, general_thresh, character_thresh, filter_tags):
|
182 |
+
images = [Image.open(file.name) for file in files]
|
183 |
+
results = predictor.predict(images, model_repo, general_thresh, character_thresh)
|
184 |
+
|
185 |
+
# Parse filter tags
|
186 |
+
filter_set = set(tag.strip().lower() for tag in filter_tags.split(","))
|
187 |
+
|
188 |
+
# Generate formatted output
|
189 |
+
prompts = []
|
190 |
+
for i, (general_tags, character_tags) in enumerate(results):
|
191 |
+
# Replace underscores with spaces for both character and general tags
|
192 |
+
character_part = ", ".join(
|
193 |
+
tag.replace('_', ' ') for tag in character_tags if tag.lower() not in filter_set
|
194 |
+
)
|
195 |
+
general_part = ", ".join(
|
196 |
+
tag.replace('_', ' ') for tag in general_tags if tag.lower() not in filter_set
|
197 |
+
)
|
198 |
+
|
199 |
+
# Construct the prompt based on the presence of character_part
|
200 |
+
if character_part:
|
201 |
+
prompts.append(f"{character_part}, {general_part}")
|
202 |
+
else:
|
203 |
+
prompts.append(general_part)
|
204 |
+
|
205 |
+
# Join all prompts with blank lines
|
206 |
+
return "\n\n".join(prompts)
|
207 |
+
|
208 |
+
submit.click(
|
209 |
+
process_images,
|
210 |
+
inputs=[image_files, model_repo, general_thresh, character_thresh, filter_tags],
|
211 |
+
outputs=output
|
212 |
)
|
213 |
|
214 |
demo.queue(max_size=10)
|
215 |
demo.launch()
|
216 |
|
217 |
if __name__ == "__main__":
|
218 |
+
main()
|