Files changed (8) hide show
  1. README.md +166 -166
  2. app.py +81 -114
  3. constants.py +1 -1
  4. env.py +0 -8
  5. modutils.py +0 -0
  6. packages.txt +1 -2
  7. requirements.txt +23 -23
  8. utils.py +21 -41
README.md CHANGED
@@ -1,166 +1,166 @@
1
- ---
2
- title: 🧩 DiffuseCraft Mod (SDXL/SD1.5 Models Text-to-Image)
3
- emoji: 🧩🖼️📦
4
- colorFrom: red
5
- colorTo: pink
6
- sdk: gradio
7
- sdk_version: 6.10.0
8
- python_version: "3.12"
9
- app_file: app.py
10
- pinned: true
11
- header: mini
12
- license: mit
13
- duplicated_from: r3gm/DiffuseCraft
14
- short_description: Stunning images using stable diffusion.
15
- preload_from_hub:
16
- - madebyollin/sdxl-vae-fp16-fix config.json,diffusion_pytorch_model.safetensors
17
- ---
18
-
19
- ## Using this Space programmatically
20
-
21
- You can call this Space from Python (via `gradio_client`) or from plain `curl`.
22
-
23
- > ⚠️ Note: This README may lag behind the actual API definition shown in the Space’s “View API” page.
24
- > If something does not work, always double-check the latest argument list and endpoint names there.
25
-
26
- Assumptions:
27
-
28
- - Space ID: `John6666/DiffuseCraftMod`
29
- - You have a valid Hugging Face access token: `hf_xxx...` (read access is enough)
30
- - Replace `hf_xxx...` with your own token
31
-
32
- ---
33
-
34
- ### 1. Python examples (`gradio_client`)
35
-
36
- Install:
37
-
38
- ```bash
39
- pip install gradio_client
40
- ````
41
-
42
- #### 1.1 Synchronous API – `generate_image`
43
-
44
- ```python
45
- from gradio_client import Client
46
-
47
- client = Client("John6666/DiffuseCraftMod", hf_token="hf_xxx...")
48
-
49
- status, images, info = client.predict(
50
- # Core text controls
51
- prompt="Hello!!",
52
- negative_prompt=(
53
- "lowres, bad anatomy, bad hands, missing fingers, extra digit, "
54
- "fewer digits, worst quality, low quality"
55
- ),
56
-
57
- # Basic generation controls
58
- num_images=1,
59
- num_inference_steps=28,
60
- guidance_scale=7.0,
61
- clip_skip=0,
62
- seed=-1,
63
-
64
- # Canvas / model / task (optional, server has defaults)
65
- height=1024,
66
- width=1024,
67
- model_name="votepurchase/animagine-xl-3.1",
68
- vae_model="None",
69
- task="txt2img",
70
-
71
- # All other arguments are optional; defaults match the UI
72
- api_name="/generate_image",
73
- )
74
-
75
- print(status) # e.g. "COMPLETE"
76
- print(images) # list of image paths / URLs
77
- print(info) # generation metadata (seed, model, etc.)
78
- ```
79
-
80
- #### 1.2 Streaming API – `generate_image_stream`
81
-
82
- ```python
83
- from gradio_client import Client
84
-
85
- client = Client("John6666/DiffuseCraftMod", hf_token="hf_xxx...")
86
-
87
- job = client.submit(
88
- prompt="Hello!!",
89
- negative_prompt=(
90
- "lowres, bad anatomy, bad hands, missing fingers, extra digit, "
91
- "fewer digits, worst quality, low quality"
92
- ),
93
- num_images=1,
94
- num_inference_steps=28,
95
- guidance_scale=7.0,
96
- clip_skip=0,
97
- seed=-1,
98
- height=1024,
99
- width=1024,
100
- model_name="votepurchase/animagine-xl-3.1",
101
- vae_model="None",
102
- task="txt2img",
103
- api_name="/generate_image_stream",
104
- )
105
-
106
- for status, images, info in job:
107
- # You will see progress messages, intermediate previews, and the final result.
108
- print(status, images, info)
109
- ```
110
-
111
- You can stop iterating once you see a `"COMPLETE"` status if you only care about the final output.
112
-
113
- ---
114
-
115
- ### 2. `curl` examples
116
-
117
- When calling from `curl`, include your HF token; anonymous calls may be rate-limited or rejected.
118
-
119
- ```bash
120
- export HF_TOKEN="hf_xxx..." # your Hugging Face access token
121
- ```
122
-
123
- The `data` field is a positional array. The order must match the function signature.
124
- For simplicity, the examples below only send the first few arguments and rely on server defaults for the rest.
125
-
126
- #### 2.1 Synchronous API – `generate_image`
127
-
128
- ```bash
129
- curl -X POST "https://john6666-diffusecraftmod.hf.space/call/generate_image" \
130
- -H "Authorization: Bearer $HF_TOKEN" \
131
- -H "Content-Type: application/json" \
132
- -d '{
133
- "data": [
134
- "Hello!!", // prompt
135
- "lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, worst quality, low quality", // negative_prompt
136
- 1, // num_images
137
- 28, // num_inference_steps
138
- 7.0, // guidance_scale
139
- 0, // clip_skip
140
- -1 // seed
141
- // All subsequent parameters will use their default values
142
- ]
143
- }'
144
- ```
145
-
146
- #### 2.2 Streaming API – `generate_image_stream`
147
-
148
- ```bash
149
- curl -X POST "https://john6666-diffusecraftmod.hf.space/call/generate_image_stream" \
150
- -H "Authorization: Bearer $HF_TOKEN" \
151
- -H "Content-Type: application/json" \
152
- -d '{
153
- "data": [
154
- "Hello!!",
155
- "lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, worst quality, low quality",
156
- 1,
157
- 28,
158
- 7.0,
159
- 0,
160
- -1
161
- ]
162
- }'
163
- ```
164
-
165
- For full parameter coverage (all advanced options such as LoRAs, ControlNet, IP-Adapter, etc.),
166
- refer to the Space’s “View API” page and adapt the examples above accordingly.
 
1
+ ---
2
+ title: 🧩 DiffuseCraft Mod (SDXL/SD1.5 Models Text-to-Image)
3
+ emoji: 🧩🖼️📦
4
+ colorFrom: red
5
+ colorTo: pink
6
+ sdk: gradio
7
+ sdk_version: 5.45.0
8
+ app_file: app.py
9
+ pinned: true
10
+ header: mini
11
+ license: mit
12
+ duplicated_from: r3gm/DiffuseCraft
13
+ short_description: Stunning images using stable diffusion.
14
+ preload_from_hub:
15
+ - madebyollin/sdxl-vae-fp16-fix config.json,diffusion_pytorch_model.safetensors
16
+ hf_oauth: true
17
+ ---
18
+
19
+ ## Using this Space programmatically
20
+
21
+ You can call this Space from Python (via `gradio_client`) or from plain `curl`.
22
+
23
+ > ⚠️ Note: This README may lag behind the actual API definition shown in the Space’s “View API” page.
24
+ > If something does not work, always double-check the latest argument list and endpoint names there.
25
+
26
+ Assumptions:
27
+
28
+ - Space ID: `John6666/DiffuseCraftMod`
29
+ - You have a valid Hugging Face access token: `hf_xxx...` (read access is enough)
30
+ - Replace `hf_xxx...` with your own token
31
+
32
+ ---
33
+
34
+ ### 1. Python examples (`gradio_client`)
35
+
36
+ Install:
37
+
38
+ ```bash
39
+ pip install gradio_client
40
+ ````
41
+
42
+ #### 1.1 Synchronous API – `generate_image`
43
+
44
+ ```python
45
+ from gradio_client import Client
46
+
47
+ client = Client("John6666/DiffuseCraftMod", hf_token="hf_xxx...")
48
+
49
+ status, images, info = client.predict(
50
+ # Core text controls
51
+ prompt="Hello!!",
52
+ negative_prompt=(
53
+ "lowres, bad anatomy, bad hands, missing fingers, extra digit, "
54
+ "fewer digits, worst quality, low quality"
55
+ ),
56
+
57
+ # Basic generation controls
58
+ num_images=1,
59
+ num_inference_steps=28,
60
+ guidance_scale=7.0,
61
+ clip_skip=0,
62
+ seed=-1,
63
+
64
+ # Canvas / model / task (optional, server has defaults)
65
+ height=1024,
66
+ width=1024,
67
+ model_name="votepurchase/animagine-xl-3.1",
68
+ vae_model="None",
69
+ task="txt2img",
70
+
71
+ # All other arguments are optional; defaults match the UI
72
+ api_name="/generate_image",
73
+ )
74
+
75
+ print(status) # e.g. "COMPLETE"
76
+ print(images) # list of image paths / URLs
77
+ print(info) # generation metadata (seed, model, etc.)
78
+ ```
79
+
80
+ #### 1.2 Streaming API – `generate_image_stream`
81
+
82
+ ```python
83
+ from gradio_client import Client
84
+
85
+ client = Client("John6666/DiffuseCraftMod", hf_token="hf_xxx...")
86
+
87
+ job = client.submit(
88
+ prompt="Hello!!",
89
+ negative_prompt=(
90
+ "lowres, bad anatomy, bad hands, missing fingers, extra digit, "
91
+ "fewer digits, worst quality, low quality"
92
+ ),
93
+ num_images=1,
94
+ num_inference_steps=28,
95
+ guidance_scale=7.0,
96
+ clip_skip=0,
97
+ seed=-1,
98
+ height=1024,
99
+ width=1024,
100
+ model_name="votepurchase/animagine-xl-3.1",
101
+ vae_model="None",
102
+ task="txt2img",
103
+ api_name="/generate_image_stream",
104
+ )
105
+
106
+ for status, images, info in job:
107
+ # You will see progress messages, intermediate previews, and the final result.
108
+ print(status, images, info)
109
+ ```
110
+
111
+ You can stop iterating once you see a `"COMPLETE"` status if you only care about the final output.
112
+
113
+ ---
114
+
115
+ ### 2. `curl` examples
116
+
117
+ When calling from `curl`, include your HF token; anonymous calls may be rate-limited or rejected.
118
+
119
+ ```bash
120
+ export HF_TOKEN="hf_xxx..." # your Hugging Face access token
121
+ ```
122
+
123
+ The `data` field is a positional array. The order must match the function signature.
124
+ For simplicity, the examples below only send the first few arguments and rely on server defaults for the rest.
125
+
126
+ #### 2.1 Synchronous API – `generate_image`
127
+
128
+ ```bash
129
+ curl -X POST "https://john6666-diffusecraftmod.hf.space/call/generate_image" \
130
+ -H "Authorization: Bearer $HF_TOKEN" \
131
+ -H "Content-Type: application/json" \
132
+ -d '{
133
+ "data": [
134
+ "Hello!!", // prompt
135
+ "lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, worst quality, low quality", // negative_prompt
136
+ 1, // num_images
137
+ 28, // num_inference_steps
138
+ 7.0, // guidance_scale
139
+ 0, // clip_skip
140
+ -1 // seed
141
+ // All subsequent parameters will use their default values
142
+ ]
143
+ }'
144
+ ```
145
+
146
+ #### 2.2 Streaming API – `generate_image_stream`
147
+
148
+ ```bash
149
+ curl -X POST "https://john6666-diffusecraftmod.hf.space/call/generate_image_stream" \
150
+ -H "Authorization: Bearer $HF_TOKEN" \
151
+ -H "Content-Type: application/json" \
152
+ -d '{
153
+ "data": [
154
+ "Hello!!",
155
+ "lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, worst quality, low quality",
156
+ 1,
157
+ 28,
158
+ 7.0,
159
+ 0,
160
+ -1
161
+ ]
162
+ }'
163
+ ```
164
+
165
+ For full parameter coverage (all advanced options such as LoRAs, ControlNet, IP-Adapter, etc.),
166
+ refer to the Space’s “View API” page and adapt the examples above accordingly.
app.py CHANGED
@@ -199,11 +199,6 @@ class GuiSD:
199
  # Avoid duplicate downloads
200
  self.active_downloads = set()
201
  self.download_lock = threading.Lock()
202
-
203
- # Anti-abuse: track new model requests.
204
- self.used_models = []
205
- self.new_model_history = []
206
-
207
  def update_storage_models(self, storage_floor_gb=24, required_inventory_for_purge=3):
208
  while get_used_storage_gb() > storage_floor_gb:
209
  if len(self.inventory) < required_inventory_for_purge:
@@ -228,34 +223,6 @@ class GuiSD:
228
  print(self.inventory)
229
 
230
  def load_new_model(self, model_name, vae_model, task, controlnet_model, progress=gr.Progress(track_tqdm=True)):
231
-
232
- if model_name != model_list[0]:
233
- # --- Anti-Abuse Check Start ---
234
- if model_name in self.used_models:
235
- # Move to the end to mark as the most recently used.
236
- self.used_models.remove(model_name)
237
- self.used_models.append(model_name)
238
- else:
239
- current_time = datetime.now()
240
- # Retain history of new model requests from the last 20 minutes.
241
- self.new_model_history = [
242
- t for t in self.new_model_history
243
- if (current_time - t).total_seconds() < 1200
244
- ]
245
-
246
- # Allow a maximum of 5 new model requests per 20 minutes.
247
- if len(self.new_model_history) >= 5:
248
- yield "Rate limit exceeded: Too many new models requested."
249
- raise gr.Error("Too many new models requested. Please reuse your previously loaded models or wait a few minutes before trying new ones.")
250
-
251
- self.new_model_history.append(current_time)
252
- self.used_models.append(model_name)
253
-
254
- # Cap the reuse list to the 5 most recent models.
255
- if len(self.used_models) > 5:
256
- self.used_models.pop(0)
257
- # --- Anti-Abuse Check End ---
258
-
259
  lock_key = model_name
260
 
261
  while True:
@@ -878,7 +845,7 @@ CSS ="""
878
  .desc [src$='#float'] { float: right; margin: 20px; }
879
  """
880
 
881
- with gr.Blocks(elem_id="main", fill_width=True, fill_height=False) as app:
882
  gr.Markdown("# 🧩 DiffuseCraft Mod", elem_classes="title")
883
  gr.Markdown("This space is a modification of [r3gm's DiffuseCraft](https://huggingface.co/spaces/r3gm/DiffuseCraft).", elem_classes="info")
884
  with gr.Column():
@@ -923,9 +890,9 @@ with gr.Blocks(elem_id="main", fill_width=True, fill_height=False) as app:
923
  keep_tags_gui = gr.Radio(label="Remove tags leaving only the following", choices=["body", "dress", "all"], value="all")
924
  image_algorithms = gr.CheckboxGroup(["Use WD Tagger"], label="Algorithms", value=["Use WD Tagger"], visible=False)
925
  generate_from_image_btn_gui = gr.Button(value="GENERATE TAGS FROM IMAGE")
926
- prompt_gui = gr.Textbox(lines=6, placeholder="1girl, solo, ...", label="Prompt", buttons=["copy"])
927
  with gr.Accordion("Negative prompt, etc.", open=False) as menu_negative:
928
- neg_prompt_gui = gr.Textbox(lines=3, placeholder="Enter Neg prompt", label="Negative prompt", value="lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, worst quality, low quality, very displeasing, (bad)", buttons=["copy"])
929
  translate_prompt_button = gr.Button(value="Translate prompt to English", size="sm", variant="secondary")
930
  with gr.Row():
931
  insert_prompt_gui = gr.Radio(label="Insert reccomended positive / negative prompt", choices=["None", "Auto", "Animagine", "Pony"], value="Auto", interactive=True)
@@ -955,7 +922,7 @@ with gr.Blocks(elem_id="main", fill_width=True, fill_height=False) as app:
955
  update_task_options,
956
  [model_name_gui, task_gui],
957
  [task_gui],
958
- api_visibility="undocumented",
959
  )
960
 
961
  load_model_gui = gr.HTML(elem_id="load_model", elem_classes="contain")
@@ -972,7 +939,8 @@ with gr.Blocks(elem_id="main", fill_width=True, fill_height=False) as app:
972
  # height="auto",
973
  interactive=False,
974
  preview=False,
975
- buttons=["download", "fullscreen"],
 
976
  selected_index=50,
977
  format="png",
978
  )
@@ -983,9 +951,9 @@ with gr.Blocks(elem_id="main", fill_width=True, fill_height=False) as app:
983
 
984
  with gr.Accordion("History", open=False):
985
  history_files = gr.Files(interactive=False, visible=False)
986
- history_gallery = gr.Gallery(label="History", columns=6, object_fit="contain", format="png", interactive=False, buttons=["download", "fullscreen"])
987
  history_clear_button = gr.Button(value="Clear History", variant="secondary")
988
- history_clear_button.click(lambda: ([], []), None, [history_gallery, history_files], queue=False, api_visibility="undocumented")
989
 
990
  with gr.Row(equal_height=False, variant="default"):
991
  gpu_duration_gui = gr.Number(minimum=5, maximum=240, value=20, show_label=False, container=False, info="GPU time duration (seconds)")
@@ -1165,7 +1133,7 @@ with gr.Blocks(elem_id="main", fill_width=True, fill_height=False) as app:
1165
  return gr.Slider(minimum=-val_lora, maximum=val_lora, step=0.01, value=1.0, label=label, visible=visible)
1166
 
1167
  def lora_textbox(label):
1168
- return gr.Textbox(label=label, info="Example of prompt:", value="None", buttons=["copy"], interactive=False, visible=False)
1169
 
1170
  with gr.Row():
1171
  with gr.Column():
@@ -1236,7 +1204,7 @@ with gr.Blocks(elem_id="main", fill_width=True, fill_height=False) as app:
1236
  search_civitai_button_lora = gr.Button("Search on Civitai")
1237
  search_civitai_desc_lora = gr.Markdown(value="", visible=False, elem_classes="desc")
1238
  with gr.Accordion("Select from Gallery", open=False):
1239
- search_civitai_gallery_lora = gr.Gallery([], label="Results", allow_preview=False, columns=5, buttons=["download", "fullscreen"], interactive=False)
1240
  search_civitai_result_lora = gr.Dropdown(label="Search Results", choices=[("", "")], value="", allow_custom_value=True, visible=False)
1241
  with gr.Row():
1242
  text_lora = 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, scale=4)
@@ -1320,8 +1288,8 @@ with gr.Blocks(elem_id="main", fill_width=True, fill_height=False) as app:
1320
  use_textual_inversion_gui = gr.CheckboxGroup(choices=get_embed_list(get_model_pipeline(model_name_gui.value)) if active_textual_inversion_gui.value else [], value=None, label="Use Textual Invertion in prompt")
1321
  def update_textual_inversion_gui(active_textual_inversion_gui, model_name_gui):
1322
  return gr.update(choices=get_embed_list(get_model_pipeline(model_name_gui)) if active_textual_inversion_gui else [])
1323
- active_textual_inversion_gui.change(update_textual_inversion_gui, [active_textual_inversion_gui, model_name_gui], [use_textual_inversion_gui], api_visibility="undocumented")
1324
- model_name_gui.change(update_textual_inversion_gui, [active_textual_inversion_gui, model_name_gui], [use_textual_inversion_gui], api_visibility="undocumented")
1325
 
1326
  with gr.Accordion("ControlNet / Img2img / Inpaint", open=False, visible=True) as menu_i2i:
1327
  with gr.Row():
@@ -1359,7 +1327,7 @@ with gr.Blocks(elem_id="main", fill_width=True, fill_height=False) as app:
1359
  change_preprocessor_choices,
1360
  [task_gui],
1361
  [preprocessor_name_gui],
1362
- api_visibility="undocumented",
1363
  )
1364
 
1365
  with gr.Row():
@@ -1419,7 +1387,7 @@ with gr.Blocks(elem_id="main", fill_width=True, fill_height=False) as app:
1419
  gr.Info(f"{len(sd_gen.model.STYLE_NAMES)} styles loaded")
1420
  return gr.update(value=None, choices=sd_gen.model.STYLE_NAMES)
1421
 
1422
- style_button.click(load_json_style_file, [style_json_gui], [style_prompt_gui], api_visibility="undocumented")
1423
 
1424
  with gr.Accordion("Other settings", open=False, visible=True) as menu_other:
1425
  with gr.Row():
@@ -1541,7 +1509,7 @@ with gr.Blocks(elem_id="main", fill_width=True, fill_height=False) as app:
1541
 
1542
  def change_visibility_canvas():
1543
  return gr.update(visible=True, interactive=True), gr.update(visible=False)
1544
- show_canvas.click(change_visibility_canvas, [], [image_base, show_canvas], api_visibility="undocumented")
1545
 
1546
  invert_mask = gr.Checkbox(value=False, label="Invert mask")
1547
  btn = gr.Button("Create mask")
@@ -1555,7 +1523,7 @@ with gr.Blocks(elem_id="main", fill_width=True, fill_height=False) as app:
1555
 
1556
  def send_img(img_source, img_result):
1557
  return img_source, img_result
1558
- btn_send.click(send_img, [img_source, img_result], [image_control, image_mask_gui], api_visibility="undocumented")
1559
 
1560
  with gr.Tab("PNG Info"):
1561
  with gr.Row():
@@ -1563,7 +1531,7 @@ with gr.Blocks(elem_id="main", fill_width=True, fill_height=False) as app:
1563
  image_metadata = gr.Image(label="Image with metadata", type="pil", sources=["upload"])
1564
 
1565
  with gr.Column():
1566
- result_metadata = gr.Textbox(label="Metadata", show_label=True, buttons=["copy"], interactive=False, container=True, max_lines=99)
1567
 
1568
  image_metadata.change(
1569
  fn=extract_exif_data,
@@ -1601,11 +1569,11 @@ with gr.Blocks(elem_id="main", fill_width=True, fill_height=False) as app:
1601
  [menu_model, menu_from_image, menu_negative, menu_gen, menu_hires, menu_lora, menu_advanced,
1602
  menu_example, task_gui, quick_speed_gui],
1603
  queue=False,
1604
- api_visibility="undocumented",
1605
  )
1606
- model_name_gui.change(get_t2i_model_info, [model_name_gui], [model_info_gui], queue=False, api_visibility="undocumented")
1607
- translate_prompt_gui.click(translate_to_en, [prompt_gui], [prompt_gui], queue=False, api_visibility="undocumented")\
1608
- .then(translate_to_en, [neg_prompt_gui], [neg_prompt_gui], queue=False, api_visibility="undocumented")
1609
 
1610
  gr.on(
1611
  triggers=[quick_model_type_gui.change, quick_genre_gui.change, quick_speed_gui.change, quick_aspect_gui.change],
@@ -1614,7 +1582,7 @@ with gr.Blocks(elem_id="main", fill_width=True, fill_height=False) as app:
1614
  outputs=[quality_selector_gui, style_selector_gui, sampler_selector_gui, optimization_gui, insert_prompt_gui],
1615
  queue=False,
1616
  trigger_mode="once",
1617
- api_visibility="undocumented",
1618
  )
1619
  gr.on(
1620
  triggers=[quality_selector_gui.change, style_selector_gui.change, insert_prompt_gui.change],
@@ -1623,7 +1591,7 @@ with gr.Blocks(elem_id="main", fill_width=True, fill_height=False) as app:
1623
  outputs=[prompt_gui, neg_prompt_gui, quick_model_type_gui],
1624
  queue=False,
1625
  trigger_mode="once",
1626
- api_visibility="undocumented",
1627
  )
1628
  sampler_selector_gui.change(set_sampler_settings, [sampler_selector_gui], [sampler_gui, steps_gui, cfg_gui, clip_skip_gui, img_width_gui, img_height_gui, optimization_gui], queue=False)
1629
  optimization_gui.change(set_optimization, [optimization_gui, steps_gui, cfg_gui, sampler_gui, clip_skip_gui, lora5_gui, lora_scale_5_gui], [steps_gui, cfg_gui, sampler_gui, clip_skip_gui, lora5_gui, lora_scale_5_gui], queue=False)
@@ -1646,15 +1614,15 @@ with gr.Blocks(elem_id="main", fill_width=True, fill_height=False) as app:
1646
  lora7_gui, lora_scale_7_gui, lora7_info_gui, lora7_copy_gui, lora7_desc_gui],
1647
  queue=False,
1648
  trigger_mode="once",
1649
- api_visibility="undocumented",
1650
  )
1651
- lora1_copy_gui.click(apply_lora_prompt, [prompt_gui, lora1_info_gui], [prompt_gui], queue=False, api_visibility="undocumented")
1652
- lora2_copy_gui.click(apply_lora_prompt, [prompt_gui, lora2_info_gui], [prompt_gui], queue=False, api_visibility="undocumented")
1653
- lora3_copy_gui.click(apply_lora_prompt, [prompt_gui, lora3_info_gui], [prompt_gui], queue=False, api_visibility="undocumented")
1654
- lora4_copy_gui.click(apply_lora_prompt, [prompt_gui, lora4_info_gui], [prompt_gui], queue=False, api_visibility="undocumented")
1655
- lora5_copy_gui.click(apply_lora_prompt, [prompt_gui, lora5_info_gui], [prompt_gui], queue=False, api_visibility="undocumented")
1656
- lora6_copy_gui.click(apply_lora_prompt, [prompt_gui, lora6_info_gui], [prompt_gui], queue=False, api_visibility="undocumented")
1657
- lora7_copy_gui.click(apply_lora_prompt, [prompt_gui, lora7_info_gui], [prompt_gui], queue=False, api_visibility="undocumented")
1658
  gr.on(
1659
  triggers=[search_civitai_button_lora.click, search_civitai_query_lora.submit],
1660
  fn=search_civitai_lora,
@@ -1663,54 +1631,54 @@ with gr.Blocks(elem_id="main", fill_width=True, fill_height=False) as app:
1663
  outputs=[search_civitai_result_lora, search_civitai_desc_lora, search_civitai_button_lora, search_civitai_query_lora, search_civitai_gallery_lora],
1664
  queue=True,
1665
  scroll_to_output=True,
1666
- api_visibility="undocumented",
1667
  )
1668
- search_civitai_result_lora.change(select_civitai_lora, [search_civitai_result_lora], [text_lora, search_civitai_desc_lora], queue=False, scroll_to_output=True, api_visibility="undocumented")
1669
- search_civitai_gallery_lora.select(update_civitai_selection, None, [search_civitai_result_lora], queue=False, api_visibility="undocumented")
1670
- button_lora.click(get_my_lora, [text_lora, romanize_text], [lora1_gui, lora2_gui, lora3_gui, lora4_gui, lora5_gui, lora6_gui, lora7_gui, new_lora_status], scroll_to_output=True, api_visibility="undocumented")
1671
- upload_button_lora.upload(upload_file_lora, [upload_button_lora], [file_output_lora, upload_button_lora], api_visibility="undocumented").success(
1672
- move_file_lora, [file_output_lora], [lora1_gui, lora2_gui, lora3_gui, lora4_gui, lora5_gui, lora6_gui, lora7_gui], scroll_to_output=True, api_visibility="undocumented")
1673
 
1674
- use_textual_inversion_gui.change(set_textual_inversion_prompt, [use_textual_inversion_gui, prompt_gui, neg_prompt_gui, prompt_syntax_gui], [prompt_gui, neg_prompt_gui], api_visibility="undocumented")
1675
 
1676
  generate_from_image_btn_gui.click(
1677
- lambda: ("", "", ""), None, [series_dbt, character_dbt, prompt_gui], queue=False, api_visibility="undocumented",
1678
  ).success(
1679
  predict_tags_wd,
1680
  [input_image_gui, prompt_gui, image_algorithms, general_threshold_gui, character_threshold_gui],
1681
  [series_dbt, character_dbt, prompt_gui, copy_button_dbt],
1682
- api_visibility="undocumented",
1683
  ).success(
1684
- compose_prompt_to_copy, [character_dbt, series_dbt, prompt_gui], [prompt_gui], queue=False, api_visibility="undocumented",
1685
  ).success(
1686
- remove_specific_prompt, [prompt_gui, keep_tags_gui], [prompt_gui], queue=False, api_visibility="undocumented",
1687
  ).success(
1688
- convert_danbooru_to_e621_prompt, [prompt_gui, tag_type_gui], [prompt_gui], queue=False, api_visibility="undocumented",
1689
  ).success(
1690
- insert_recom_prompt, [prompt_gui, neg_prompt_gui, recom_prompt_gui], [prompt_gui, neg_prompt_gui], queue=False, api_visibility="undocumented",
1691
  )
1692
 
1693
- prompt_type_button.click(convert_danbooru_to_e621_prompt, [prompt_gui, prompt_type_gui], [prompt_gui], queue=False, api_visibility="undocumented")
1694
- random_character_gui.click(select_random_character, [series_dbt, character_dbt], [series_dbt, character_dbt], queue=False, api_visibility="undocumented")
1695
  generate_db_random_button.click(
1696
  v2_random_prompt,
1697
  [prompt_gui, series_dbt, character_dbt,
1698
  rating_dbt, aspect_ratio_dbt, length_dbt, identity_dbt, ban_tags_dbt, model_name_dbt],
1699
  [prompt_gui, series_dbt, character_dbt],
1700
- api_visibility="undocumented",
1701
  ).success(
1702
- convert_danbooru_to_e621_prompt, [prompt_gui, tag_type_gui], [prompt_gui], queue=False, api_visibility="undocumented",
1703
  )
1704
 
1705
- translate_prompt_button.click(translate_prompt, [prompt_gui], [prompt_gui], queue=False, api_visibility="undocumented")
1706
- translate_prompt_button.click(translate_prompt, [character_dbt], [character_dbt], queue=False, api_visibility="undocumented")
1707
- translate_prompt_button.click(translate_prompt, [series_dbt], [series_dbt], queue=False, api_visibility="undocumented")
1708
 
1709
  generate_button.click(
1710
  fn=insert_model_recom_prompt,
1711
  inputs=[prompt_gui, neg_prompt_gui, model_name_gui, recom_prompt_gui],
1712
  outputs=[prompt_gui, neg_prompt_gui],
1713
- api_visibility="private",
1714
  queue=False,
1715
  ).success(
1716
  fn=sd_gen.load_new_model,
@@ -1853,8 +1821,8 @@ with gr.Blocks(elem_id="main", fill_width=True, fill_height=False) as app:
1853
  api_name="sd_gen_generate_pipeline",
1854
  queue=True,
1855
  show_progress="full",
1856
- ).success(save_gallery_images, [result_images, model_name_gui], [result_images, result_images_files], queue=False, api_visibility="undocumented")\
1857
- .success(save_gallery_history, [result_images, result_images_files, history_gallery, history_files], [history_gallery, history_files], queue=False, api_visibility="undocumented")
1858
 
1859
  with gr.Tab("Danbooru Tags Transformer with WD Tagger", render=True):
1860
  with gr.Column(scale=2):
@@ -1893,60 +1861,60 @@ with gr.Blocks(elem_id="main", fill_width=True, fill_height=False) as app:
1893
  generate_btn = gr.Button(value="GENERATE TAGS", size="lg", variant="primary")
1894
  with gr.Row():
1895
  with gr.Group():
1896
- output_text = gr.TextArea(label="Output tags", interactive=False, buttons=["copy"])
1897
  with gr.Row():
1898
  copy_btn = gr.Button(value="Copy to clipboard", size="sm", interactive=False)
1899
  copy_prompt_btn = gr.Button(value="Copy to primary prompt", size="sm", interactive=False)
1900
  with gr.Group():
1901
- output_text_pony = gr.TextArea(label="Output tags (Pony e621 style)", interactive=False, buttons=["copy"])
1902
  with gr.Row():
1903
  copy_btn_pony = gr.Button(value="Copy to clipboard", size="sm", interactive=False)
1904
  copy_prompt_btn_pony = gr.Button(value="Copy to primary prompt", size="sm", interactive=False)
1905
  description_ui()
1906
 
1907
- translate_input_prompt_button.click(translate_prompt, inputs=[input_general], outputs=[input_general], queue=False, api_visibility="undocumented")
1908
- translate_input_prompt_button.click(translate_prompt, inputs=[input_character], outputs=[input_character], queue=False, api_visibility="undocumented")
1909
- translate_input_prompt_button.click(translate_prompt, inputs=[input_copyright], outputs=[input_copyright], queue=False, api_visibility="undocumented")
1910
 
1911
  generate_from_image_btn.click(
1912
- lambda: ("", "", ""), None, [input_copyright, input_character, input_general], queue=False, api_visibility="undocumented",
1913
  ).success(
1914
  predict_tags_wd,
1915
  [input_image, input_general, image_algorithms, general_threshold, character_threshold],
1916
  [input_copyright, input_character, input_general, copy_input_btn],
1917
- api_visibility="undocumented",
1918
  ).success(
1919
- remove_specific_prompt, inputs=[input_general, keep_tags], outputs=[input_general], queue=False, api_visibility="undocumented",
1920
  ).success(
1921
- convert_danbooru_to_e621_prompt, inputs=[input_general, input_tag_type], outputs=[input_general], queue=False, api_visibility="undocumented",
1922
  ).success(
1923
- insert_recom_prompt, inputs=[input_general, dummy_np, recom_prompt], outputs=[input_general, dummy_np], queue=False, api_visibility="undocumented",
1924
  ).success(lambda: gr.update(interactive=True), None, [copy_prompt_btn_input], queue=False)
1925
- copy_input_btn.click(compose_prompt_to_copy, inputs=[input_character, input_copyright, input_general], outputs=[input_tags_to_copy], api_visibility="undocumented")\
1926
- .success(gradio_copy_text, inputs=[input_tags_to_copy], js=COPY_ACTION_JS, api_visibility="undocumented")
1927
- copy_prompt_btn_input.click(compose_prompt_to_copy, inputs=[input_character, input_copyright, input_general], outputs=[input_tags_to_copy], api_visibility="undocumented")\
1928
- .success(gradio_copy_prompt, inputs=[input_tags_to_copy], outputs=[prompt_gui], api_visibility="undocumented")
1929
 
1930
- pick_random_character.click(select_random_character, [input_copyright, input_character], [input_copyright, input_character], api_visibility="undocumented")
1931
 
1932
  generate_btn.click(
1933
  v2_upsampling_prompt,
1934
  [model_name, input_copyright, input_character, input_general,
1935
  input_rating, input_aspect_ratio, input_length, input_identity, input_ban_tags],
1936
  [output_text],
1937
- api_visibility="undocumented",
1938
  ).success(
1939
- convert_danbooru_to_e621_prompt, inputs=[output_text, tag_type], outputs=[output_text_pony], queue=False, api_visibility="undocumented",
1940
  ).success(
1941
- insert_recom_prompt, inputs=[output_text, dummy_np, recom_animagine], outputs=[output_text, dummy_np], queue=False, api_visibility="undocumented",
1942
  ).success(
1943
- insert_recom_prompt, inputs=[output_text_pony, dummy_np, recom_pony], outputs=[output_text_pony, dummy_np], queue=False, api_visibility="undocumented",
1944
  ).success(lambda: (gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True)),
1945
- None, [copy_btn, copy_btn_pony, copy_prompt_btn, copy_prompt_btn_pony], queue=False, api_visibility="undocumented")
1946
- copy_btn.click(gradio_copy_text, inputs=[output_text], js=COPY_ACTION_JS, api_visibility="undocumented")
1947
- copy_btn_pony.click(gradio_copy_text, inputs=[output_text_pony], js=COPY_ACTION_JS, api_visibility="undocumented")
1948
- copy_prompt_btn.click(gradio_copy_prompt, inputs=[output_text], outputs=[prompt_gui], api_visibility="undocumented")
1949
- copy_prompt_btn_pony.click(gradio_copy_prompt, inputs=[output_text_pony], outputs=[prompt_gui], api_visibility="undocumented")
1950
 
1951
  from typing import Any, Dict, List, Optional, Tuple, Generator
1952
  # 1) Helper: model loader (keeps existing behavior)
@@ -2284,9 +2252,10 @@ with gr.Blocks(elem_id="main", fill_width=True, fill_height=False) as app:
2284
  yield from _generate_image(argv)
2285
 
2286
  # 5) Register two APIs with explicit signatures
2287
- gr.api(generate_image, api_name="generate_image", api_visibility="public", queue=True, concurrency_id="gpu")
2288
- gr.api(generate_image_stream, api_name="generate_image_stream", api_visibility="public", queue=True, concurrency_id="gpu")
2289
 
 
2290
  gr.DuplicateButton(value="Duplicate Space for private use (This demo does not work on CPU. Requires GPU Space)")
2291
 
2292
 
@@ -2299,7 +2268,5 @@ if __name__ == "__main__":
2299
  ssr_mode=args.ssr,
2300
  mcp_server=False,
2301
  allowed_paths=[allowed_path],
2302
- theme=args.theme,
2303
- css=CSS,
2304
  )
2305
  ## END MOD
 
199
  # Avoid duplicate downloads
200
  self.active_downloads = set()
201
  self.download_lock = threading.Lock()
 
 
 
 
 
202
  def update_storage_models(self, storage_floor_gb=24, required_inventory_for_purge=3):
203
  while get_used_storage_gb() > storage_floor_gb:
204
  if len(self.inventory) < required_inventory_for_purge:
 
223
  print(self.inventory)
224
 
225
  def load_new_model(self, model_name, vae_model, task, controlnet_model, progress=gr.Progress(track_tqdm=True)):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
  lock_key = model_name
227
 
228
  while True:
 
845
  .desc [src$='#float'] { float: right; margin: 20px; }
846
  """
847
 
848
+ with gr.Blocks(theme=args.theme, elem_id="main", fill_width=True, fill_height=False, css=CSS) as app:
849
  gr.Markdown("# 🧩 DiffuseCraft Mod", elem_classes="title")
850
  gr.Markdown("This space is a modification of [r3gm's DiffuseCraft](https://huggingface.co/spaces/r3gm/DiffuseCraft).", elem_classes="info")
851
  with gr.Column():
 
890
  keep_tags_gui = gr.Radio(label="Remove tags leaving only the following", choices=["body", "dress", "all"], value="all")
891
  image_algorithms = gr.CheckboxGroup(["Use WD Tagger"], label="Algorithms", value=["Use WD Tagger"], visible=False)
892
  generate_from_image_btn_gui = gr.Button(value="GENERATE TAGS FROM IMAGE")
893
+ prompt_gui = gr.Textbox(lines=6, placeholder="1girl, solo, ...", label="Prompt", show_copy_button=True)
894
  with gr.Accordion("Negative prompt, etc.", open=False) as menu_negative:
895
+ neg_prompt_gui = gr.Textbox(lines=3, placeholder="Enter Neg prompt", label="Negative prompt", value="lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, worst quality, low quality, very displeasing, (bad)", show_copy_button=True)
896
  translate_prompt_button = gr.Button(value="Translate prompt to English", size="sm", variant="secondary")
897
  with gr.Row():
898
  insert_prompt_gui = gr.Radio(label="Insert reccomended positive / negative prompt", choices=["None", "Auto", "Animagine", "Pony"], value="Auto", interactive=True)
 
922
  update_task_options,
923
  [model_name_gui, task_gui],
924
  [task_gui],
925
+ show_api=False,
926
  )
927
 
928
  load_model_gui = gr.HTML(elem_id="load_model", elem_classes="contain")
 
939
  # height="auto",
940
  interactive=False,
941
  preview=False,
942
+ show_share_button=False,
943
+ show_download_button=True,
944
  selected_index=50,
945
  format="png",
946
  )
 
951
 
952
  with gr.Accordion("History", open=False):
953
  history_files = gr.Files(interactive=False, visible=False)
954
+ history_gallery = gr.Gallery(label="History", columns=6, object_fit="contain", format="png", interactive=False, show_share_button=False, show_download_button=True)
955
  history_clear_button = gr.Button(value="Clear History", variant="secondary")
956
+ history_clear_button.click(lambda: ([], []), None, [history_gallery, history_files], queue=False, show_api=False)
957
 
958
  with gr.Row(equal_height=False, variant="default"):
959
  gpu_duration_gui = gr.Number(minimum=5, maximum=240, value=20, show_label=False, container=False, info="GPU time duration (seconds)")
 
1133
  return gr.Slider(minimum=-val_lora, maximum=val_lora, step=0.01, value=1.0, label=label, visible=visible)
1134
 
1135
  def lora_textbox(label):
1136
+ return gr.Textbox(label=label, info="Example of prompt:", value="None", show_copy_button=True, interactive=False, visible=False)
1137
 
1138
  with gr.Row():
1139
  with gr.Column():
 
1204
  search_civitai_button_lora = gr.Button("Search on Civitai")
1205
  search_civitai_desc_lora = gr.Markdown(value="", visible=False, elem_classes="desc")
1206
  with gr.Accordion("Select from Gallery", open=False):
1207
+ search_civitai_gallery_lora = gr.Gallery([], label="Results", allow_preview=False, columns=5, show_share_button=False, interactive=False)
1208
  search_civitai_result_lora = gr.Dropdown(label="Search Results", choices=[("", "")], value="", allow_custom_value=True, visible=False)
1209
  with gr.Row():
1210
  text_lora = 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, scale=4)
 
1288
  use_textual_inversion_gui = gr.CheckboxGroup(choices=get_embed_list(get_model_pipeline(model_name_gui.value)) if active_textual_inversion_gui.value else [], value=None, label="Use Textual Invertion in prompt")
1289
  def update_textual_inversion_gui(active_textual_inversion_gui, model_name_gui):
1290
  return gr.update(choices=get_embed_list(get_model_pipeline(model_name_gui)) if active_textual_inversion_gui else [])
1291
+ active_textual_inversion_gui.change(update_textual_inversion_gui, [active_textual_inversion_gui, model_name_gui], [use_textual_inversion_gui], show_api=False)
1292
+ model_name_gui.change(update_textual_inversion_gui, [active_textual_inversion_gui, model_name_gui], [use_textual_inversion_gui], show_api=False)
1293
 
1294
  with gr.Accordion("ControlNet / Img2img / Inpaint", open=False, visible=True) as menu_i2i:
1295
  with gr.Row():
 
1327
  change_preprocessor_choices,
1328
  [task_gui],
1329
  [preprocessor_name_gui],
1330
+ show_api=False,
1331
  )
1332
 
1333
  with gr.Row():
 
1387
  gr.Info(f"{len(sd_gen.model.STYLE_NAMES)} styles loaded")
1388
  return gr.update(value=None, choices=sd_gen.model.STYLE_NAMES)
1389
 
1390
+ style_button.click(load_json_style_file, [style_json_gui], [style_prompt_gui], show_api=False)
1391
 
1392
  with gr.Accordion("Other settings", open=False, visible=True) as menu_other:
1393
  with gr.Row():
 
1509
 
1510
  def change_visibility_canvas():
1511
  return gr.update(visible=True, interactive=True), gr.update(visible=False)
1512
+ show_canvas.click(change_visibility_canvas, [], [image_base, show_canvas], show_api=False)
1513
 
1514
  invert_mask = gr.Checkbox(value=False, label="Invert mask")
1515
  btn = gr.Button("Create mask")
 
1523
 
1524
  def send_img(img_source, img_result):
1525
  return img_source, img_result
1526
+ btn_send.click(send_img, [img_source, img_result], [image_control, image_mask_gui], show_api=False)
1527
 
1528
  with gr.Tab("PNG Info"):
1529
  with gr.Row():
 
1531
  image_metadata = gr.Image(label="Image with metadata", type="pil", sources=["upload"])
1532
 
1533
  with gr.Column():
1534
+ result_metadata = gr.Textbox(label="Metadata", show_label=True, show_copy_button=True, interactive=False, container=True, max_lines=99)
1535
 
1536
  image_metadata.change(
1537
  fn=extract_exif_data,
 
1569
  [menu_model, menu_from_image, menu_negative, menu_gen, menu_hires, menu_lora, menu_advanced,
1570
  menu_example, task_gui, quick_speed_gui],
1571
  queue=False,
1572
+ show_api=False,
1573
  )
1574
+ model_name_gui.change(get_t2i_model_info, [model_name_gui], [model_info_gui], queue=False, show_api=False)
1575
+ translate_prompt_gui.click(translate_to_en, [prompt_gui], [prompt_gui], queue=False, show_api=False)\
1576
+ .then(translate_to_en, [neg_prompt_gui], [neg_prompt_gui], queue=False, show_api=False)
1577
 
1578
  gr.on(
1579
  triggers=[quick_model_type_gui.change, quick_genre_gui.change, quick_speed_gui.change, quick_aspect_gui.change],
 
1582
  outputs=[quality_selector_gui, style_selector_gui, sampler_selector_gui, optimization_gui, insert_prompt_gui],
1583
  queue=False,
1584
  trigger_mode="once",
1585
+ show_api=False,
1586
  )
1587
  gr.on(
1588
  triggers=[quality_selector_gui.change, style_selector_gui.change, insert_prompt_gui.change],
 
1591
  outputs=[prompt_gui, neg_prompt_gui, quick_model_type_gui],
1592
  queue=False,
1593
  trigger_mode="once",
1594
+ show_api=False,
1595
  )
1596
  sampler_selector_gui.change(set_sampler_settings, [sampler_selector_gui], [sampler_gui, steps_gui, cfg_gui, clip_skip_gui, img_width_gui, img_height_gui, optimization_gui], queue=False)
1597
  optimization_gui.change(set_optimization, [optimization_gui, steps_gui, cfg_gui, sampler_gui, clip_skip_gui, lora5_gui, lora_scale_5_gui], [steps_gui, cfg_gui, sampler_gui, clip_skip_gui, lora5_gui, lora_scale_5_gui], queue=False)
 
1614
  lora7_gui, lora_scale_7_gui, lora7_info_gui, lora7_copy_gui, lora7_desc_gui],
1615
  queue=False,
1616
  trigger_mode="once",
1617
+ show_api=False,
1618
  )
1619
+ lora1_copy_gui.click(apply_lora_prompt, [prompt_gui, lora1_info_gui], [prompt_gui], queue=False, show_api=False)
1620
+ lora2_copy_gui.click(apply_lora_prompt, [prompt_gui, lora2_info_gui], [prompt_gui], queue=False, show_api=False)
1621
+ lora3_copy_gui.click(apply_lora_prompt, [prompt_gui, lora3_info_gui], [prompt_gui], queue=False, show_api=False)
1622
+ lora4_copy_gui.click(apply_lora_prompt, [prompt_gui, lora4_info_gui], [prompt_gui], queue=False, show_api=False)
1623
+ lora5_copy_gui.click(apply_lora_prompt, [prompt_gui, lora5_info_gui], [prompt_gui], queue=False, show_api=False)
1624
+ lora6_copy_gui.click(apply_lora_prompt, [prompt_gui, lora6_info_gui], [prompt_gui], queue=False, show_api=False)
1625
+ lora7_copy_gui.click(apply_lora_prompt, [prompt_gui, lora7_info_gui], [prompt_gui], queue=False, show_api=False)
1626
  gr.on(
1627
  triggers=[search_civitai_button_lora.click, search_civitai_query_lora.submit],
1628
  fn=search_civitai_lora,
 
1631
  outputs=[search_civitai_result_lora, search_civitai_desc_lora, search_civitai_button_lora, search_civitai_query_lora, search_civitai_gallery_lora],
1632
  queue=True,
1633
  scroll_to_output=True,
1634
+ show_api=False,
1635
  )
1636
+ search_civitai_result_lora.change(select_civitai_lora, [search_civitai_result_lora], [text_lora, search_civitai_desc_lora], queue=False, scroll_to_output=True, show_api=False)
1637
+ search_civitai_gallery_lora.select(update_civitai_selection, None, [search_civitai_result_lora], queue=False, show_api=False)
1638
+ button_lora.click(get_my_lora, [text_lora, romanize_text], [lora1_gui, lora2_gui, lora3_gui, lora4_gui, lora5_gui, lora6_gui, lora7_gui, new_lora_status], scroll_to_output=True, show_api=False)
1639
+ upload_button_lora.upload(upload_file_lora, [upload_button_lora], [file_output_lora, upload_button_lora], show_api=False).success(
1640
+ move_file_lora, [file_output_lora], [lora1_gui, lora2_gui, lora3_gui, lora4_gui, lora5_gui, lora6_gui, lora7_gui], scroll_to_output=True, show_api=False)
1641
 
1642
+ use_textual_inversion_gui.change(set_textual_inversion_prompt, [use_textual_inversion_gui, prompt_gui, neg_prompt_gui, prompt_syntax_gui], [prompt_gui, neg_prompt_gui], show_api=False)
1643
 
1644
  generate_from_image_btn_gui.click(
1645
+ lambda: ("", "", ""), None, [series_dbt, character_dbt, prompt_gui], queue=False, show_api=False,
1646
  ).success(
1647
  predict_tags_wd,
1648
  [input_image_gui, prompt_gui, image_algorithms, general_threshold_gui, character_threshold_gui],
1649
  [series_dbt, character_dbt, prompt_gui, copy_button_dbt],
1650
+ show_api=False,
1651
  ).success(
1652
+ compose_prompt_to_copy, [character_dbt, series_dbt, prompt_gui], [prompt_gui], queue=False, show_api=False,
1653
  ).success(
1654
+ remove_specific_prompt, [prompt_gui, keep_tags_gui], [prompt_gui], queue=False, show_api=False,
1655
  ).success(
1656
+ convert_danbooru_to_e621_prompt, [prompt_gui, tag_type_gui], [prompt_gui], queue=False, show_api=False,
1657
  ).success(
1658
+ insert_recom_prompt, [prompt_gui, neg_prompt_gui, recom_prompt_gui], [prompt_gui, neg_prompt_gui], queue=False, show_api=False,
1659
  )
1660
 
1661
+ prompt_type_button.click(convert_danbooru_to_e621_prompt, [prompt_gui, prompt_type_gui], [prompt_gui], queue=False, show_api=False)
1662
+ random_character_gui.click(select_random_character, [series_dbt, character_dbt], [series_dbt, character_dbt], queue=False, show_api=False)
1663
  generate_db_random_button.click(
1664
  v2_random_prompt,
1665
  [prompt_gui, series_dbt, character_dbt,
1666
  rating_dbt, aspect_ratio_dbt, length_dbt, identity_dbt, ban_tags_dbt, model_name_dbt],
1667
  [prompt_gui, series_dbt, character_dbt],
1668
+ show_api=False,
1669
  ).success(
1670
+ convert_danbooru_to_e621_prompt, [prompt_gui, tag_type_gui], [prompt_gui], queue=False, show_api=False,
1671
  )
1672
 
1673
+ translate_prompt_button.click(translate_prompt, [prompt_gui], [prompt_gui], queue=False, show_api=False)
1674
+ translate_prompt_button.click(translate_prompt, [character_dbt], [character_dbt], queue=False, show_api=False)
1675
+ translate_prompt_button.click(translate_prompt, [series_dbt], [series_dbt], queue=False, show_api=False)
1676
 
1677
  generate_button.click(
1678
  fn=insert_model_recom_prompt,
1679
  inputs=[prompt_gui, neg_prompt_gui, model_name_gui, recom_prompt_gui],
1680
  outputs=[prompt_gui, neg_prompt_gui],
1681
+ api_name=False,
1682
  queue=False,
1683
  ).success(
1684
  fn=sd_gen.load_new_model,
 
1821
  api_name="sd_gen_generate_pipeline",
1822
  queue=True,
1823
  show_progress="full",
1824
+ ).success(save_gallery_images, [result_images, model_name_gui], [result_images, result_images_files], queue=False, show_api=False)\
1825
+ .success(save_gallery_history, [result_images, result_images_files, history_gallery, history_files], [history_gallery, history_files], queue=False, show_api=False)
1826
 
1827
  with gr.Tab("Danbooru Tags Transformer with WD Tagger", render=True):
1828
  with gr.Column(scale=2):
 
1861
  generate_btn = gr.Button(value="GENERATE TAGS", size="lg", variant="primary")
1862
  with gr.Row():
1863
  with gr.Group():
1864
+ output_text = gr.TextArea(label="Output tags", interactive=False, show_copy_button=True)
1865
  with gr.Row():
1866
  copy_btn = gr.Button(value="Copy to clipboard", size="sm", interactive=False)
1867
  copy_prompt_btn = gr.Button(value="Copy to primary prompt", size="sm", interactive=False)
1868
  with gr.Group():
1869
+ output_text_pony = gr.TextArea(label="Output tags (Pony e621 style)", interactive=False, show_copy_button=True)
1870
  with gr.Row():
1871
  copy_btn_pony = gr.Button(value="Copy to clipboard", size="sm", interactive=False)
1872
  copy_prompt_btn_pony = gr.Button(value="Copy to primary prompt", size="sm", interactive=False)
1873
  description_ui()
1874
 
1875
+ translate_input_prompt_button.click(translate_prompt, inputs=[input_general], outputs=[input_general], queue=False, show_api=False)
1876
+ translate_input_prompt_button.click(translate_prompt, inputs=[input_character], outputs=[input_character], queue=False, show_api=False)
1877
+ translate_input_prompt_button.click(translate_prompt, inputs=[input_copyright], outputs=[input_copyright], queue=False, show_api=False)
1878
 
1879
  generate_from_image_btn.click(
1880
+ lambda: ("", "", ""), None, [input_copyright, input_character, input_general], queue=False, show_api=False,
1881
  ).success(
1882
  predict_tags_wd,
1883
  [input_image, input_general, image_algorithms, general_threshold, character_threshold],
1884
  [input_copyright, input_character, input_general, copy_input_btn],
1885
+ show_api=False,
1886
  ).success(
1887
+ remove_specific_prompt, inputs=[input_general, keep_tags], outputs=[input_general], queue=False, show_api=False,
1888
  ).success(
1889
+ convert_danbooru_to_e621_prompt, inputs=[input_general, input_tag_type], outputs=[input_general], queue=False, show_api=False,
1890
  ).success(
1891
+ insert_recom_prompt, inputs=[input_general, dummy_np, recom_prompt], outputs=[input_general, dummy_np], queue=False, show_api=False,
1892
  ).success(lambda: gr.update(interactive=True), None, [copy_prompt_btn_input], queue=False)
1893
+ copy_input_btn.click(compose_prompt_to_copy, inputs=[input_character, input_copyright, input_general], outputs=[input_tags_to_copy], show_api=False)\
1894
+ .success(gradio_copy_text, inputs=[input_tags_to_copy], js=COPY_ACTION_JS, show_api=False)
1895
+ copy_prompt_btn_input.click(compose_prompt_to_copy, inputs=[input_character, input_copyright, input_general], outputs=[input_tags_to_copy], show_api=False)\
1896
+ .success(gradio_copy_prompt, inputs=[input_tags_to_copy], outputs=[prompt_gui], show_api=False)
1897
 
1898
+ pick_random_character.click(select_random_character, [input_copyright, input_character], [input_copyright, input_character], show_api=False)
1899
 
1900
  generate_btn.click(
1901
  v2_upsampling_prompt,
1902
  [model_name, input_copyright, input_character, input_general,
1903
  input_rating, input_aspect_ratio, input_length, input_identity, input_ban_tags],
1904
  [output_text],
1905
+ show_api=False,
1906
  ).success(
1907
+ convert_danbooru_to_e621_prompt, inputs=[output_text, tag_type], outputs=[output_text_pony], queue=False, show_api=False,
1908
  ).success(
1909
+ insert_recom_prompt, inputs=[output_text, dummy_np, recom_animagine], outputs=[output_text, dummy_np], queue=False, show_api=False,
1910
  ).success(
1911
+ insert_recom_prompt, inputs=[output_text_pony, dummy_np, recom_pony], outputs=[output_text_pony, dummy_np], queue=False, show_api=False,
1912
  ).success(lambda: (gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True)),
1913
+ None, [copy_btn, copy_btn_pony, copy_prompt_btn, copy_prompt_btn_pony], queue=False, show_api=False)
1914
+ copy_btn.click(gradio_copy_text, inputs=[output_text], js=COPY_ACTION_JS, show_api=False)
1915
+ copy_btn_pony.click(gradio_copy_text, inputs=[output_text_pony], js=COPY_ACTION_JS, show_api=False)
1916
+ copy_prompt_btn.click(gradio_copy_prompt, inputs=[output_text], outputs=[prompt_gui], show_api=False)
1917
+ copy_prompt_btn_pony.click(gradio_copy_prompt, inputs=[output_text_pony], outputs=[prompt_gui], show_api=False)
1918
 
1919
  from typing import Any, Dict, List, Optional, Tuple, Generator
1920
  # 1) Helper: model loader (keeps existing behavior)
 
2252
  yield from _generate_image(argv)
2253
 
2254
  # 5) Register two APIs with explicit signatures
2255
+ gr.api(generate_image, api_name="generate_image", show_api=True, queue=True, concurrency_id="gpu")
2256
+ gr.api(generate_image_stream, api_name="generate_image_stream", show_api=True, queue=True, concurrency_id="gpu")
2257
 
2258
+ gr.LoginButton()
2259
  gr.DuplicateButton(value="Duplicate Space for private use (This demo does not work on CPU. Requires GPU Space)")
2260
 
2261
 
 
2268
  ssr_mode=args.ssr,
2269
  mcp_server=False,
2270
  allowed_paths=[allowed_path],
 
 
2271
  )
2272
  ## END MOD
constants.py CHANGED
@@ -19,7 +19,7 @@ DOWNLOAD_MODEL = "https://huggingface.co/zuv0/test/resolve/main/milkyWonderland_
19
  DOWNLOAD_VAE = "https://huggingface.co/Anzhc/Anzhcs-VAEs/resolve/main/SDXL%20Anime%20VAE%20Dec-only%20B3.safetensors, https://huggingface.co/fp16-guy/anything_kl-f8-anime2_vae-ft-mse-840000-ema-pruned_blessed_clearvae_fp16_cleaned/resolve/main/vae-ft-mse-840000-ema-pruned_fp16.safetensors?download=true"
20
 
21
  # - **Download LoRAs**
22
- DOWNLOAD_LORA = "https://huggingface.co/Leopain/color/resolve/main/Coloring_book_-_LineArt.safetensors, https://civitai.com/api/download/models/135867, https://huggingface.co/Linaqruf/anime-detailer-xl-lora/resolve/main/anime-detailer-xl.safetensors?download=true, https://huggingface.co/Linaqruf/style-enhancer-xl-lora/resolve/main/style-enhancer-xl.safetensors?download=true"
23
 
24
  LOAD_DIFFUSERS_FORMAT_MODEL = [
25
  'TestOrganizationPleaseIgnore/potato_quality_anime_plzwork_sdxl',
 
19
  DOWNLOAD_VAE = "https://huggingface.co/Anzhc/Anzhcs-VAEs/resolve/main/SDXL%20Anime%20VAE%20Dec-only%20B3.safetensors, https://huggingface.co/fp16-guy/anything_kl-f8-anime2_vae-ft-mse-840000-ema-pruned_blessed_clearvae_fp16_cleaned/resolve/main/vae-ft-mse-840000-ema-pruned_fp16.safetensors?download=true"
20
 
21
  # - **Download LoRAs**
22
+ DOWNLOAD_LORA = "https://huggingface.co/Leopain/color/resolve/main/Coloring_book_-_LineArt.safetensors, https://civitai.com/api/download/models/135867, https://huggingface.co/Linaqruf/anime-detailer-xl-lora/resolve/main/anime-detailer-xl.safetensors?download=true, https://huggingface.co/Linaqruf/style-enhancer-xl-lora/resolve/main/style-enhancer-xl.safetensors?download=true, https://huggingface.co/ByteDance/Hyper-SD/resolve/main/Hyper-SD15-8steps-CFG-lora.safetensors?download=true, https://huggingface.co/ByteDance/Hyper-SD/resolve/main/Hyper-SDXL-8steps-CFG-lora.safetensors?download=true"
23
 
24
  LOAD_DIFFUSERS_FORMAT_MODEL = [
25
  'TestOrganizationPleaseIgnore/potato_quality_anime_plzwork_sdxl',
env.py CHANGED
@@ -30,8 +30,6 @@ LOAD_DIFFUSERS_FORMAT_MODEL = [
30
  'BlueDancer/Artisanica_XL',
31
  'neta-art/neta-noob-1.0',
32
  'OnomaAIResearch/Illustrious-xl-early-release-v0',
33
- 'martineux/bismuth7-xl',
34
- 'martineux/perfectdeliberate8',
35
  'Raelina/Rae-Diffusion-XL-V2',
36
  'Raelina/Raemu-XL-V4',
37
  'Raelina/Raemu-XL-V5',
@@ -47,12 +45,6 @@ LOAD_DIFFUSERS_FORMAT_MODEL = [
47
  'Raelina/Raehoshi-illust-XL-7',
48
  'Raelina/Raehoshi-illust-XL-7.1',
49
  'Raelina/Raehoshi-illust-XL-8',
50
- 'Raelina/Raehoshi-illust-XL-8.1',
51
- 'Raelina/Raehoshi-illust-XL-9',
52
- 'Raelina/Raehoshi-illust-XL-9.1',
53
- 'Raelina/Raehoshi-illust-XL-10',
54
- 'Raelina/Raehoshi-illust-XL-11',
55
- 'Raelina/Raehoshi-illust-vpred',
56
  'camenduru/FLUX.1-dev-diffusers',
57
  'black-forest-labs/FLUX.1-schnell',
58
  'sayakpaul/FLUX.1-merged',
 
30
  'BlueDancer/Artisanica_XL',
31
  'neta-art/neta-noob-1.0',
32
  'OnomaAIResearch/Illustrious-xl-early-release-v0',
 
 
33
  'Raelina/Rae-Diffusion-XL-V2',
34
  'Raelina/Raemu-XL-V4',
35
  'Raelina/Raemu-XL-V5',
 
45
  'Raelina/Raehoshi-illust-XL-7',
46
  'Raelina/Raehoshi-illust-XL-7.1',
47
  'Raelina/Raehoshi-illust-XL-8',
 
 
 
 
 
 
48
  'camenduru/FLUX.1-dev-diffusers',
49
  'black-forest-labs/FLUX.1-schnell',
50
  'sayakpaul/FLUX.1-merged',
modutils.py CHANGED
The diff for this file is too large to render. See raw diff
 
packages.txt CHANGED
@@ -1,2 +1 @@
1
- git-lfs
2
- ffmpeg
 
1
+ git-lfs aria2 ffmpeg
 
requirements.txt CHANGED
@@ -1,23 +1,23 @@
1
- stablepy==0.6.5
2
- diffusers
3
- transformers>=4.47.1,<5,!=4.57.0
4
- accelerate
5
- huggingface_hub
6
- spaces
7
- torch==2.8.0
8
- numpy<2
9
- gdown
10
- opencv-python
11
- #dartrs
12
- git+https://github.com/John6666cat/dartrs
13
- translatepy
14
- timm
15
- rapidfuzz
16
- pandas
17
- safetensors
18
- sentencepiece
19
- unidecode
20
- matplotlib-inline
21
- mediapipe==0.10.13
22
- einops
23
- # pydantic==2.10.6
 
1
+ stablepy==0.6.5
2
+ diffusers
3
+ transformers
4
+ accelerate
5
+ huggingface_hub
6
+ hf_transfer
7
+ hf_xet
8
+ torch==2.5.1
9
+ torchvision
10
+ numpy<2
11
+ gdown
12
+ opencv-python
13
+ optimum[onnxruntime]
14
+ #dartrs
15
+ git+https://github.com/John6666cat/dartrs
16
+ translatepy
17
+ timm
18
+ rapidfuzz
19
+ sentencepiece
20
+ unidecode
21
+ matplotlib-inline
22
+ https://github.com/mjun0812/flash-attention-prebuild-wheels/releases/download/v0.4.11/flash_attn-2.8.3+cu124torch2.5-cp310-cp310-linux_x86_64.whl
23
+ pydantic==2.10.6
utils.py CHANGED
@@ -275,11 +275,11 @@ def civ_redirect_down(url, dir_, civitai_api_key, romanize, alternative_name):
275
  elif os.path.exists(os.path.join(dir_, filename_base)):
276
  return os.path.join(dir_, filename_base), filename_base
277
 
278
- wget_command = (
279
- f'wget -c -nv '
280
- f'-O "{os.path.join(dir_, filename_base)}" "{redirect_url}"'
281
  )
282
- r_code = os.system(wget_command) # noqa
283
 
284
  # if r_code != 0:
285
  # raise RuntimeError(f"Failed to download file: {filename_base}. Error code: {r_code}")
@@ -293,32 +293,27 @@ def civ_redirect_down(url, dir_, civitai_api_key, romanize, alternative_name):
293
 
294
  def civ_api_down(url, dir_, civitai_api_key, civ_filename):
295
  """
296
- This method is susceptible to being blocked because it generates a lot of temp redirect links with wget.
297
- If an API key limit is reached, generating a new API key and using it can fix the issue. no
298
  """
299
  output_path = None
300
-
301
  url_dl = url + f"?token={civitai_api_key}"
302
-
303
  if not civ_filename:
304
- wget_command = (
305
- f'wget -c -nv '
306
- f'-P "{dir_}" "{url_dl}"'
307
- )
308
- os.system(wget_command)
309
-
310
  else:
311
  output_path = os.path.join(dir_, civ_filename)
312
-
313
  if not os.path.exists(output_path):
314
- wget_command = (
315
- f'wget -c -nv '
316
- f'-O "{output_path}" "{url_dl}"'
317
  )
318
- os.system(wget_command)
319
-
320
  return output_path
321
 
 
322
  def drive_down(url, dir_):
323
  import gdown
324
 
@@ -359,16 +354,10 @@ def hf_down(url, dir_, hf_token, romanize):
359
  url = url.replace("/blob/", "/resolve/")
360
 
361
  if hf_token:
362
- os.system(
363
- f'wget -c -nv '
364
- f'--header="Authorization: Bearer {hf_token}" '
365
- f'-O "{os.path.join(dir_, filename)}" "{url}"'
366
- )
367
  else:
368
- os.system(
369
- f'wget -c -nv '
370
- f'-O "{os.path.join(dir_, filename)}" "{url}"'
371
- )
372
 
373
  return output_path
374
 
@@ -381,8 +370,7 @@ def download_things(directory, url, hf_token="", civitai_api_key="", romanize=Fa
381
  downloaded_file_path = drive_down(url, directory)
382
  elif "huggingface.co" in url:
383
  downloaded_file_path = hf_down(url, directory, hf_token, romanize)
384
- elif "civitai." in url:
385
- url = url.replace("civitai.red", "civitai.com")
386
  if not civitai_api_key:
387
  msg = "You need an API key to download Civitai models."
388
  print(f"\033[91m{msg}\033[0m")
@@ -405,10 +393,7 @@ def download_things(directory, url, hf_token="", civitai_api_key="", romanize=Fa
405
  gr.Warning(msg)
406
  downloaded_file_path = civ_api_down(url, directory, civitai_api_key, civ_filename)
407
  else:
408
- os.system(
409
- f'wget -c -nv '
410
- f'-P "{directory}" "{url}"'
411
- )
412
 
413
  return downloaded_file_path
414
 
@@ -578,12 +563,7 @@ def create_mask_now(img, invert):
578
 
579
  time.sleep(0.5)
580
 
581
- layers = (img.get("layers") or []) if isinstance(img, dict) else []
582
- if not layers:
583
- background = img.get("background") if isinstance(img, dict) else None
584
- return background, None
585
-
586
- transparent_image = layers[0]
587
 
588
  # Extract the alpha channel
589
  alpha_channel = np.array(transparent_image)[:, :, 3]
 
275
  elif os.path.exists(os.path.join(dir_, filename_base)):
276
  return os.path.join(dir_, filename_base), filename_base
277
 
278
+ aria2_command = (
279
+ f'aria2c --console-log-level=error --summary-interval=10 -c -x 16 '
280
+ f'-k 1M -s 16 -d "{dir_}" -o "{filename_base}" "{redirect_url}"'
281
  )
282
+ r_code = os.system(aria2_command) # noqa
283
 
284
  # if r_code != 0:
285
  # raise RuntimeError(f"Failed to download file: {filename_base}. Error code: {r_code}")
 
293
 
294
  def civ_api_down(url, dir_, civitai_api_key, civ_filename):
295
  """
296
+ This method is susceptible to being blocked because it generates a lot of temp redirect links with aria2c.
297
+ If an API key limit is reached, generating a new API key and using it can fix the issue.
298
  """
299
  output_path = None
300
+
301
  url_dl = url + f"?token={civitai_api_key}"
 
302
  if not civ_filename:
303
+ aria2_command = f'aria2c -c -x 1 -s 1 -d "{dir_}" "{url_dl}"'
304
+ os.system(aria2_command)
 
 
 
 
305
  else:
306
  output_path = os.path.join(dir_, civ_filename)
 
307
  if not os.path.exists(output_path):
308
+ aria2_command = (
309
+ f'aria2c --console-log-level=error --summary-interval=10 -c -x 16 '
310
+ f'-k 1M -s 16 -d "{dir_}" -o "{civ_filename}" "{url_dl}"'
311
  )
312
+ os.system(aria2_command)
313
+
314
  return output_path
315
 
316
+
317
  def drive_down(url, dir_):
318
  import gdown
319
 
 
354
  url = url.replace("/blob/", "/resolve/")
355
 
356
  if hf_token:
357
+ user_header = f'"Authorization: Bearer {hf_token}"'
358
+ os.system(f"aria2c --console-log-level=error --summary-interval=10 --header={user_header} -c -x 16 -k 1M -s 16 {url} -d {dir_} -o {filename}")
 
 
 
359
  else:
360
+ os.system(f"aria2c --optimize-concurrent-downloads --console-log-level=error --summary-interval=10 -c -x 16 -k 1M -s 16 {url} -d {dir_} -o {filename}")
 
 
 
361
 
362
  return output_path
363
 
 
370
  downloaded_file_path = drive_down(url, directory)
371
  elif "huggingface.co" in url:
372
  downloaded_file_path = hf_down(url, directory, hf_token, romanize)
373
+ elif "civitai.com" in url:
 
374
  if not civitai_api_key:
375
  msg = "You need an API key to download Civitai models."
376
  print(f"\033[91m{msg}\033[0m")
 
393
  gr.Warning(msg)
394
  downloaded_file_path = civ_api_down(url, directory, civitai_api_key, civ_filename)
395
  else:
396
+ os.system(f"aria2c --console-log-level=error --summary-interval=10 -c -x 16 -k 1M -s 16 -d {directory} {url}")
 
 
 
397
 
398
  return downloaded_file_path
399
 
 
563
 
564
  time.sleep(0.5)
565
 
566
+ transparent_image = img["layers"][0]
 
 
 
 
 
567
 
568
  # Extract the alpha channel
569
  alpha_channel = np.array(transparent_image)[:, :, 3]