John6666 commited on
Commit
962587f
·
verified ·
1 Parent(s): 1d13075

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +644 -283
app.py CHANGED
@@ -1,299 +1,660 @@
 
1
  import gradio as gr
2
- import requests
3
- from pathlib import Path
4
- import re
5
- import os
6
- import tempfile
7
- import shutil
8
- import urllib
9
- from huggingface_hub import whoami, HfApi, hf_hub_download, RepoCard
10
- from huggingface_hub.utils import build_hf_headers, hf_raise_for_status
11
- from gradio_huggingfacehub_search import HuggingfaceHubSearch
12
-
13
- ENDPOINT = "https://huggingface.co"
14
- # ENDPOINT = "http://localhost:5564"
15
-
16
- REPO_TYPES = ["model", "dataset", "space"]
17
- HF_REPO = os.environ.get("HF_REPO") if os.environ.get("HF_REPO") else "" # set your default repo
18
- HF_REPO_PREFIX = os.environ.get("HF_REPO_PREFIX") if os.environ.get("HF_REPO_PREFIX") else "" # set your default repo prefix
19
- HF_REPO_SUFFIX = os.environ.get("HF_REPO_SUFFIX") if os.environ.get("HF_REPO_SUFFIX") else "" # set your default repo suffix
20
- HF_USER = os.environ.get("HF_USER") if os.environ.get("HF_USER") else "" # set your username
21
- REGEX_HF_REPO = r'^[\w_\-\.]+/[\w_\-\.]+$'
22
-
23
- def remove_repo_tags(repo_id: str, tags: list[str], repo_type: str, hf_token: str):
24
- try:
25
- card = RepoCard.load(repo_id, repo_type=repo_type, token=hf_token)
26
- orig_content = card.content
27
- for tag in tags:
28
- if 'tags' in card.data and tag in card.data['tags']: card.data['tags'].remove(tag)
29
- if card.content == orig_content: return
30
- card.push_to_hub(repo_id=repo_id, repo_type=repo_type, token=hf_token)
31
- except Exception as e:
32
- print(f"Failed to remove tags from repocard. {e}")
33
-
34
- def duplicate(source_repo, dst_repo, repo_type, private, overwrite, auto_dir, remove_tag, oauth_token: gr.OAuthToken | None, progress=gr.Progress(track_tqdm=True)):
35
- hf_token = oauth_token.token
36
- api = HfApi(token=hf_token)
37
- try:
38
- if not repo_type in REPO_TYPES:
39
- raise ValueError("need to select valid repo type")
40
- _ = whoami(oauth_token.token)
41
- # ^ this will throw if token is invalid
42
- except Exception as e:
43
- raise gr.Error(f"""Oops, you forgot to login. Please use the loggin button on the top left to migrate your repo {e}""")
44
-
45
- try:
46
- if re.fullmatch(REGEX_HF_REPO, source_repo): target = ""
47
- else:
48
- source_repo, target = re.findall(r'^(?:http.+\.co/)?(?:datasets)?(?:spaces)?([\w_\-\.]+/[\w_\-\.]+)/?(?:blob/main/)?(?:resolve/main/)?(.+)?$', source_repo)[0]
49
- target = urllib.parse.unquote(target.removesuffix("/"))
50
-
51
- if re.fullmatch(REGEX_HF_REPO, dst_repo): subfolder = ""
52
- else:
53
- dst_repo, subfolder = re.findall(r'^([\w_\-\.]+/[\w_\-\.]+)/?(.+)?$', dst_repo)[0]
54
- subfolder = subfolder.removesuffix("/")
55
- if auto_dir: subfolder = source_repo
56
-
57
- if not overwrite and api.repo_exists(repo_id=dst_repo, repo_type=repo_type, token=hf_token): raise gr.Error(f"Repo already exists {dst_repo}")
58
-
59
- if overwrite or subfolder:
60
- temp_dir = tempfile.mkdtemp()
61
- api.create_repo(repo_id=dst_repo, repo_type=repo_type, private=private, exist_ok=True, token=hf_token)
62
- for path in api.list_repo_files(repo_id=source_repo, repo_type=repo_type, token=hf_token):
63
- if target and target not in path: continue
64
- file = hf_hub_download(repo_id=source_repo, filename=path, repo_type=repo_type, local_dir=temp_dir, token=hf_token)
65
- if not Path(file).exists(): continue
66
- if Path(file).is_dir(): # unused for now
67
- api.upload_folder(repo_id=dst_repo, folder_path=file, path_in_repo=f"{subfolder}/{path}" if subfolder else path, repo_type=repo_type, token=hf_token)
68
- elif Path(file).is_file():
69
- api.upload_file(repo_id=dst_repo, path_or_fileobj=file, path_in_repo=f"{subfolder}/{path}" if subfolder else path, repo_type=repo_type, token=hf_token)
70
- if Path(file).exists(): Path(file).unlink()
71
- if repo_type == "dataset": repo_url = f"https://huggingface.co/datasets/{dst_repo}"
72
- elif repo_type == "space": repo_url = f"https://huggingface.co/spaces/{dst_repo}"
73
- else: repo_url = f"https://huggingface.co/{dst_repo}"
74
- shutil.rmtree(temp_dir)
75
- else:
76
- r = requests.post(
77
- f"{ENDPOINT}/api/{repo_type}s/{source_repo}/duplicate",
78
- headers=build_hf_headers(token=oauth_token.token),
79
- json={"repository": dst_repo, "private": private},
80
- )
81
- hf_raise_for_status(r)
82
-
83
- repo_url = r.json().get("url")
84
-
85
- if remove_tag: remove_repo_tags(dst_repo, ["not-for-all-audiences"], repo_type, hf_token)
86
-
87
- return (
88
- f'Find your repo <a href=\'{repo_url}\' target="_blank" style="text-decoration:underline">here</a>',
89
- "sp.jpg",
90
- )
91
-
92
- except Exception as e:
93
- print(e)
94
- raise gr.Error(f"Error occured: {e}")
95
-
96
- def parse_repos(s):
97
- repo_pattern = r'[^\w_\-\.]?([\w_\-\.]+/[\w_\-\.]+)[^\w_\-\.]?'
98
- try:
99
- s = re.sub("https?://[\\w/:%#\\$&\\?\\(\\)~\\.=\\+\\-]+", "", s)
100
- repos = re.findall(repo_pattern, s)
101
- return list(repos)
102
- except Exception:
103
- return []
104
-
105
- def duplicate_m2o(source_repos_str, dst_repo, repo_type, private, overwrite, oauth_token: gr.OAuthToken | None, progress=gr.Progress(track_tqdm=True)):
106
- hf_token = oauth_token.token
107
- api = HfApi(token=hf_token)
108
- try:
109
- if not repo_type in REPO_TYPES:
110
- raise ValueError("need to select valid repo type")
111
- _ = whoami(oauth_token.token)
112
- # ^ this will throw if token is invalid
113
- except Exception as e:
114
- raise gr.Error(f"""Oops, you forgot to login. Please use the loggin button on the top left to migrate your repo {e}""")
115
-
116
- try:
117
- if re.fullmatch(REGEX_HF_REPO, dst_repo): subfolder_prefix = ""
118
- else:
119
- dst_repo, subfolder_prefix = re.findall(r'^([\w_\-\.]+/[\w_\-\.]+)/?(.+)?$', dst_repo)[0]
120
- subfolder_prefix = subfolder.removesuffix("/")
121
- if not overwrite and api.repo_exists(repo_id=dst_repo, repo_type=repo_type, token=hf_token): raise gr.Error(f"Repo already exists {dst_repo}")
122
- source_repos = parse_repos(source_repos_str)
123
- for source_repo in source_repos:
124
- if re.fullmatch(REGEX_HF_REPO, source_repo): target = ""
125
- else:
126
- source_repo, target = re.findall(r'^(?:http.+\.co/)?(?:datasets)?(?:spaces)?([\w_\-\.]+/[\w_\-\.]+)/?(?:blob/main/)?(?:resolve/main/)?(.+)?$', source_repo)[0]
127
- target = urllib.parse.unquote(target.removesuffix("/"))
128
-
129
- subfolder = subfolder_prefix + "/" + source_repo if subfolder_prefix else source_repo
130
-
131
- temp_dir = tempfile.mkdtemp()
132
- api.create_repo(repo_id=dst_repo, repo_type=repo_type, private=private, exist_ok=True, token=hf_token)
133
- for path in api.list_repo_files(repo_id=source_repo, repo_type=repo_type, token=hf_token):
134
- if target and target not in path: continue
135
- file = hf_hub_download(repo_id=source_repo, filename=path, repo_type=repo_type, local_dir=temp_dir, token=hf_token)
136
- if not Path(file).exists(): continue
137
- if Path(file).is_dir(): # unused for now
138
- api.upload_folder(repo_id=dst_repo, folder_path=file, path_in_repo=f"{subfolder}/{path}" if subfolder else path, repo_type=repo_type, token=hf_token)
139
- elif Path(file).is_file():
140
- api.upload_file(repo_id=dst_repo, path_or_fileobj=file, path_in_repo=f"{subfolder}/{path}" if subfolder else path, repo_type=repo_type, token=hf_token)
141
- if Path(file).exists(): Path(file).unlink()
142
- if repo_type == "dataset": repo_url = f"https://huggingface.co/datasets/{dst_repo}"
143
- elif repo_type == "space": repo_url = f"https://huggingface.co/spaces/{dst_repo}"
144
- else: repo_url = f"https://huggingface.co/{dst_repo}"
145
- shutil.rmtree(temp_dir)
146
-
147
- return (
148
- f'Find your repo <a href=\'{repo_url}\' target="_blank" style="text-decoration:underline">here</a>',
149
- "sp.jpg",
150
- )
151
 
152
- except Exception as e:
153
- print(e)
154
- raise gr.Error(f"Error occured: {e}")
155
-
156
- def duplicate_m2m(source_repos_str, hf_user, repo_type, private, overwrite, remove_tag, repo_prefix, repo_suffix, oauth_token: gr.OAuthToken | None, progress=gr.Progress(track_tqdm=True)):
157
- hf_token = oauth_token.token
158
- api = HfApi(token=hf_token)
159
- try:
160
- if not repo_type in REPO_TYPES:
161
- raise ValueError("need to select valid repo type")
162
- _ = whoami(oauth_token.token)
163
- # ^ this will throw if token is invalid
164
- except Exception as e:
165
- raise gr.Error(f"""Oops, you forgot to login. Please use the loggin button on the top left to migrate your repo {e}""")
166
-
167
- try:
168
- source_repos = parse_repos(source_repos_str)
169
- repo_url_result = 'Find your repo '
170
- for source_repo in source_repos:
171
- if not re.fullmatch(REGEX_HF_REPO, source_repo) or not api.repo_exists(repo_id=source_repo, repo_type=repo_type, token=hf_token): continue
172
- dst_repo = hf_user + "/" + repo_prefix + source_repo.split("/")[-1] + repo_suffix
173
- if not re.fullmatch(REGEX_HF_REPO, dst_repo): continue
174
- if not overwrite and api.repo_exists(repo_id=dst_repo, repo_type=repo_type, token=hf_token):
175
- gr.Info(f"Repo already exists {dst_repo}")
176
- continue
177
-
178
- r = requests.post(
179
- f"{ENDPOINT}/api/{repo_type}s/{source_repo}/duplicate",
180
- headers=build_hf_headers(token=oauth_token.token),
181
- json={"repository": dst_repo, "private": private},
182
- )
183
- hf_raise_for_status(r)
184
-
185
- repo_url = r.json().get("url")
186
- repo_url_result += f'<a href=\'{repo_url}\' target="_blank" style="text-decoration:underline">{dst_repo}</a><br>\n'
187
-
188
- if remove_tag: remove_repo_tags(dst_repo, ["not-for-all-audiences"], repo_type, hf_token)
189
-
190
- return (
191
- repo_url_result,
192
- "sp.jpg",
193
- )
194
 
195
- except Exception as e:
196
- print(e)
197
- raise gr.Error(f"Error occured: {e}")
198
 
199
- def add_repo_text(repo_id: str, source_repos: str):
200
- return source_repos + "\n" + repo_id if source_repos else repo_id
 
201
 
202
- def swap_visibilty(profile: gr.OAuthProfile | None):
203
- return gr.update(elem_classes=["main_ui_logged_in"]) if profile else gr.update(elem_classes=["main_ui_logged_out"])
 
 
 
 
 
 
 
204
 
205
- css = '''
206
- .main_ui_logged_out{opacity: 0.3; pointer-events: none}
207
- .title {text-align: center; align-items: center}
208
- '''
209
- with gr.Blocks(css=css) as demo:
210
- gr.LoginButton()
211
- with gr.Column(elem_classes="main_ui_logged_out") as main_ui:
212
- gr.Markdown("# Duplicate your repo!", elem_classes="title")
213
- gr.Markdown("Duplicate a Hugging Face repository! This Space is a an experimental demo.")
214
- with gr.Tab("One to One"):
215
  with gr.Row():
216
- with gr.Column():
217
- search = HuggingfaceHubSearch(
218
- label="source_repo",
219
- placeholder="Source repository (e.g. osanseviero/src)",
220
- search_type=["model", "dataset", "space"],
221
- sumbit_on_select=False,
222
- )
223
- with gr.Group():
224
- dst_repo = gr.Textbox(label="dst_repo", placeholder="Destination repository (e.g. osanseviero/dst)", value=HF_REPO)
225
- repo_type = gr.Dropdown(label="repo_type", choices=REPO_TYPES, value="model")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
  with gr.Row():
227
- is_private = gr.Checkbox(label="Make new repo private?", value=True)
228
- is_overwrite = gr.Checkbox(label="Overwrite existing repo?", value=True)
229
- is_subdir = gr.Checkbox(label="Create subdirectories automatically?", value=True)
230
- is_remtag = gr.Checkbox(label="Remove NFAA tag?", value=True)
231
  with gr.Row():
232
- submit_button = gr.Button("Submit", variant="primary")
233
- clear_button = gr.Button("Clear", variant="secondary")
234
- with gr.Column():
235
- output_md = gr.Markdown(label="output")
236
- output_image = gr.Image(show_label=False)
237
- with gr.Tab("Multi to One"):
238
- with gr.Row():
239
- with gr.Column():
240
- m2o_search = HuggingfaceHubSearch(
241
- label="source_repo",
242
- placeholder="Source repository (e.g. osanseviero/src)",
243
- search_type=["model", "dataset", "space"],
244
- sumbit_on_select=True,
245
- )
246
- m2o_source_repos = gr.Textbox(label="source_repos", placeholder="Source repositories (e.g. osanseviero/src)\n...", value="", lines=10)
247
- with gr.Group():
248
- m2o_dst_repo = gr.Textbox(label="dst_repo", placeholder="Destination repository (e.g. osanseviero/dst)", value=HF_REPO)
249
- m2o_repo_type = gr.Dropdown(label="repo_type", choices=REPO_TYPES, value="model")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
250
  with gr.Row():
251
- m2o_is_private = gr.Checkbox(label="Make new repo private?", value=True)
252
- m2o_is_overwrite = gr.Checkbox(label="Overwrite existing repo?", value=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  with gr.Row():
254
- m2o_submit_button = gr.Button("Submit", variant="primary")
255
- m2o_clear_button = gr.Button("Clear", variant="secondary")
256
- with gr.Column():
257
- m2o_output_md = gr.Markdown(label="output")
258
- m2o_output_image = gr.Image(show_label=False)
259
- with gr.Tab("Multi to Multi"):
260
- with gr.Row():
261
- with gr.Column():
262
- m2m_search = HuggingfaceHubSearch(
263
- label="source_repo",
264
- placeholder="Source repository (e.g. osanseviero/src)",
265
- search_type=["model", "dataset", "space"],
266
- sumbit_on_select=True,
267
- )
268
- m2m_source_repos = gr.Textbox(label="source_repos", placeholder="Source repositories (e.g. osanseviero/src)\n...", value="", lines=10)
269
- with gr.Group():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
270
  with gr.Row():
271
- m2m_user = gr.Textbox(label="hf_user", placeholder="Your HF username", value=HF_USER)
272
- m2m_prefix = gr.Textbox(label="repo_prefix", value=HF_REPO_PREFIX)
273
- m2m_suffix = gr.Textbox(label="repo_suffix", value=HF_REPO_SUFFIX)
274
- m2m_repo_type = gr.Dropdown(label="repo_type", choices=REPO_TYPES, value="model")
 
275
  with gr.Row():
276
- m2m_is_private = gr.Checkbox(label="Make new repo private?", value=True)
277
- m2m_is_overwrite = gr.Checkbox(label="Overwrite existing repo?", value=False)
278
- m2m_is_remtag = gr.Checkbox(label="Remove NFAA tag?", value=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
279
  with gr.Row():
280
- m2m_submit_button = gr.Button("Submit", variant="primary")
281
- m2m_clear_button = gr.Button("Clear", variant="secondary")
282
- with gr.Column():
283
- m2m_output_md = gr.Markdown(label="output")
284
- m2m_output_image = gr.Image(show_label=False)
285
- demo.load(fn=swap_visibilty, outputs=main_ui)
286
- submit_button.click(duplicate, [search, dst_repo, repo_type, is_private, is_overwrite, is_subdir, is_remtag], [output_md, output_image])
287
- clear_button.click(lambda: ("", HF_REPO, "model", True, True, True, True), None, [search, dst_repo, repo_type, is_private, is_overwrite, is_subdir, is_remtag], queue=False)
288
- m2o_search.submit(add_repo_text, [m2o_search, m2o_source_repos], [m2o_source_repos], queue=False)
289
- m2o_submit_button.click(duplicate_m2o, [m2o_source_repos, m2o_dst_repo, m2o_repo_type, m2o_is_private, m2o_is_overwrite], [m2o_output_md, m2o_output_image])
290
- m2o_clear_button.click(lambda: ("", HF_REPO, "model", True, True, ""), None,
291
- [m2o_search, m2o_dst_repo, m2o_repo_type, m2o_is_private, m2o_is_overwrite, m2o_source_repos], queue=False)
292
- m2m_search.submit(add_repo_text, [m2m_search, m2m_source_repos], [m2m_source_repos], queue=False)
293
- m2m_submit_button.click(duplicate_m2m, [m2m_source_repos, m2m_user, m2m_repo_type, m2m_is_private, m2m_is_overwrite, m2m_is_remtag, m2m_prefix, m2m_suffix],
294
- [m2m_output_md, m2m_output_image])
295
- m2m_clear_button.click(lambda: ("", HF_USER, "model", True, False, True, "", HF_REPO_PREFIX, HF_REPO_SUFFIX), None,
296
- [m2m_search, m2m_user, m2m_repo_type, m2m_is_private, m2m_is_overwrite, m2m_is_remtag, m2m_source_repos, m2m_prefix, m2m_suffix], queue=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297
 
298
  demo.queue()
299
- demo.launch()
 
1
+ import spaces
2
  import gradio as gr
3
+ import numpy as np
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
+ # DiffuseCraft
6
+ from dc import (infer, _infer, pass_result, get_diffusers_model_list, get_samplers, save_image_history,
7
+ get_vaes, enable_diffusers_model_detail, extract_exif_data, esrgan_upscale, UPSCALER_KEYS,
8
+ preset_quality, preset_styles, process_style_prompt, get_all_lora_tupled_list, update_loras, apply_lora_prompt,
9
+ download_my_lora, search_civitai_lora, update_civitai_selection, select_civitai_lora, search_civitai_lora_json,
10
+ get_t2i_model_info, get_civitai_tag, CIVITAI_SORT, CIVITAI_PERIOD, CIVITAI_BASEMODEL,
11
+ SCHEDULE_TYPE_OPTIONS, SCHEDULE_PREDICTION_TYPE_OPTIONS, preprocessor_tab, SDXL_TASK, TASK_MODEL_LIST,
12
+ PROMPT_W_OPTIONS, POST_PROCESSING_SAMPLER, IP_ADAPTERS_SD, IP_ADAPTERS_SDXL, DIFFUSERS_CONTROLNET_MODEL,
13
+ TASK_AND_PREPROCESSORS, update_task_options, change_preprocessor_choices, get_ti_choices,
14
+ update_textual_inversion, set_textual_inversion_prompt, create_mask_now)
15
+ # Translator
16
+ from llmdolphin import (dolphin_respond_auto, dolphin_parse_simple,
17
+ get_llm_formats, get_dolphin_model_format, get_dolphin_models,
18
+ get_dolphin_model_info, select_dolphin_model, select_dolphin_format, get_dolphin_sysprompt)
19
+ # Tagger
20
+ from tagger.v2 import v2_upsampling_prompt, V2_ALL_MODELS
21
+ from tagger.utils import (gradio_copy_text, gradio_copy_prompt, COPY_ACTION_JS,
22
+ V2_ASPECT_RATIO_OPTIONS, V2_RATING_OPTIONS, V2_LENGTH_OPTIONS, V2_IDENTITY_OPTIONS)
23
+ from tagger.tagger import (predict_tags_wd, convert_danbooru_to_e621_prompt,
24
+ remove_specific_prompt, insert_recom_prompt, compose_prompt_to_copy,
25
+ translate_prompt, select_random_character)
26
+ from tagger.fl2sd3longcap import predict_tags_fl2_sd3
27
+ def description_ui():
28
+ gr.Markdown(
29
+ """
30
+ ## Danbooru Tags Transformer V2 Demo with WD Tagger & SD3 Long Captioner
31
+ (Image =>) Prompt => Upsampled longer prompt
32
+ - Mod of p1atdev's [Danbooru Tags Transformer V2 Demo](https://huggingface.co/spaces/p1atdev/danbooru-tags-transformer-v2) and [WD Tagger with 🤗 transformers](https://huggingface.co/spaces/p1atdev/wd-tagger-transformers).
33
+ - Models: p1atdev's [wd-swinv2-tagger-v3-hf](https://huggingface.co/p1atdev/wd-swinv2-tagger-v3-hf), [dart-v2-moe-sft](https://huggingface.co/p1atdev/dart-v2-moe-sft), [dart-v2-sft](https://huggingface.co/p1atdev/dart-v2-sft)\
34
+ , gokaygokay's [Florence-2-SD3-Captioner](https://huggingface.co/gokaygokay/Florence-2-SD3-Captioner)
35
+ """
36
+ )
 
 
 
 
 
 
 
 
 
 
37
 
 
 
 
38
 
39
+ MAX_SEED = np.iinfo(np.int32).max
40
+ MAX_IMAGE_SIZE = 4096
41
+ MIN_IMAGE_SIZE = 256
42
 
43
+ css = """
44
+ #container { margin: 0 auto; !important; }
45
+ #col-container { margin: 0 auto; !important; }
46
+ #result { max-width: 520px; max-height: 520px; margin: 0px auto; !important; }
47
+ .lora { min-width: 480px; !important; }
48
+ .title { font-size: 3em; align-items: center; text-align: center; }
49
+ .info { align-items: center; text-align: center; }
50
+ .desc [src$='#float'] { float: right; margin: 20px; }
51
+ """
52
 
53
+ with gr.Blocks(fill_width=True, elem_id="container", css=css, delete_cache=(60, 3600)) as demo:
54
+ gr.Markdown("# Votepurchase Multiple Model", elem_classes="title")
55
+ state = gr.State(value={})
56
+ with gr.Tab("Image Generator"):
57
+ with gr.Column(elem_id="col-container"):
 
 
 
 
 
58
  with gr.Row():
59
+ prompt = gr.Text(label="Prompt", show_label=False, lines=1, max_lines=8, placeholder="Enter your prompt", container=False)
60
+
61
+ with gr.Row():
62
+ run_button = gr.Button("Run", variant="primary", scale=5)
63
+ run_translate_button = gr.Button("Run with LLM Enhance", variant="secondary", scale=3)
64
+ auto_trans = gr.Checkbox(label="Auto translate to English", value=False, scale=2)
65
+
66
+ result = gr.Image(label="Result", elem_id="result", format="png", type="filepath", show_label=False, interactive=False,
67
+ show_download_button=True, show_share_button=False, container=True)
68
+
69
+ with gr.Accordion("History", open=False):
70
+ history_files = gr.Files(interactive=False, visible=False)
71
+ history_gallery = gr.Gallery(label="History", columns=6, object_fit="contain", format="png", interactive=False, show_share_button=False,
72
+ show_download_button=True)
73
+ history_clear_button = gr.Button(value="Clear History", variant="secondary")
74
+ history_clear_button.click(lambda: ([], []), None, [history_gallery, history_files], queue=False, show_api=False)
75
+
76
+ with gr.Accordion("Advanced Settings", open=True):
77
+ task = gr.Dropdown(label="Task", choices=SDXL_TASK, value=TASK_MODEL_LIST[0])
78
+ with gr.Tab("Generation Settings"):
79
+ with gr.Row():
80
+ negative_prompt = gr.Text(label="Negative prompt", lines=1, max_lines=6, placeholder="Enter a negative prompt", show_copy_button=True,
81
+ value="(low quality, worst quality:1.2), very displeasing, watermark, signature, ugly")
82
+ with gr.Accordion("Prompt Settings", open=False):
83
+ with gr.Row():
84
+ quality_selector = gr.Radio(label="Quality Tag Presets", interactive=True, choices=list(preset_quality.keys()), value="None", scale=3)
85
+ style_selector = gr.Radio(label="Style Presets", interactive=True, choices=list(preset_styles.keys()), value="None", scale=3)
86
  with gr.Row():
87
+ recom_prompt = gr.Checkbox(label="Recommended prompt", value=True, scale=1)
88
+ prompt_syntax = gr.Dropdown(label="Prompt Syntax", choices=PROMPT_W_OPTIONS, value=PROMPT_W_OPTIONS[1][1])
 
 
89
  with gr.Row():
90
+ seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0)
91
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
92
+ gpu_duration = gr.Slider(label="GPU time duration (seconds)", minimum=5, maximum=240, value=59)
93
+ with gr.Row():
94
+ width = gr.Slider(label="Width", minimum=MIN_IMAGE_SIZE, maximum=MAX_IMAGE_SIZE, step=32, value=1024) # 832
95
+ height = gr.Slider(label="Height", minimum=MIN_IMAGE_SIZE, maximum=MAX_IMAGE_SIZE, step=32, value=1024) # 1216
96
+ guidance_scale = gr.Slider(label="Guidance scale", minimum=0.0, maximum=30.0, step=0.1, value=7)
97
+ guidance_rescale = gr.Slider(label="CFG rescale", value=0., step=0.01, minimum=0., maximum=1.5)
98
+ with gr.Row():
99
+ num_inference_steps = gr.Slider(label="Number of inference steps", minimum=1, maximum=100, step=1, value=28)
100
+ pag_scale = gr.Slider(minimum=0.0, maximum=10.0, step=0.1, value=0.0, label="PAG Scale")
101
+ clip_skip = gr.Checkbox(value=True, label="Layer 2 Clip Skip")
102
+ free_u = gr.Checkbox(value=False, label="FreeU")
103
+ with gr.Row():
104
+ sampler = gr.Dropdown(label="Sampler", choices=get_samplers(), value="Euler")
105
+ schedule_type = gr.Dropdown(label="Schedule type", choices=SCHEDULE_TYPE_OPTIONS, value=SCHEDULE_TYPE_OPTIONS[0])
106
+ schedule_prediction_type = gr.Dropdown(label="Discrete Sampling Type", choices=SCHEDULE_PREDICTION_TYPE_OPTIONS, value=SCHEDULE_PREDICTION_TYPE_OPTIONS[0])
107
+ vae_model = gr.Dropdown(label="VAE Model", choices=get_vaes(), value=get_vaes()[0])
108
+ with gr.Accordion("Other Settings", open=False):
109
+ with gr.Accordion("Textual inversion", open=True):
110
+ active_textual_inversion = gr.Checkbox(value=False, label="Active Textual Inversion in prompt")
111
+ use_textual_inversion = gr.CheckboxGroup(choices=get_ti_choices(model_name.value) if active_textual_inversion.value else [], value=None, label="Use Textual Invertion in prompt")
112
+ with gr.Row():
113
+ with gr.Column(scale=4):
114
+ model_name = gr.Dropdown(label="Model", info="You can enter a huggingface model repo_id to want to use.",
115
+ choices=get_diffusers_model_list(), value=get_diffusers_model_list()[0],
116
+ allow_custom_value=True, interactive=True, min_width=320)
117
+ model_info = gr.Markdown(elem_classes="info")
118
+ with gr.Column(scale=1):
119
+ model_detail = gr.Checkbox(label="Show detail of model in list", value=False)
120
+
121
+ with gr.Tab("LoRA"):
122
+ def lora_dropdown(label, visible=True):
123
+ return gr.Dropdown(label=label, choices=get_all_lora_tupled_list(), value="", allow_custom_value=True, elem_classes="lora", min_width=320, visible=visible)
124
+
125
+ def lora_scale_slider(label, visible=True):
126
+ return gr.Slider(minimum=-2, maximum=2, step=0.01, value=1.00, label=label, visible=visible)
127
+
128
+ def lora_textbox():
129
+ return gr.Textbox(label="", info="Example of prompt:", value="", show_copy_button=True, interactive=False, visible=False)
130
+
131
+ with gr.Row():
132
+ with gr.Column():
133
+ with gr.Row():
134
+ lora1 = lora_dropdown("LoRA 1")
135
+ lora1_wt = lora_scale_slider("LoRA 1: weight")
136
+ with gr.Row():
137
+ lora1_info = lora_textbox()
138
+ lora1_copy = gr.Button(value="Copy example to prompt", visible=False)
139
+ lora1_md = gr.Markdown(value="", visible=False)
140
+ with gr.Column():
141
+ with gr.Row():
142
+ lora2 = lora_dropdown("LoRA 2")
143
+ lora2_wt = lora_scale_slider("LoRA 2: weight")
144
+ with gr.Row():
145
+ lora2_info = lora_textbox()
146
+ lora2_copy = gr.Button(value="Copy example to prompt", visible=False)
147
+ lora2_md = gr.Markdown(value="", visible=False)
148
+ with gr.Column():
149
+ with gr.Row():
150
+ lora3 = lora_dropdown("LoRA 3")
151
+ lora3_wt = lora_scale_slider("LoRA 3: weight")
152
+ with gr.Row():
153
+ lora3_info = lora_textbox()
154
+ lora3_copy = gr.Button(value="Copy example to prompt", visible=False)
155
+ lora3_md = gr.Markdown(value="", visible=False)
156
+ with gr.Column():
157
+ with gr.Row():
158
+ lora4 = lora_dropdown("LoRA 4")
159
+ lora4_wt = lora_scale_slider("LoRA 4: weight")
160
+ with gr.Row():
161
+ lora4_info = lora_textbox()
162
+ lora4_copy = gr.Button(value="Copy example to prompt", visible=False)
163
+ lora4_md = gr.Markdown(value="", visible=False)
164
+ with gr.Column():
165
+ with gr.Row():
166
+ lora5 = lora_dropdown("LoRA 5")
167
+ lora5_wt = lora_scale_slider("LoRA 5: weight")
168
+ with gr.Row():
169
+ lora5_info = lora_textbox()
170
+ lora5_copy = gr.Button(value="Copy example to prompt", visible=False)
171
+ lora5_md = gr.Markdown(value="", visible=False)
172
+ with gr.Column():
173
+ with gr.Row():
174
+ lora6 = lora_dropdown("LoRA 6", visible=False)
175
+ lora6_wt = lora_scale_slider("LoRA 6: weight", visible=False)
176
+ with gr.Row():
177
+ lora6_info = lora_textbox()
178
+ lora6_copy = gr.Button(value="Copy example to prompt", visible=False)
179
+ lora6_md = gr.Markdown(value="", visible=False)
180
+ with gr.Column():
181
+ with gr.Row():
182
+ lora7 = lora_dropdown("LoRA 7", visible=False)
183
+ lora7_wt = lora_scale_slider("LoRA 7: weight", visible=False)
184
+ with gr.Row():
185
+ lora7_info = lora_textbox()
186
+ lora7_copy = gr.Button(value="Copy example to prompt", visible=False)
187
+ lora7_md = gr.Markdown(value="", visible=False)
188
+ with gr.Accordion("From URL", open=True, visible=True):
189
  with gr.Row():
190
+ lora_search_civitai_basemodel = gr.CheckboxGroup(label="Search LoRA for", choices=CIVITAI_BASEMODEL, value=["Pony", "Illustrious", "SDXL 1.0"])
191
+ lora_search_civitai_sort = gr.Radio(label="Sort", choices=CIVITAI_SORT, value="Highest Rated")
192
+ lora_search_civitai_period = gr.Radio(label="Period", choices=CIVITAI_PERIOD, value="AllTime")
193
+ with gr.Row():
194
+ lora_search_civitai_query = gr.Textbox(label="Query", placeholder="oomuro sakurako...", lines=1)
195
+ lora_search_civitai_tag = gr.Dropdown(label="Tag", choices=get_civitai_tag(), value=get_civitai_tag()[0], allow_custom_value=True)
196
+ lora_search_civitai_user = gr.Textbox(label="Username", lines=1)
197
+ lora_search_civitai_submit = gr.Button("Search on Civitai")
198
+ with gr.Row():
199
+ lora_search_civitai_json = gr.JSON(value={}, visible=False)
200
+ lora_search_civitai_desc = gr.Markdown(value="", visible=False, elem_classes="desc")
201
+ with gr.Accordion("Select from Gallery", open=False):
202
+ lora_search_civitai_gallery = gr.Gallery([], label="Results", allow_preview=False, columns=5, show_share_button=False, interactive=False)
203
+ lora_search_civitai_result = gr.Dropdown(label="Search Results", choices=[("", "")], value="", allow_custom_value=True, visible=False)
204
+ lora_download_url = gr.Textbox(label="LoRA's download URL", placeholder="https://civitai.com/api/download/models/28907", info="It has to be .safetensors files, and you can also download them from Hugging Face.", lines=1)
205
+ lora_download = gr.Button("Get and set LoRA and apply to prompt")
206
+
207
+ with gr.Tab("ControlNet / Img2img / Inpaint"):
208
  with gr.Row():
209
+ #image_control = gr.Image(label="Image ControlNet / Inpaint / Img2img", type="filepath", height=384, sources=["upload", "clipboard", "webcam"], show_share_button=False)
210
+ image_control = gr.ImageEditor(label="Image ControlNet / Inpaint / Img2img", type="filepath", sources=["upload", "clipboard", "webcam"], image_mode='RGB',
211
+ show_share_button=False, show_fullscreen_button=False, layers=False, canvas_size=(384, 384), width=384, height=512,
212
+ brush=gr.Brush(colors=["#FFFFFF"], color_mode="fixed", default_size=32), eraser=gr.Eraser(default_size="32"))
213
+ image_mask = gr.Image(label="Image Mask", type="filepath", height=384, sources=["upload", "clipboard"], show_share_button=False)
214
+ with gr.Row():
215
+ strength = gr.Slider(minimum=0.01, maximum=1.0, step=0.01, value=0.55, label="Strength",
216
+ info="This option adjusts the level of changes for img2img and inpainting.")
217
+ image_resolution = gr.Slider(minimum=64, maximum=2048, step=64, value=1024, label="Image Resolution",
218
+ info="The maximum proportional size of the generated image based on the uploaded image.")
219
+ with gr.Row():
220
+ controlnet_model = gr.Dropdown(label="ControlNet model", choices=DIFFUSERS_CONTROLNET_MODEL, value=DIFFUSERS_CONTROLNET_MODEL[0])
221
+ control_net_output_scaling = gr.Slider(minimum=0, maximum=5.0, step=0.1, value=1, label="ControlNet Output Scaling in UNet")
222
+ control_net_start_threshold = gr.Slider(minimum=0, maximum=1, step=0.01, value=0, label="ControlNet Start Threshold (%)")
223
+ control_net_stop_threshold = gr.Slider(minimum=0, maximum=1, step=0.01, value=1, label="ControlNet Stop Threshold (%)")
224
+ with gr.Row():
225
+ preprocessor_name = gr.Dropdown(label="Preprocessor Name", choices=TASK_AND_PREPROCESSORS["canny"])
226
+ preprocess_resolution = gr.Slider(minimum=64, maximum=2048, step=64, value=512, label="Preprocessor Resolution")
227
+ low_threshold = gr.Slider(minimum=1, maximum=255, step=1, value=100, label="'CANNY' low threshold")
228
+ high_threshold = gr.Slider(minimum=1, maximum=255, step=1, value=200, label="'CANNY' high threshold")
229
+ with gr.Row():
230
+ value_threshold = gr.Slider(minimum=1, maximum=2.0, step=0.01, value=0.1, label="'MLSD' Hough value threshold")
231
+ distance_threshold = gr.Slider(minimum=1, maximum=20.0, step=0.01, value=0.1, label="'MLSD' Hough distance threshold")
232
+ recolor_gamma_correction = gr.Number(minimum=0., maximum=25., value=1., step=0.001, label="'RECOLOR' gamma correction")
233
+ tile_blur_sigma = gr.Number(minimum=0, maximum=100, value=9, step=1, label="'TILE' blur sigma")
234
+
235
+ with gr.Tab("IP-Adapter"):
236
+ IP_MODELS = sorted(list(set(IP_ADAPTERS_SD + IP_ADAPTERS_SDXL)))
237
+ MODE_IP_OPTIONS = ["original", "style", "layout", "style+layout"]
238
+ with gr.Accordion("IP-Adapter 1", open=True, visible=True):
239
  with gr.Row():
240
+ #image_ip1 = gr.Image(label="IP Image", type="filepath", height=384, sources=["upload", "clipboard"], show_share_button=False)
241
+ image_ip1 = gr.ImageEditor(label="IP Image", type="filepath", sources=["upload", "clipboard", "webcam"], image_mode='RGB',
242
+ show_share_button=False, show_fullscreen_button=False, layers=False, canvas_size=(384, 384), width=384, height=512,
243
+ brush=gr.Brush(colors=["#FFFFFF"], color_mode="fixed", default_size=32), eraser=gr.Eraser(default_size="32"))
244
+ mask_ip1 = gr.Image(label="IP Mask (optional)", type="filepath", height=384, sources=["upload", "clipboard"], show_share_button=False)
245
  with gr.Row():
246
+ model_ip1 = gr.Dropdown(value="plus_face", label="Model", choices=IP_MODELS)
247
+ mode_ip1 = gr.Dropdown(value="original", label="Mode", choices=MODE_IP_OPTIONS)
248
+ scale_ip1 = gr.Slider(minimum=0., maximum=2., step=0.01, value=0.7, label="Scale")
249
+ with gr.Accordion("IP-Adapter 2", open=True, visible=True):
250
+ with gr.Row():
251
+ #image_ip2 = gr.Image(label="IP Image", type="filepath", height=384, sources=["upload", "clipboard"], show_share_button=False)
252
+ image_ip2 = gr.ImageEditor(label="IP Image", type="filepath", sources=["upload", "clipboard", "webcam"], image_mode='RGB',
253
+ show_share_button=False, show_fullscreen_button=False, layers=False, canvas_size=(384, 384), width=384, height=512,
254
+ brush=gr.Brush(colors=["#FFFFFF"], color_mode="fixed", default_size=32), eraser=gr.Eraser(default_size="32"))
255
+ mask_ip2 = gr.Image(label="IP Mask (optional)", type="filepath", height=384, sources=["upload", "clipboard"], show_share_button=False)
256
+ with gr.Row():
257
+ model_ip2 = gr.Dropdown(value="base", label="Model", choices=IP_MODELS)
258
+ mode_ip2 = gr.Dropdown(value="style", label="Mode", choices=MODE_IP_OPTIONS)
259
+ scale_ip2 = gr.Slider(minimum=0., maximum=2., step=0.01, value=0.7, label="Scale")
260
+
261
+ with gr.Tab("Inpaint Mask Maker"):
262
  with gr.Row():
263
+ with gr.Column():
264
+ image_base = gr.ImageEditor(sources=["upload", "clipboard", "webcam"],
265
+ brush=gr.Brush(default_size="32", color_mode="fixed", colors=["rgba(0, 0, 0, 1)", "rgba(0, 0, 0, 0.1)", "rgba(255, 255, 255, 0.1)"]),
266
+ eraser=gr.Eraser(default_size="32"), show_share_button=False, show_fullscreen_button=False,
267
+ canvas_size=(384, 384), width=384, height=512)
268
+ invert_mask = gr.Checkbox(value=False, label="Invert mask")
269
+ cm_btn = gr.Button("Create mask")
270
+ with gr.Column():
271
+ img_source = gr.Image(interactive=False, height=384, show_share_button=False)
272
+ img_result = gr.Image(label="Mask image", show_label=True, interactive=False, height=384, show_share_button=False)
273
+ cm_btn_send = gr.Button("Send to ControlNet / Img2img / Inpaint")
274
+ cm_btn_send_ip1 = gr.Button("Send to IP-Adapter 1")
275
+ cm_btn_send_ip2 = gr.Button("Send to IP-Adapter 2")
276
+ cm_btn.click(create_mask_now, [image_base, invert_mask], [img_source, img_result], show_api=False)
277
+ def send_img(img_source, img_result):
278
+ return img_source, img_result
279
+ cm_btn_send.click(send_img, [img_source, img_result], [image_control, image_mask], queue=False, show_api=False)
280
+ cm_btn_send_ip1.click(send_img, [img_source, img_result], [image_ip1, mask_ip1], queue=False, show_api=False)
281
+ cm_btn_send_ip2.click(send_img, [img_source, img_result], [image_ip2, mask_ip2], queue=False, show_api=False)
282
+
283
+ with gr.Tab("Hires fix / Detailfix"):
284
+ with gr.Accordion("Hires fix", open=True):
285
+ with gr.Row():
286
+ upscaler_model_path = gr.Dropdown(label="Upscaler", choices=UPSCALER_KEYS, value=UPSCALER_KEYS[0])
287
+ upscaler_increases_size = gr.Slider(minimum=1.1, maximum=4., step=0.1, value=1.2, label="Upscale by")
288
+ esrgan_tile = gr.Slider(minimum=0, value=0, maximum=500, step=1, label="ESRGAN Tile")
289
+ esrgan_tile_overlap = gr.Slider(minimum=1, maximum=200, step=1, value=8, label="ESRGAN Tile Overlap")
290
+ with gr.Row():
291
+ hires_steps = gr.Slider(minimum=0, value=30, maximum=100, step=1, label="Hires Steps")
292
+ hires_denoising_strength = gr.Slider(minimum=0.1, maximum=1.0, step=0.01, value=0.55, label="Hires Denoising Strength")
293
+ hires_sampler = gr.Dropdown(label="Hires Sampler", choices=POST_PROCESSING_SAMPLER, value=POST_PROCESSING_SAMPLER[0])
294
+ hires_schedule_list = ["Use same schedule type"] + SCHEDULE_TYPE_OPTIONS
295
+ hires_schedule_type = gr.Dropdown(label="Hires Schedule type", choices=hires_schedule_list, value=hires_schedule_list[0])
296
+ hires_guidance_scale = gr.Slider(minimum=-1., maximum=30., step=0.5, value=-1., label="Hires CFG", info="If the value is -1, the main CFG will be used")
297
+ with gr.Row():
298
+ hires_prompt = gr.Textbox(label="Hires Prompt", placeholder="Main prompt will be use", lines=3)
299
+ hires_negative_prompt = gr.Textbox(label="Hires Negative Prompt", placeholder="Main negative prompt will be use", lines=3)
300
+ with gr.Accordion("Detail fix", open=True):
301
+ with gr.Row():
302
+ # Adetailer Inpaint Only
303
+ adetailer_inpaint_only = gr.Checkbox(label="Inpaint only", value=True)
304
+ # Adetailer Verbose
305
+ adetailer_verbose = gr.Checkbox(label="Verbose", value=False)
306
+ # Adetailer Sampler
307
+ adetailer_sampler = gr.Dropdown(label="Adetailer sampler:", choices=POST_PROCESSING_SAMPLER, value=POST_PROCESSING_SAMPLER[0])
308
+ with gr.Row():
309
+ with gr.Accordion("Detailfix A", open=True, visible=True):
310
+ # Adetailer A
311
+ adetailer_active_a = gr.Checkbox(label="Enable Adetailer A", value=False)
312
+ prompt_ad_a = gr.Textbox(label="Main prompt", placeholder="Main prompt will be use", lines=3)
313
+ negative_prompt_ad_a = gr.Textbox(label="Negative prompt", placeholder="Main negative prompt will be use", lines=3)
314
+ with gr.Row():
315
+ strength_ad_a = gr.Number(label="Strength:", value=0.35, step=0.01, minimum=0.01, maximum=1.0)
316
+ face_detector_ad_a = gr.Checkbox(label="Face detector", value=False)
317
+ person_detector_ad_a = gr.Checkbox(label="Person detector", value=True)
318
+ hand_detector_ad_a = gr.Checkbox(label="Hand detector", value=False)
319
+ with gr.Row():
320
+ mask_dilation_a = gr.Number(label="Mask dilation:", value=4, minimum=1)
321
+ mask_blur_a = gr.Number(label="Mask blur:", value=4, minimum=1)
322
+ mask_padding_a = gr.Number(label="Mask padding:", value=32, minimum=1)
323
+ with gr.Accordion("Detailfix B", open=True, visible=True):
324
+ # Adetailer B
325
+ adetailer_active_b = gr.Checkbox(label="Enable Adetailer B", value=False)
326
+ prompt_ad_b = gr.Textbox(label="Main prompt", placeholder="Main prompt will be use", lines=3)
327
+ negative_prompt_ad_b = gr.Textbox(label="Negative prompt", placeholder="Main negative prompt will be use", lines=3)
328
+ with gr.Row():
329
+ strength_ad_b = gr.Number(label="Strength:", value=0.35, step=0.01, minimum=0.01, maximum=1.0)
330
+ face_detector_ad_b = gr.Checkbox(label="Face detector", value=False)
331
+ person_detector_ad_b = gr.Checkbox(label="Person detector", value=True)
332
+ hand_detector_ad_b = gr.Checkbox(label="Hand detector", value=False)
333
+ with gr.Row():
334
+ mask_dilation_b = gr.Number(label="Mask dilation:", value=4, minimum=1)
335
+ mask_blur_b = gr.Number(label="Mask blur:", value=4, minimum=1)
336
+ mask_padding_b = gr.Number(label="Mask padding:", value=32, minimum=1)
337
+
338
+ with gr.Tab("Translation Settings"):
339
+ chatbot = gr.Chatbot(render_markdown=False, visible=False) # component for auto-translation
340
+ chat_model = gr.Dropdown(choices=get_dolphin_models(), value=get_dolphin_models()[0][1], allow_custom_value=True, label="Model")
341
+ chat_model_info = gr.Markdown(value=get_dolphin_model_info(get_dolphin_models()[0][1]), label="Model info")
342
+ chat_format = gr.Dropdown(choices=get_llm_formats(), value=get_dolphin_model_format(get_dolphin_models()[0][1]), label="Message format")
343
+ with gr.Row():
344
+ chat_tokens = gr.Slider(minimum=1, maximum=4096, value=512, step=1, label="Max tokens")
345
+ chat_temperature = gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature")
346
+ chat_topp = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p")
347
+ chat_topk = gr.Slider(minimum=0, maximum=100, value=40, step=1, label="Top-k")
348
+ chat_rp = gr.Slider(minimum=0.0, maximum=2.0, value=1.1, step=0.1, label="Repetition penalty")
349
+ chat_sysmsg = gr.Textbox(value=get_dolphin_sysprompt(), label="System message")
350
+
351
+ examples = gr.Examples(
352
+ examples = [
353
+ ["souryuu asuka langley, 1girl, neon genesis evangelion, plugsuit, pilot suit, red bodysuit, sitting, crossing legs, black eye patch, cat hat, throne, symmetrical, looking down, from bottom, looking at viewer, outdoors"],
354
+ ["sailor moon, magical girl transformation, sparkles and ribbons, soft pastel colors, crescent moon motif, starry night sky background, shoujo manga style"],
355
+ ["kafuu chino, 1girl, solo"],
356
+ ["1girl"],
357
+ ["beautiful sunset"],
358
+ ],
359
+ inputs=[prompt],
360
+ cache_examples=False,
361
+ )
362
+
363
+ model_name.change(update_task_options, [model_name, task], [task], queue=False, show_api=False)
364
+ task.change(change_preprocessor_choices, [task], [preprocessor_name], queue=False, show_api=False)
365
+ active_textual_inversion.change(update_textual_inversion, [active_textual_inversion, model_name], [use_textual_inversion], queue=False, show_api=False)
366
+ model_name.change(update_textual_inversion, [active_textual_inversion, model_name], [use_textual_inversion], queue=False, show_api=False)
367
+ use_textual_inversion.change(set_textual_inversion_prompt, [use_textual_inversion, prompt, negative_prompt, prompt_syntax], [prompt, negative_prompt])
368
+
369
+ gr.on( #lambda x: None, inputs=None, outputs=result).then(
370
+ triggers=[run_button.click, prompt.submit],
371
+ fn=infer,
372
+ inputs=[prompt, negative_prompt, seed, randomize_seed, width, height,
373
+ guidance_scale, num_inference_steps, model_name,
374
+ lora1, lora1_wt, lora2, lora2_wt, lora3, lora3_wt, lora4, lora4_wt,
375
+ lora5, lora5_wt, lora6, lora6_wt, lora7, lora7_wt, task, prompt_syntax,
376
+ sampler, vae_model, schedule_type, schedule_prediction_type,
377
+ clip_skip, pag_scale, free_u, guidance_rescale,
378
+ image_control, image_mask, strength, image_resolution,
379
+ controlnet_model, control_net_output_scaling, control_net_start_threshold, control_net_stop_threshold,
380
+ preprocessor_name, preprocess_resolution, low_threshold, high_threshold,
381
+ value_threshold, distance_threshold, recolor_gamma_correction, tile_blur_sigma,
382
+ image_ip1, mask_ip1, model_ip1, mode_ip1, scale_ip1,
383
+ image_ip2, mask_ip2, model_ip2, mode_ip2, scale_ip2,
384
+ upscaler_model_path, upscaler_increases_size, esrgan_tile, esrgan_tile_overlap, hires_steps, hires_denoising_strength,
385
+ hires_sampler, hires_schedule_type, hires_guidance_scale, hires_prompt, hires_negative_prompt,
386
+ adetailer_inpaint_only, adetailer_verbose, adetailer_sampler, adetailer_active_a,
387
+ prompt_ad_a, negative_prompt_ad_a, strength_ad_a, face_detector_ad_a, person_detector_ad_a, hand_detector_ad_a,
388
+ mask_dilation_a, mask_blur_a, mask_padding_a, adetailer_active_b, prompt_ad_b, negative_prompt_ad_b, strength_ad_b,
389
+ face_detector_ad_b, person_detector_ad_b, hand_detector_ad_b, mask_dilation_b, mask_blur_b, mask_padding_b,
390
+ active_textual_inversion, gpu_duration, auto_trans, recom_prompt],
391
+ outputs=[result],
392
+ queue=True,
393
+ show_progress="full",
394
+ show_api=True,
395
+ )
396
+
397
+ gr.on( #lambda x: None, inputs=None, outputs=result).then(
398
+ triggers=[run_translate_button.click],
399
+ fn=_infer, # dummy fn for api
400
+ inputs=[prompt, negative_prompt, seed, randomize_seed, width, height,
401
+ guidance_scale, num_inference_steps, model_name,
402
+ lora1, lora1_wt, lora2, lora2_wt, lora3, lora3_wt, lora4, lora4_wt,
403
+ lora5, lora5_wt, lora6, lora6_wt, lora7, lora7_wt, task, prompt_syntax,
404
+ sampler, vae_model, schedule_type, schedule_prediction_type,
405
+ clip_skip, pag_scale, free_u, guidance_rescale,
406
+ image_control, image_mask, strength, image_resolution,
407
+ controlnet_model, control_net_output_scaling, control_net_start_threshold, control_net_stop_threshold,
408
+ preprocessor_name, preprocess_resolution, low_threshold, high_threshold,
409
+ value_threshold, distance_threshold, recolor_gamma_correction, tile_blur_sigma,
410
+ image_ip1, mask_ip1, model_ip1, mode_ip1, scale_ip1,
411
+ image_ip2, mask_ip2, model_ip2, mode_ip2, scale_ip2,
412
+ upscaler_model_path, upscaler_increases_size, esrgan_tile, esrgan_tile_overlap, hires_steps, hires_denoising_strength,
413
+ hires_sampler, hires_schedule_type, hires_guidance_scale, hires_prompt, hires_negative_prompt,
414
+ adetailer_inpaint_only, adetailer_verbose, adetailer_sampler, adetailer_active_a,
415
+ prompt_ad_a, negative_prompt_ad_a, strength_ad_a, face_detector_ad_a, person_detector_ad_a, hand_detector_ad_a,
416
+ mask_dilation_a, mask_blur_a, mask_padding_a, adetailer_active_b, prompt_ad_b, negative_prompt_ad_b, strength_ad_b,
417
+ face_detector_ad_b, person_detector_ad_b, hand_detector_ad_b, mask_dilation_b, mask_blur_b, mask_padding_b,
418
+ active_textual_inversion, gpu_duration, auto_trans, recom_prompt],
419
+ outputs=[result],
420
+ queue=False,
421
+ show_api=True,
422
+ api_name="infer_translate",
423
+ ).success(
424
+ fn=dolphin_respond_auto,
425
+ inputs=[prompt, chatbot, chat_model, chat_sysmsg, chat_tokens, chat_temperature, chat_topp, chat_topk, chat_rp, state],
426
+ outputs=[chatbot, result, prompt],
427
+ queue=True,
428
+ show_progress="full",
429
+ show_api=False,
430
+ ).success(
431
+ fn=dolphin_parse_simple,
432
+ inputs=[prompt, chatbot, state],
433
+ outputs=[prompt],
434
+ queue=False,
435
+ show_api=False,
436
+ ).success(
437
+ fn=infer,
438
+ inputs=[prompt, negative_prompt, seed, randomize_seed, width, height,
439
+ guidance_scale, num_inference_steps, model_name,
440
+ lora1, lora1_wt, lora2, lora2_wt, lora3, lora3_wt, lora4, lora4_wt,
441
+ lora5, lora5_wt, lora6, lora6_wt, lora7, lora7_wt, task, prompt_syntax,
442
+ sampler, vae_model, schedule_type, schedule_prediction_type,
443
+ clip_skip, pag_scale, free_u, guidance_rescale,
444
+ image_control, image_mask, strength, image_resolution,
445
+ controlnet_model, control_net_output_scaling, control_net_start_threshold, control_net_stop_threshold,
446
+ preprocessor_name, preprocess_resolution, low_threshold, high_threshold,
447
+ value_threshold, distance_threshold, recolor_gamma_correction, tile_blur_sigma,
448
+ image_ip1, mask_ip1, model_ip1, mode_ip1, scale_ip1,
449
+ image_ip2, mask_ip2, model_ip2, mode_ip2, scale_ip2,
450
+ upscaler_model_path, upscaler_increases_size, esrgan_tile, esrgan_tile_overlap, hires_steps, hires_denoising_strength,
451
+ hires_sampler, hires_schedule_type, hires_guidance_scale, hires_prompt, hires_negative_prompt,
452
+ adetailer_inpaint_only, adetailer_verbose, adetailer_sampler, adetailer_active_a,
453
+ prompt_ad_a, negative_prompt_ad_a, strength_ad_a, face_detector_ad_a, person_detector_ad_a, hand_detector_ad_a,
454
+ mask_dilation_a, mask_blur_a, mask_padding_a, adetailer_active_b, prompt_ad_b, negative_prompt_ad_b, strength_ad_b,
455
+ face_detector_ad_b, person_detector_ad_b, hand_detector_ad_b, mask_dilation_b, mask_blur_b, mask_padding_b,
456
+ active_textual_inversion, gpu_duration, auto_trans, recom_prompt],
457
+ outputs=[result],
458
+ queue=True,
459
+ show_progress="full",
460
+ show_api=False,
461
+ ).success(lambda: None, None, chatbot, queue=False, show_api=False)\
462
+ .success(pass_result, [result], [result], queue=False, show_api=False) # dummy fn for api
463
+
464
+ result.change(save_image_history, [result, history_gallery, history_files, model_name], [history_gallery, history_files], queue=False, show_api=False)
465
+
466
+ gr.on(
467
+ triggers=[lora1.change, lora1_wt.change, lora2.change, lora2_wt.change, lora3.change, lora3_wt.change,
468
+ lora4.change, lora4_wt.change, lora5.change, lora5_wt.change, lora6.change, lora6_wt.change, lora7.change, lora7_wt.change, prompt_syntax.change],
469
+ fn=update_loras,
470
+ inputs=[prompt, prompt_syntax, lora1, lora1_wt, lora2, lora2_wt, lora3, lora3_wt, lora4, lora4_wt, lora5, lora5_wt, lora6, lora6_wt, lora7, lora7_wt],
471
+ outputs=[prompt, lora1, lora1_wt, lora1_info, lora1_copy, lora1_md,
472
+ lora2, lora2_wt, lora2_info, lora2_copy, lora2_md, lora3, lora3_wt, lora3_info, lora3_copy, lora3_md,
473
+ lora4, lora4_wt, lora4_info, lora4_copy, lora4_md, lora5, lora5_wt, lora5_info, lora5_copy, lora5_md,
474
+ lora6, lora6_wt, lora6_info, lora6_copy, lora6_md, lora7, lora7_wt, lora7_info, lora7_copy, lora7_md],
475
+ queue=False,
476
+ trigger_mode="once",
477
+ show_api=False,
478
+ )
479
+ lora1_copy.click(apply_lora_prompt, [prompt, lora1_info], [prompt], queue=False, show_api=False)
480
+ lora2_copy.click(apply_lora_prompt, [prompt, lora2_info], [prompt], queue=False, show_api=False)
481
+ lora3_copy.click(apply_lora_prompt, [prompt, lora3_info], [prompt], queue=False, show_api=False)
482
+ lora4_copy.click(apply_lora_prompt, [prompt, lora4_info], [prompt], queue=False, show_api=False)
483
+ lora5_copy.click(apply_lora_prompt, [prompt, lora5_info], [prompt], queue=False, show_api=False)
484
+ lora6_copy.click(apply_lora_prompt, [prompt, lora6_info], [prompt], queue=False, show_api=False)
485
+ lora7_copy.click(apply_lora_prompt, [prompt, lora7_info], [prompt], queue=False, show_api=False)
486
+
487
+ gr.on(
488
+ triggers=[lora_search_civitai_submit.click, lora_search_civitai_query.submit],
489
+ fn=search_civitai_lora,
490
+ inputs=[lora_search_civitai_query, lora_search_civitai_basemodel, lora_search_civitai_sort, lora_search_civitai_period, lora_search_civitai_tag, lora_search_civitai_user, lora_search_civitai_gallery],
491
+ outputs=[lora_search_civitai_result, lora_search_civitai_desc, lora_search_civitai_submit, lora_search_civitai_query, lora_search_civitai_gallery],
492
+ scroll_to_output=True,
493
+ queue=True,
494
+ show_api=False,
495
+ )
496
+ lora_search_civitai_json.change(search_civitai_lora_json, [lora_search_civitai_query, lora_search_civitai_basemodel], [lora_search_civitai_json], queue=True, show_api=True) # fn for api
497
+ lora_search_civitai_result.change(select_civitai_lora, [lora_search_civitai_result], [lora_download_url, lora_search_civitai_desc], scroll_to_output=True, queue=False, show_api=False)
498
+ gr.on(
499
+ triggers=[lora_download.click, lora_download_url.submit],
500
+ fn=download_my_lora,
501
+ inputs=[lora_download_url, lora1, lora2, lora3, lora4, lora5, lora6, lora7],
502
+ outputs=[lora1, lora2, lora3, lora4, lora5, lora6, lora7],
503
+ scroll_to_output=True,
504
+ queue=True,
505
+ show_api=False,
506
+ )
507
+ lora_search_civitai_gallery.select(update_civitai_selection, None, [lora_search_civitai_result], queue=False, show_api=False)
508
+
509
+ #recom_prompt.change(enable_model_recom_prompt, [recom_prompt], [recom_prompt], queue=False, show_api=False)
510
+ gr.on(
511
+ triggers=[quality_selector.change, style_selector.change],
512
+ fn=process_style_prompt,
513
+ inputs=[prompt, negative_prompt, style_selector, quality_selector],
514
+ outputs=[prompt, negative_prompt],
515
+ queue=False,
516
+ trigger_mode="once",
517
+ show_api=False,
518
+ )
519
+
520
+ model_detail.change(enable_diffusers_model_detail, [model_detail, model_name, state], [model_detail, model_name, state], queue=False, show_api=False)
521
+ model_name.change(get_t2i_model_info, [model_name], [model_info], queue=False, show_api=False)
522
+
523
+ chat_model.change(select_dolphin_model, [chat_model, state], [chat_model, chat_format, chat_model_info, state], queue=True, show_progress="full", show_api=False)\
524
+ .success(lambda: None, None, chatbot, queue=False, show_api=False)
525
+ chat_format.change(select_dolphin_format, [chat_format, state], [chat_format, state], queue=False, show_api=False)\
526
+ .success(lambda: None, None, chatbot, queue=False, show_api=False)
527
+
528
+ # Tagger
529
+ with gr.Tab("Tags Transformer with Tagger"):
530
+ with gr.Column():
531
+ with gr.Group():
532
+ input_image = gr.Image(label="Input image", type="pil", sources=["upload", "clipboard"], height=256)
533
+ with gr.Accordion(label="Advanced options", open=False):
534
+ general_threshold = gr.Slider(label="Threshold", minimum=0.0, maximum=1.0, value=0.3, step=0.01, interactive=True)
535
+ character_threshold = gr.Slider(label="Character threshold", minimum=0.0, maximum=1.0, value=0.8, step=0.01, interactive=True)
536
+ input_tag_type = gr.Radio(label="Convert tags to", info="danbooru for Animagine, e621 for Pony.", choices=["danbooru", "e621"], value="danbooru")
537
+ recom_prompt = gr.Radio(label="Insert reccomended prompt", choices=["None", "Animagine", "Pony"], value="None", interactive=True)
538
+ image_algorithms = gr.CheckboxGroup(["Use WD Tagger", "Use Florence-2-SD3-Long-Captioner"], label="Algorithms", value=["Use WD Tagger"])
539
+ keep_tags = gr.Radio(label="Remove tags leaving only the following", choices=["body", "dress", "all"], value="all")
540
+ generate_from_image_btn = gr.Button(value="GENERATE TAGS FROM IMAGE", size="lg", variant="primary")
541
+ with gr.Group():
542
+ with gr.Row():
543
+ input_character = gr.Textbox(label="Character tags", placeholder="hatsune miku")
544
+ input_copyright = gr.Textbox(label="Copyright tags", placeholder="vocaloid")
545
+ random_character = gr.Button(value="Random character 🎲", size="sm")
546
+ input_general = gr.TextArea(label="General tags", lines=4, placeholder="1girl, ...", value="")
547
+ input_tags_to_copy = gr.Textbox(value="", visible=False)
548
+ with gr.Row():
549
+ copy_input_btn = gr.Button(value="Copy to clipboard", size="sm", interactive=False)
550
+ copy_prompt_btn_input = gr.Button(value="Copy to primary prompt", size="sm", interactive=False)
551
+ translate_input_prompt_button = gr.Button(value="Translate prompt to English", size="sm", variant="secondary")
552
+ tag_type = gr.Radio(label="Output tag conversion", info="danbooru for Animagine, e621 for Pony.", choices=["danbooru", "e621"], value="e621", visible=False)
553
+ input_rating = gr.Radio(label="Rating", choices=list(V2_RATING_OPTIONS), value="explicit")
554
+ with gr.Accordion(label="Advanced options", open=False):
555
+ input_aspect_ratio = gr.Radio(label="Aspect ratio", info="The aspect ratio of the image.", choices=list(V2_ASPECT_RATIO_OPTIONS), value="square")
556
+ input_length = gr.Radio(label="Length", info="The total length of the tags.", choices=list(V2_LENGTH_OPTIONS), value="very_long")
557
+ input_identity = gr.Radio(label="Keep identity", info="How strictly to keep the identity of the character or subject. If you specify the detail of subject in the prompt, you should choose `strict`. Otherwise, choose `none` or `lax`. `none` is very creative but sometimes ignores the input prompt.", choices=list(V2_IDENTITY_OPTIONS), value="lax")
558
+ input_ban_tags = gr.Textbox(label="Ban tags", info="Tags to ban from the output.", placeholder="alternate costumen, ...", value="censored")
559
+ model_name = gr.Dropdown(label="Model", choices=list(V2_ALL_MODELS.keys()), value=list(V2_ALL_MODELS.keys())[0])
560
+ dummy_np = gr.Textbox(label="Negative prompt", value="", visible=False)
561
+ recom_animagine = gr.Textbox(label="Animagine reccomended prompt", value="Animagine", visible=False)
562
+ recom_pony = gr.Textbox(label="Pony reccomended prompt", value="Pony", visible=False)
563
+ generate_btn = gr.Button(value="GENERATE TAGS", size="lg", variant="primary")
564
+ with gr.Row():
565
+ with gr.Group():
566
+ output_text = gr.TextArea(label="Output tags", interactive=False, show_copy_button=True)
567
+ with gr.Row():
568
+ copy_btn = gr.Button(value="Copy to clipboard", size="sm", interactive=False)
569
+ copy_prompt_btn = gr.Button(value="Copy to primary prompt", size="sm", interactive=False)
570
+ with gr.Group():
571
+ output_text_pony = gr.TextArea(label="Output tags (Pony e621 style)", interactive=False, show_copy_button=True)
572
+ with gr.Row():
573
+ copy_btn_pony = gr.Button(value="Copy to clipboard", size="sm", interactive=False)
574
+ copy_prompt_btn_pony = gr.Button(value="Copy to primary prompt", size="sm", interactive=False)
575
+
576
+ random_character.click(select_random_character, [input_copyright, input_character], [input_copyright, input_character], queue=False, show_api=False)
577
+
578
+ translate_input_prompt_button.click(translate_prompt, [input_general], [input_general], queue=False, show_api=False)
579
+ translate_input_prompt_button.click(translate_prompt, [input_character], [input_character], queue=False, show_api=False)
580
+ translate_input_prompt_button.click(translate_prompt, [input_copyright], [input_copyright], queue=False, show_api=False)
581
+
582
+ generate_from_image_btn.click(
583
+ lambda: ("", "", ""), None, [input_copyright, input_character, input_general], queue=False, show_api=False,
584
+ ).success(
585
+ predict_tags_wd,
586
+ [input_image, input_general, image_algorithms, general_threshold, character_threshold],
587
+ [input_copyright, input_character, input_general, copy_input_btn],
588
+ show_api=False,
589
+ ).success(
590
+ predict_tags_fl2_sd3, [input_image, input_general, image_algorithms], [input_general], show_api=False,
591
+ ).success(
592
+ remove_specific_prompt, [input_general, keep_tags], [input_general], queue=False, show_api=False,
593
+ ).success(
594
+ convert_danbooru_to_e621_prompt, [input_general, input_tag_type], [input_general], queue=False, show_api=False,
595
+ ).success(
596
+ insert_recom_prompt, [input_general, dummy_np, recom_prompt], [input_general, dummy_np], queue=False, show_api=False,
597
+ ).success(lambda: gr.update(interactive=True), None, [copy_prompt_btn_input], queue=False, show_api=False)
598
+ copy_input_btn.click(compose_prompt_to_copy, [input_character, input_copyright, input_general], [input_tags_to_copy], show_api=False)\
599
+ .success(gradio_copy_text, [input_tags_to_copy], js=COPY_ACTION_JS, show_api=False)
600
+ copy_prompt_btn_input.click(compose_prompt_to_copy, inputs=[input_character, input_copyright, input_general], outputs=[input_tags_to_copy], show_api=False)\
601
+ .success(gradio_copy_prompt, inputs=[input_tags_to_copy], outputs=[prompt], show_api=False)
602
+
603
+ generate_btn.click(
604
+ v2_upsampling_prompt,
605
+ [model_name, input_copyright, input_character, input_general,
606
+ input_rating, input_aspect_ratio, input_length, input_identity, input_ban_tags],
607
+ [output_text],
608
+ show_api=False,
609
+ ).success(
610
+ convert_danbooru_to_e621_prompt, [output_text, tag_type], [output_text_pony], queue=False, show_api=False,
611
+ ).success(
612
+ insert_recom_prompt, [output_text, dummy_np, recom_animagine], [output_text, dummy_np], queue=False, show_api=False,
613
+ ).success(
614
+ insert_recom_prompt, [output_text_pony, dummy_np, recom_pony], [output_text_pony, dummy_np], queue=False, show_api=False,
615
+ ).success(lambda: (gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True)),
616
+ None, [copy_btn, copy_btn_pony, copy_prompt_btn, copy_prompt_btn_pony], queue=False, show_api=False)
617
+ copy_btn.click(gradio_copy_text, [output_text], js=COPY_ACTION_JS, show_api=False)
618
+ copy_btn_pony.click(gradio_copy_text, [output_text_pony], js=COPY_ACTION_JS, show_api=False)
619
+ copy_prompt_btn.click(gradio_copy_prompt, inputs=[output_text], outputs=[prompt], show_api=False)
620
+ copy_prompt_btn_pony.click(gradio_copy_prompt, inputs=[output_text_pony], outputs=[prompt], show_api=False)
621
+
622
+ with gr.Tab("PNG Info"):
623
+ with gr.Row():
624
+ with gr.Column():
625
+ image_metadata = gr.Image(label="Image with metadata", type="pil", sources=["upload"])
626
+
627
+ with gr.Column():
628
+ result_metadata = gr.Textbox(label="Metadata", show_label=True, show_copy_button=True, interactive=False, container=True, max_lines=99)
629
+
630
+ image_metadata.change(
631
+ fn=extract_exif_data,
632
+ inputs=[image_metadata],
633
+ outputs=[result_metadata],
634
+ )
635
+
636
+ with gr.Tab("Upscaler"):
637
+ with gr.Row():
638
+ with gr.Column():
639
+ image_up_tab = gr.Image(label="Image", type="pil", sources=["upload"])
640
+ upscaler_tab = gr.Dropdown(label="Upscaler", choices=UPSCALER_KEYS[9:], value=UPSCALER_KEYS[11])
641
+ upscaler_size_tab = gr.Slider(minimum=1., maximum=4., step=0.1, value=1.1, label="Upscale by")
642
+ generate_button_up_tab = gr.Button(value="START UPSCALE", variant="primary")
643
+
644
+ with gr.Column():
645
+ result_up_tab = gr.Image(label="Result", type="pil", interactive=False, format="png")
646
+
647
+ generate_button_up_tab.click(
648
+ fn=esrgan_upscale,
649
+ inputs=[image_up_tab, upscaler_tab, upscaler_size_tab],
650
+ outputs=[result_up_tab],
651
+ )
652
+
653
+ with gr.Tab("Preprocessor", render=True):
654
+ preprocessor_tab()
655
+
656
+ gr.LoginButton()
657
+ gr.DuplicateButton(value="Duplicate Space for private use (This demo does not work on CPU. Requires GPU Space)")
658
 
659
  demo.queue()
660
+ demo.launch(show_error=True, debug=True)