AdamOswald1 commited on
Commit
7fe3857
1 Parent(s): e22d59d

Upload 5 files

Browse files
Files changed (5) hide show
  1. README.md +11 -7
  2. app.py +213 -394
  3. requirements (1).txt +27 -0
  4. requirements (2).txt +27 -0
  5. requirements.txt +19 -0
README.md CHANGED
@@ -1,9 +1,13 @@
1
  ---
 
 
 
 
 
 
 
 
2
  license: mit
3
- inference: true
4
- datasets:
5
- - Gustavosta/Stable-Diffusion-Prompts
6
- - Fazzie/Teyvat
7
- - Guizmus/AnimeChanStyle
8
- - poloclub/diffusiondb
9
- ---
 
1
  ---
2
+ title: Finetuned Diffusion
3
+ emoji: 🪄🖼️
4
+ colorFrom: red
5
+ colorTo: pink
6
+ sdk: gradio
7
+ sdk_version: 3.18.0
8
+ app_file: app.py
9
+ pinned: true
10
  license: mit
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
app.py CHANGED
@@ -1,164 +1,21 @@
 
1
  import gradio as gr
2
- import json
3
- import shutil
4
- import sqlite3
5
- import subprocess
6
- import sys
7
- sys.path.append('src/blip')
8
- sys.path.append('src/clip')
9
- import clip
10
- import hashlib
11
- import math
12
- import numpy as np
13
- import pickle
14
- import torchvision.transforms as T
15
- import torchvision.transforms.functional as TF
16
- import requests
17
- import wget
18
- import gradio as grad, random, re
19
  import torch
20
- import os
21
  import utils
22
- import html
23
- import re
24
- import base64
25
- import subprocess
26
- import argparse
27
- import logging
28
- import streamlit as st
29
- import pandas as pd
30
- import datasets
31
- import yaml
32
- import textwrap
33
- import tornado
34
  import time
35
- import cv2 as cv
36
- from torch import autocast
37
- from diffusers import StableDiffusionPipeline
38
- from transformers import pipeline, set_seed
39
- from huggingface_hub import HfApi
40
- from huggingface_hub import hf_hub_download
41
- from transformers import CLIPTextModel, CLIPTokenizer
42
- from diffusers import AutoencoderKL, UNet2DConditionModel
43
- from diffusers import StableDiffusionImg2ImgPipeline
44
- from PIL import Image
45
- from datasets import load_dataset
46
- from share_btn import community_icon_html, loading_icon_html, share_js
47
- from io import BytesIO
48
- from models.blip import blip_decoder
49
- from torch import nn
50
- from torch.nn import functional as F
51
- from tqdm import tqdm
52
- from pathlib import Path
53
- from flask import Flask, request, jsonify, g
54
- from flask_expects_json import expects_json
55
- from flask_cors import CORS
56
- from huggingface_hub import Repository
57
- from flask_apscheduler import APScheduler
58
- from jsonschema import ValidationError
59
- from os import mkdir
60
- from os.path import isdir
61
- from colorthief import ColorThief
62
- from data_measurements.dataset_statistics import DatasetStatisticsCacheClass as dmt_cls
63
- from utils import dataset_utils
64
- from utils import streamlit_utils as st_utils
65
- from dataclasses import asdict
66
- from .transfer import transfer_color
67
- from .utils import convert_bytes_to_pil
68
- from diffusers import DiffusionPipeline
69
- from huggingface_hub.inference_api import InferenceApi
70
- from huggingface_hub import login
71
- from datasets import load_dataset
72
- #from torch import autocast
73
- #from diffusers import StableDiffusionPipeline
74
- #from io import BytesIO
75
- #import base64
76
- #import torch
77
-
78
- is_colab = utils.is_google_colab()
79
-
80
- from share_btn import community_icon_html, loading_icon_html, share_js
81
-
82
- from huggingface_hub import login
83
- login()
84
-
85
- from huggingface_hub.inference_api import InferenceApi
86
- inference = InferenceApi(repo_id="bert-base-uncased", token=API_TOKEN)
87
-
88
- from datasets import load_dataset
89
-
90
- dataset = load_dataset("Fazzie/Teyvat")
91
-
92
- from datasets import load_dataset
93
-
94
- dataset = load_dataset("Guizmus/AnimeChanStyle")
95
-
96
- from datasets import load_dataset
97
-
98
- dataset = load_dataset("poloclub/diffusiondb")
99
-
100
- from datasets import load_dataset
101
-
102
- dataset = load_dataset("Gustavosta/Stable-Diffusion-Prompts")
103
-
104
- from datasets import load_dataset
105
- dataset = load_dataset("Fazzie/Teyvat")
106
- from datasets import load_dataset
107
- dataset = load_dataset("Guizmus/AnimeChanStyle")
108
- from datasets import load_dataset
109
- dataset = load_dataset("poloclub/diffusiondb")
110
- from datasets import load_dataset
111
- dataset = load_dataset("Gustavosta/Stable-Diffusion-Prompts")
112
-
113
- from datasets import load_dataset
114
- dataset = load_dataset("Fazzie/Teyvat")
115
-
116
- from datasets import load_dataset
117
- dataset = load_dataset("Guizmus/AnimeChanStyle")
118
-
119
- from datasets import load_dataset
120
- dataset = load_dataset("poloclub/diffusiondb")
121
-
122
- from datasets import load_dataset
123
- dataset = load_dataset("Gustavosta/Stable-Diffusion-Prompts")
124
-
125
-
126
- dataset = load_dataset("Fazzie/Teyvat")
127
-
128
-
129
- dataset = load_dataset("Guizmus/AnimeChanStyle")
130
-
131
-
132
- dataset = load_dataset("poloclub/diffusiondb")
133
-
134
-
135
- dataset = load_dataset("Gustavosta/Stable-Diffusion-Prompts")
136
-
137
- dataset = load_dataset("Fazzie/Teyvat")
138
- dataset = load_dataset("Guizmus/AnimeChanStyle")
139
- dataset = load_dataset("poloclub/diffusiondb")
140
- dataset = load_dataset("Gustavosta/Stable-Diffusion-Prompts")
141
-
142
- dataset = load_dataset("Fazzie/Teyvat")
143
 
144
- dataset = load_dataset("Guizmus/AnimeChanStyle")
145
 
146
- dataset = load_dataset("poloclub/diffusiondb")
147
-
148
- dataset = load_dataset("Gustavosta/Stable-Diffusion-Prompts")
149
-
150
- sys.path.append('src/blip')
151
- sys.path.append('src/clip')
152
-
153
- pipeline = DiffusionPipeline.from_pretrained("flax/waifu-diffusion")
154
- pipeline = DiffusionPipeline.from_pretrained("flax/Cyberpunk-Anime-Diffusion")
155
- pipeline = DiffusionPipeline.from_pretrained("technillogue/waifu-diffusion")
156
- pipeline = DiffusionPipeline.from_pretrained("svjack/Stable-Diffusion-Pokemon-en")
157
- pipeline = DiffusionPipeline.from_pretrained("AdamOswald1/Idk")
158
- pipeline = DiffusionPipeline.from_pretrained("katakana/2D-Mix")
159
 
160
  class Model:
161
- def __init__(self, name, path, prefix):
162
  self.name = name
163
  self.path = path
164
  self.prefix = prefix
@@ -166,179 +23,36 @@ class Model:
166
  self.pipe_i2i = None
167
 
168
  models = [
169
- Model("Custom model", "", ""),
170
- Model("Arcane", "nitrosocke/Arcane-Diffusion", "arcane style"),
171
- Model("Archer", "nitrosocke/archer-diffusion", "archer style"),
172
- Model("Elden Ring", "nitrosocke/elden-ring-diffusion", "elden ring style"),
173
- Model("Spider-Verse", "nitrosocke/spider-verse-diffusion", "spiderverse style"),
174
- Model("Modern Disney", "nitrosocke/modern-disney-diffusion", "modern disney style"),
175
- Model("Classic Disney", "nitrosocke/classic-anim-diffusion", "classic disney style"),
176
- Model("Waifu", "hakurei/waifu-diffusion", ""),
177
- Model("Pokémon", "lambdalabs/sd-pokemon-diffusers", "pokemon style"),
178
- Model("Pokémon", "svjack/Stable-Diffusion-Pokemon-en", "pokemon style"),
179
- Model("Pony Diffusion", "AstraliteHeart/pony-diffusion", "pony style"),
180
- Model("Robo Diffusion", "nousr/robo-diffusion", "robo style"),
181
- Model("Cyberpunk Anime", "DGSpitzer/Cyberpunk-Anime-Diffusion, flax/Cyberpunk-Anime-Diffusion", "cyberpunk style"),
182
- Model("Cyberpunk Anime", "DGSpitzer/Cyberpunk-Anime-Diffusion", "cyberpunk style"),
183
- Model("Cyberpunk Anime", "flax/Cyberpunk-Anime-Diffusion", "cyberpunk style"),
184
- Model("Cyberware", "Eppinette/Cyberware", "cyberware"),
185
- Model("Tron Legacy", "dallinmackay/Tron-Legacy-diffusion", "trnlgcy"),
186
- Model("Waifu", "flax/waifu-diffusion", ""),
187
- Model("Dark Souls", "Guizmus/DarkSoulsDiffusion", "dark souls style"),
188
- Model("Waifu", "technillogue/waifu-diffusion", ""),
189
- Model("Ouroborus", "Eppinette/Ouroboros", "m_ouroboros style"),
190
- Model("Ouroborus alt", "Eppinette/Ouroboros", "m_ouroboros"),
191
- Model("Waifu", "Eppinette/Mona", "Mona"),
192
- Model("Waifu", "Eppinette/Mona", "Mona Woman"),
193
- Model("Waifu", "Eppinette/Mona", "Mona Genshin"),
194
- Model("Genshin", "Eppinette/Mona", "Mona"),
195
- Model("Genshin", "Eppinette/Mona", "Mona Woman"),
196
- Model("Genshin", "Eppinette/Mona", "Mona Genshin"),
197
- Model("Space Machine", "rabidgremlin/sd-db-epic-space-machine", "EpicSpaceMachine"),
198
- Model("Spacecraft", "rabidgremlin/sd-db-epic-space-machine", "EpicSpaceMachine"),
199
- Model("TARDIS", "Guizmus/Tardisfusion", "Classic Tardis style"),
200
- Model("TARDIS", "Guizmus/Tardisfusion", "Modern Tardis style"),
201
- Model("TARDIS", "Guizmus/Tardisfusion", "Tardis Box style"),
202
- Model("Spacecraft", "Guizmus/Tardisfusion", "Classic Tardis style"),
203
- Model("Spacecraft", "Guizmus/Tardisfusion", "Modern Tardis style"),
204
- Model("Spacecraft", "Guizmus/Tardisfusion", "Tardis Box style"),
205
- Model("CLIP", "EleutherAI/clip-guided-diffusion", "CLIP"),
206
- Model("Face Swap", "felixrosberg/face-swap", "faceswap"),
207
- Model("Face Swap", "felixrosberg/face-swap", "faceswap with"),
208
- Model("Face Swap", "felixrosberg/face-swap", "faceswapped"),
209
- Model("Face Swap", "felixrosberg/face-swap", "faceswapped with"),
210
- Model("Face Swap", "felixrosberg/face-swap", "face on"),
211
- Model("Waifu", "Fampai/lumine_genshin_impact", "lumine_genshin"),
212
- Model("Waifu", "Fampai/lumine_genshin_impact", "lumine"),
213
- Model("Waifu", "Fampai/lumine_genshin_impact", "Lumine Genshin"),
214
- Model("Waifu", "Fampai/lumine_genshin_impact", "Lumine_genshin"),
215
- Model("Waifu", "Fampai/lumine_genshin_impact", "Lumine_Genshin"),
216
- Model("Waifu", "Fampai/lumine_genshin_impact", "Lumine"),
217
- Model("Genshin", "Fampai/lumine_genshin_impact", "Lumine_genshin"),
218
- Model("Genshin", "Fampai/lumine_genshin_impact", "Lumine_Genshin"),
219
- Model("Genshin", "Fampai/lumine_genshin_impact", "Lumine"),
220
- Model("Genshin", "Fampai/lumine_genshin_impact", "Lumine Genshin"),
221
- Model("Genshin", "Fampai/lumine_genshin_impact", "lumine"),
222
- Model("Genshin", "sd-concepts-library/ganyu-genshin-impact", "Ganyu"),
223
- Model("Genshin", "sd-concepts-library/ganyu-genshin-impact", "Ganyu Woman"),
224
- Model("Genshin", "sd-concepts-library/ganyu-genshin-impact", "Ganyu Genshin"),
225
- Model("Waifu", "sd-concepts-library/ganyu-genshin-impact", "Ganyu"),
226
- Model("Waifu", "sd-concepts-library/ganyu-genshin-impact", "Ganyu Woman"),
227
- Model("Waifu", "sd-concepts-library/ganyu-genshin-impact", "Ganyu Genshin"),
228
- Model("Waifu", "Fampai/raiden_genshin_impact", "raiden_ei"),
229
- Model("Waifu", "Fampai/raiden_genshin_impact", "Raiden Ei"),
230
- Model("Waifu", "Fampai/raiden_genshin_impact", "Ei Genshin"),
231
- Model("Waifu", "Fampai/raiden_genshin_impact", "Raiden Genshin"),
232
- Model("Waifu", "Fampai/raiden_genshin_impact", "Raiden_Genshin"),
233
- Model("Waifu", "Fampai/raiden_genshin_impact", "Ei_Genshin"),
234
- Model("Waifu", "Fampai/raiden_genshin_impact", "Raiden"),
235
- Model("Waifu", "Fampai/raiden_genshin_impact", "Ei"),
236
- Model("Genshin", "Fampai/raiden_genshin_impact", "Raiden Ei"),
237
- Model("Genshin", "Fampai/raiden_genshin_impact", "raiden_ei"),
238
- Model("Genshin", "Fampai/raiden_genshin_impact", "Raiden"),
239
- Model("Genshin", "Fampai/raiden_genshin_impact", "Raiden Genshin"),
240
- Model("Genshin", "Fampai/raiden_genshin_impact", "Ei Genshin"),
241
- Model("Genshin", "Fampai/raiden_genshin_impact", "Raiden_Genshin"),
242
- Model("Genshin", "Fampai/raiden_genshin_impact", "Ei_Genshin"),
243
- Model("Genshin", "Fampai/raiden_genshin_impact", "Ei"),
244
- Model("Waifu", "Fampai/hutao_genshin_impact", "hutao_genshin"),
245
- Model("Waifu", "Fampai/hutao_genshin_impact", "HuTao_Genshin"),
246
- Model("Waifu", "Fampai/hutao_genshin_impact", "HuTao Genshin"),
247
- Model("Waifu", "Fampai/hutao_genshin_impact", "HuTao"),
248
- Model("Waifu", "Fampai/hutao_genshin_impact", "hutao_genshin"),
249
- Model("Genshin", "Fampai/hutao_genshin_impact", "hutao_genshin"),
250
- Model("Genshin", "Fampai/hutao_genshin_impact", "HuTao_Genshin"),
251
- Model("Genshin", "Fampai/hutao_genshin_impact", "HuTao Genshin"),
252
- Model("Genshin", "Fampai/hutao_genshin_impact", "HuTao"),
253
- Model("Genshin", "Fampai/lumine_genshin_impact, Eppinette/Mona, sd-concepts-library/ganyu-genshin-impact, Fampai/raiden_genshin_impact, Fampai/hutao_genshin_impact", "Female"),
254
- Model("Genshin", "Fampai/lumine_genshin_impact, Eppinette/Mona, sd-concepts-library/ganyu-genshin-impact, Fampai/raiden_genshin_impact, Fampai/hutao_genshin_impact", "female"),
255
- Model("Genshin", "Fampai/lumine_genshin_impact, Eppinette/Mona, sd-concepts-library/ganyu-genshin-impact, Fampai/raiden_genshin_impact, Fampai/hutao_genshin_impact", "Woman"),
256
- Model("Genshin", "Fampai/lumine_genshin_impact, Eppinette/Mona, sd-concepts-library/ganyu-genshin-impact, Fampai/raiden_genshin_impact, Fampai/hutao_genshin_impact", "woman"),
257
- Model("Genshin", "Fampai/lumine_genshin_impact, Eppinette/Mona, sd-concepts-library/ganyu-genshin-impact, Fampai/raiden_genshin_impact, Fampai/hutao_genshin_impact", "Girl"),
258
- Model("Genshin", "Fampai/lumine_genshin_impact, Eppinette/Mona, sd-concepts-library/ganyu-genshin-impact, Fampai/raiden_genshin_impact, Fampai/hutao_genshin_impact", "girl"),
259
- Model("Genshin", "Fampai/lumine_genshin_impact", "Female"),
260
- Model("Genshin", "Fampai/lumine_genshin_impact", "female"),
261
- Model("Genshin", "Fampai/lumine_genshin_impact", "Woman"),
262
- Model("Genshin", "Fampai/lumine_genshin_impact", "woman"),
263
- Model("Genshin", "Fampai/lumine_genshin_impact", "Girl"),
264
- Model("Genshin", "Fampai/lumine_genshin_impact", "girl"),
265
- Model("Genshin", "Eppinette/Mona", "Female"),
266
- Model("Genshin", "Eppinette/Mona", "female"),
267
- Model("Genshin", "Eppinette/Mona", "Woman"),
268
- Model("Genshin", "Eppinette/Mona", "woman"),
269
- Model("Genshin", "Eppinette/Mona", "Girl"),
270
- Model("Genshin", "Eppinette/Mona", "girl"),
271
- Model("Genshin", "sd-concepts-library/ganyu-genshin-impact", "Female"),
272
- Model("Genshin", "sd-concepts-library/ganyu-genshin-impact", "female"),
273
- Model("Genshin", "sd-concepts-library/ganyu-genshin-impact", "Woman"),
274
- Model("Genshin", "sd-concepts-library/ganyu-genshin-impact", "woman"),
275
- Model("Genshin", "sd-concepts-library/ganyu-genshin-impact", "Girl"),
276
- Model("Genshin", "sd-concepts-library/ganyu-genshin-impact", "girl"),
277
- Model("Genshin", "Fampai/raiden_genshin_impact", "Female"),
278
- Model("Genshin", "Fampai/raiden_genshin_impact", "female"),
279
- Model("Genshin", "Fampai/raiden_genshin_impact", "Woman"),
280
- Model("Genshin", "Fampai/raiden_genshin_impact", "woman"),
281
- Model("Genshin", "Fampai/raiden_genshin_impact", "Girl"),
282
- Model("Genshin", "Fampai/raiden_genshin_impact", "girl"),
283
- Model("Genshin", "Fampai/hutao_genshin_impact", "Female"),
284
- Model("Genshin", "Fampai/hutao_genshin_impact", "female"),
285
- Model("Genshin", "Fampai/hutao_genshin_impact", "Woman"),
286
- Model("Genshin", "Fampai/hutao_genshin_impact", "woman"),
287
- Model("Genshin", "Fampai/hutao_genshin_impact", "Girl"),
288
- Model("Genshin", "Fampai/hutao_genshin_impact", "girl"),
289
- Model("Waifu", "crumb/genshin-stable-inversion, yuiqena/GenshinImpact, Fampai/lumine_genshin_impact, Eppinette/Mona, sd-concepts-library/ganyu-genshin-impact, Fampai/raiden_genshin_impact, Fampai/hutao_genshin_impact", "Genshin"),
290
- Model("Waifu", "crumb/genshin-stable-inversion, yuiqena/GenshinImpact, Fampai/lumine_genshin_impact, Eppinette/Mona, sd-concepts-library/ganyu-genshin-impact, Fampai/raiden_genshin_impact, Fampai/hutao_genshin_impact", "Genshin Impact"),
291
- Model("Genshin", "crumb/genshin-stable-inversion, yuiqena/GenshinImpact, Fampai/lumine_genshin_impact, Eppinette/Mona, sd-concepts-library/ganyu-genshin-impact, Fampai/raiden_genshin_impact, Fampai/hutao_genshin_impact", ""),
292
- Model("Waifu", "crumb/genshin-stable-inversion", "Genshin"),
293
- Model("Waifu", "crumb/genshin-stable-inversion", "Genshin Impact"),
294
- Model("Genshin", "crumb/genshin-stable-inversion", ""),
295
- Model("Waifu", "yuiqena/GenshinImpact", "Genshin"),
296
- Model("Waifu", "yuiqena/GenshinImpact", "Genshin Impact"),
297
- Model("Genshin", "yuiqena/GenshinImpact", ""),
298
- Model("Waifu", "hakurei/waifu-diffusion, flax/waifu-diffusion, technillogue/waifu-diffusion, Guizmus/AnimeChanStyle, katakana/2D-Mix", ""),
299
- Model("Pokémon", "lambdalabs/sd-pokemon-diffusers, svjack/Stable-Diffusion-Pokemon-en", "pokemon style"),
300
- Model("Pokémon", "lambdalabs/sd-pokemon-diffusers, svjack/Stable-Diffusion-Pokemon-en", ""),
301
- Model("Test", "AdamoOswald1/Idk", ""),
302
- Model("Anime", "Guizmus/AnimeChanStyle", "AnimeChan Style"),
303
- Model("Genshin", "Guizmus/AnimeChanStyle", "AnimeChan Style"),
304
- Model("Waifu", "Guizmus/AnimeChanStyle", "AnimeChan Style"),
305
- Model("Waifu", "Guizmus/AnimeChanStyle", "Genshin"),
306
- Model("Waifu", "Guizmus/AnimeChanStyle", "Genshin Impact"),
307
- Model("Genshin", "Guizmus/AnimeChanStyle", ""),
308
- Model("Anime", "Guizmus/AnimeChanStyle", ""),
309
- Model("Waifu", "Guizmus/AnimeChanStyle", ""),
310
- Model("Anime", "Guizmus/AnimeChanStyle, katakana/2D-Mix", ""),
311
- Model("Anime", "katakana/2D-Mix", "2D-Mix"),
312
- Model("Genshin", "katakana/2D-Mix", "2D-Mix"),
313
- Model("Waifu", "katakana/2D-Mix", "2D-Mix"),
314
- Model("Waifu", "katakana/2D-Mix", "Genshin"),
315
- Model("Waifu", "katakana/2D-Mix", "Genshin Impact"),
316
- Model("Genshin", "katakana/2D-Mix", ""),
317
- Model("Anime", "katakana/2D-Mix", ""),
318
- Model("Waifu", "katakana/2D-Mix", ""),
319
- Model("Beeple", "riccardogiorato/beeple-diffusion", "beeple style "),
320
- Model("Avatar", "riccardogiorato/avatar-diffusion", "avatartwow style "),
321
- Model("Poolsuite", "prompthero/poolsuite", "poolsuite style ")
322
  ]
323
- # Model("Beksinski", "s3nh/beksinski-style-stable-diffusion", "beksinski style "),
324
- # Model("Guohua", "Langboat/Guohua-Diffusion", "guohua style ")
325
-
326
- scheduler = DPMSolverMultistepScheduler(
327
- beta_start=0.00085,
328
- beta_end=0.012,
329
- beta_schedule="scaled_linear",
330
- num_train_timesteps=1000,
331
- trained_betas=None,
332
- predict_epsilon=True,
333
- thresholding=False,
334
- algorithm_type="dpmsolver++",
335
- solver_type="midpoint",
336
- lower_order_final=True,
337
- )
338
 
339
  custom_model = None
340
  if is_colab:
341
- models.insert(0, Model("Custom model", "", ""))
342
  custom_model = models[0]
343
 
344
  last_mode = "txt2img"
@@ -346,41 +60,61 @@ current_model = models[1] if is_colab else models[0]
346
  current_model_path = current_model.path
347
 
348
  if is_colab:
349
- pipe = StableDiffusionPipeline.from_pretrained(current_model.path, torch_dtype=torch.float16, scheduler=scheduler)
350
- pipe = StableDiffusionPipeline.from_pretrained("hakurei/waifu-diffusion", torch_type=torch.float16, revision="fp16")
351
- pipe = StableDiffusionPipeline.from_pretrained(current_model, torch_dtype=torchfloat, revision="fp16")
352
- gpt2_pipe = pipeline('text-generation', model='Gustavosta/MagicPrompt-Stable-Diffusion', tokenizer='gpt2')
353
- pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=True, revision="fp16", torch_dtype=torch.float16).to("cuda")
354
- pipe = StableDiffusionPipeline.from_pretrained(current_model.path, torch_dtype=torch.float16)
355
- pipeline = DiffusionPipeline.from_pretrained("flax/waifu-diffusion")
356
- pipeline = DiffusionPipeline.from_pretrained("flax/Cyberpunk-Anime-Diffusion")
357
- pipeline = DiffusionPipeline.from_pretrained("technillogue/waifu-diffusion")
358
- pipeline = DiffusionPipeline.from_pretrained("svjack/Stable-Diffusion-Pokemon-en")
359
- pipeline = DiffusionPipeline.from_pretrained("AdamOswald1/Idk")
360
- pipeline = DiffusionPipeline.from_pretrained("katakana/2D-Mix")
361
-
362
- else: # download all models
363
- vae = AutoencoderKL.from_pretrained(current_model.path, subfolder="vae", torch_dtype=torch.float16)
364
- for model in models:
365
- try:
366
- unet = UNet2DConditionModel.from_pretrained(model.path, subfolder="unet", torch_dtype=torch.float16)
367
- model.pipe_t2i = StableDiffusionPipeline.from_pretrained(model.path, unet=unet, vae=vae, torch_dtype=torch.float16, scheduler=scheduler)
368
- model.pipe_i2i = StableDiffusionImg2ImgPipeline.from_pretrained(model.path, unet=unet, vae=vae, torch_dtype=torch.float16, scheduler=scheduler)
369
- except:
370
- models.remove(model)
371
- pipe = models[0].pipe_t2i
372
-
373
  if torch.cuda.is_available():
374
  pipe = pipe.to("cuda")
 
375
 
376
  device = "GPU 🔥" if torch.cuda.is_available() else "CPU 🥶"
377
 
 
 
 
 
 
 
 
 
 
 
 
 
378
  def custom_model_changed(path):
379
  models[0].path = path
380
  global current_model
381
  current_model = models[0]
382
 
383
- def inference(model_name, prompt, guidance, steps, width=512, height=512, seed=0, img=None, strength=0.5, neg_prompt=""):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
384
 
385
  global current_model
386
  for model in models:
@@ -388,14 +122,23 @@ def inference(model_name, prompt, guidance, steps, width=512, height=512, seed=0
388
  current_model = model
389
  model_path = current_model.path
390
 
391
- generator = torch.Generator('cuda').manual_seed(seed) if seed != 0 else None
 
 
 
 
392
 
393
- if img is not None:
394
- return img_to_img(model_path, prompt, neg_prompt, img, strength, guidance, steps, width, height, generator)
395
- else:
396
- return txt_to_img(model_path, prompt, neg_prompt, guidance, steps, width, height, generator)
 
 
 
397
 
398
- def txt_to_img(model_path, prompt, neg_prompt, guidance, steps, width, height, generator=None):
 
 
399
 
400
  global last_mode
401
  global pipe
@@ -403,29 +146,48 @@ def txt_to_img(model_path, prompt, neg_prompt, guidance, steps, width, height, g
403
  if model_path != current_model_path or last_mode != "txt2img":
404
  current_model_path = model_path
405
 
 
 
406
  if is_colab or current_model == custom_model:
407
- pipe = StableDiffusionPipeline.from_pretrained(current_model_path, torch_dtype=torch.float16, scheduler=scheduler)
 
 
 
 
 
408
  else:
409
- pipe.to("cpu")
410
- pipe = current_model.pipe_t2i
 
 
 
 
 
411
 
412
  if torch.cuda.is_available():
413
  pipe = pipe.to("cuda")
 
414
  last_mode = "txt2img"
415
 
416
  prompt = current_model.prefix + prompt
417
  result = pipe(
418
  prompt,
419
  negative_prompt = neg_prompt,
420
- # num_images_per_prompt=n_images,
421
  num_inference_steps = int(steps),
422
  guidance_scale = guidance,
423
  width = width,
424
  height = height,
425
- generator = generator)
426
-
427
 
428
- def img_to_img(model_path, prompt, neg_prompt, img, strength, guidance, steps, width, height, generator=None):
 
 
 
 
 
 
429
 
430
  global last_mode
431
  global pipe
@@ -433,14 +195,27 @@ def img_to_img(model_path, prompt, neg_prompt, img, strength, guidance, steps, w
433
  if model_path != current_model_path or last_mode != "img2img":
434
  current_model_path = model_path
435
 
 
 
436
  if is_colab or current_model == custom_model:
437
- pipe = StableDiffusionImg2ImgPipeline.from_pretrained(current_model_path, torch_dtype=torch.float16, scheduler=scheduler)
 
 
 
 
 
438
  else:
439
- pipe.to("cpu")
440
- pipe = current_model.pipe_i2i
 
 
 
 
 
441
 
442
  if torch.cuda.is_available():
443
  pipe = pipe.to("cuda")
 
444
  last_mode = "img2img"
445
 
446
  prompt = current_model.prefix + prompt
@@ -449,32 +224,48 @@ def img_to_img(model_path, prompt, neg_prompt, img, strength, guidance, steps, w
449
  result = pipe(
450
  prompt,
451
  negative_prompt = neg_prompt,
452
- # num_images_per_prompt=n_images,
453
- init_image = img,
454
  num_inference_steps = int(steps),
455
  strength = strength,
456
  guidance_scale = guidance,
457
- width = width,
458
- height = height,
459
- generator = generator)
 
 
 
460
 
461
- css = """.finetuned-diffusion-div div{display:inline-flex;align-items:center;gap:.8rem;font-size:1.75rem}.finetuned-diffusion-div div h1{font-weight:900;margin-bottom:7px}.finetuned-diffusion-div p{margin-bottom:10px;font-size:94%}a{text-decoration:underline}.tabs{margin-top:0;margin-bottom:0}#gallery{min-height:20rem}
462
- """
463
- with gr.Blocks(css=css) as demo:
 
 
 
 
 
 
 
 
 
 
 
 
464
  gr.HTML(
465
  f"""
466
  <div class="finetuned-diffusion-div">
467
  <div>
468
- <h1>Playground Diffusion</h1>
469
  </div>
470
  <p>
471
  Demo for multiple fine-tuned Stable Diffusion models, trained on different styles: <br>
472
- <a href="https://huggingface.co/riccardogiorato/avatar-diffusion">Avatar</a>,<br/>
473
- <a href="https://huggingface.co/riccardogiorato/beeple-diffusion">Beeple</a>,<br/>
474
- <a href="https://huggingface.co/s3nh/beksinski-style-stable-diffusion">Beksinski</a>,<br/>
475
- Diffusers 🧨 SD model hosted on HuggingFace 🤗.
476
  Running on <b>{device}</b>{(" in a <b>Google Colab</b>." if is_colab else "")}
477
  </p>
 
 
478
  </div>
479
  """
480
  )
@@ -492,25 +283,26 @@ with gr.Blocks(css=css) as demo:
492
  generate = gr.Button(value="Generate").style(rounded=(False, True, True, False))
493
 
494
 
495
- image_out = gr.Image(height=512)
496
- # gallery = gr.Gallery(
497
- # label="Generated images", show_label=False, elem_id="gallery"
498
- # ).style(grid=[1], height="auto")
 
499
 
500
  with gr.Column(scale=45):
501
  with gr.Tab("Options"):
502
  with gr.Group():
503
  neg_prompt = gr.Textbox(label="Negative prompt", placeholder="What to exclude from the image")
504
 
505
- # n_images = gr.Slider(label="Images", value=1, minimum=1, maximum=4, step=1)
506
 
507
  with gr.Row():
508
  guidance = gr.Slider(label="Guidance scale", value=7.5, maximum=15)
509
- steps = gr.Slider(label="Steps", value=25, minimum=2, maximum=75, step=1)
510
 
511
  with gr.Row():
512
- width = gr.Slider(label="Width", value=512, minimum=64, maximum=1024, step=8)
513
- height = gr.Slider(label="Height", value=512, minimum=64, maximum=1024, step=8)
514
 
515
  seed = gr.Slider(0, 2147483647, label='Seed (0 = random)', value=0, step=1)
516
 
@@ -520,14 +312,41 @@ with gr.Blocks(css=css) as demo:
520
  strength = gr.Slider(label="Transformation strength", minimum=0, maximum=1, step=0.01, value=0.5)
521
 
522
  if is_colab:
523
- model_name.change(lambda x: gr.update(visible = x == models[0].name), inputs=model_name, outputs=custom_model_group)
524
- custom_model_path.change(custom_model_changed, inputs=custom_model_path, outputs=None)
525
  # n_images.change(lambda n: gr.Gallery().style(grid=[2 if n > 1 else 1], height="auto"), inputs=n_images, outputs=gallery)
526
-
527
- inputs = [model_name, prompt, guidance, steps, width, height, seed, image, strength, neg_prompt]
528
- prompt.submit(inference, inputs=inputs, outputs=image_out)
529
- generate.click(inference, inputs=inputs, outputs=image_out)
530
-
531
- if not is_colab:
532
- demo.queue(concurrency_count=1)
533
- demo.launch(debug=is_colab, share=is_colab)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffusers import AutoencoderKL, UNet2DConditionModel, StableDiffusionPipeline, StableDiffusionImg2ImgPipeline, DPMSolverMultistepScheduler
2
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  import torch
4
+ from PIL import Image
5
  import utils
6
+ import datetime
 
 
 
 
 
 
 
 
 
 
 
7
  import time
8
+ import psutil
9
+ import random
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
 
11
 
12
+ start_time = time.time()
13
+ is_colab = utils.is_google_colab()
14
+ state = None
15
+ current_steps = 25
 
 
 
 
 
 
 
 
 
16
 
17
  class Model:
18
+ def __init__(self, name, path="", prefix=""):
19
  self.name = name
20
  self.path = path
21
  self.prefix = prefix
 
23
  self.pipe_i2i = None
24
 
25
  models = [
26
+ Model("Arcane", "nitrosocke/Arcane-Diffusion", "arcane style "),
27
+ Model("Dreamlike Diffusion 1.0", "dreamlike-art/dreamlike-diffusion-1.0", "dreamlikeart "),
28
+ Model("Archer", "nitrosocke/archer-diffusion", "archer style "),
29
+ Model("Anything V3", "Linaqruf/anything-v3.0", ""),
30
+ Model("Modern Disney", "nitrosocke/mo-di-diffusion", "modern disney style "),
31
+ Model("Classic Disney", "nitrosocke/classic-anim-diffusion", "classic disney style "),
32
+ Model("Loving Vincent (Van Gogh)", "dallinmackay/Van-Gogh-diffusion", "lvngvncnt "),
33
+ Model("Wavyfusion", "wavymulder/wavyfusion", "wa-vy style "),
34
+ Model("Analog Diffusion", "wavymulder/Analog-Diffusion", "analog style "),
35
+ Model("Redshift renderer (Cinema4D)", "nitrosocke/redshift-diffusion", "redshift style "),
36
+ Model("Midjourney v4 style", "prompthero/midjourney-v4-diffusion", "mdjrny-v4 style "),
37
+ Model("Waifu", "hakurei/waifu-diffusion"),
38
+ Model("Cyberpunk Anime", "DGSpitzer/Cyberpunk-Anime-Diffusion", "dgs illustration style "),
39
+ Model("Elden Ring", "nitrosocke/elden-ring-diffusion", "elden ring style "),
40
+ Model("TrinArt v2", "naclbit/trinart_stable_diffusion_v2"),
41
+ Model("Spider-Verse", "nitrosocke/spider-verse-diffusion", "spiderverse style "),
42
+ Model("Balloon Art", "Fictiverse/Stable_Diffusion_BalloonArt_Model", "BalloonArt "),
43
+ Model("Tron Legacy", "dallinmackay/Tron-Legacy-diffusion", "trnlgcy "),
44
+ Model("Pokémon", "lambdalabs/sd-pokemon-diffusers"),
45
+ Model("Pony Diffusion", "AstraliteHeart/pony-diffusion"),
46
+ Model("Robo Diffusion", "nousr/robo-diffusion"),
47
+ Model("Epic Diffusion", "johnslegers/epic-diffusion"),
48
+ Model("Modern Era TARDIS Interior", "Guizmus/Tardisfusion", "Modern Tardis style"),
49
+ Model("Classic Era TARDIS Interior", "Guizmus/Tardisfusion", "Classic Tardis style"),
50
+ Model("Cyber-Genshin", "AdamOswald1/Cyberpunk-Anime-Diffusion_with_support_for_Gen-Imp_characters", "Teyvat, Teyvat Style, cyberware_style, m_cyberware, Cyberware, Cyberware style, m_cyberware style, cyberware style, dgs illustration style, genshin impact style, ")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
  custom_model = None
54
  if is_colab:
55
+ models.insert(0, Model("Custom model"))
56
  custom_model = models[0]
57
 
58
  last_mode = "txt2img"
 
60
  current_model_path = current_model.path
61
 
62
  if is_colab:
63
+ pipe = StableDiffusionPipeline.from_pretrained(
64
+ current_model.path,
65
+ torch_dtype=torch.float16,
66
+ scheduler=DPMSolverMultistepScheduler.from_pretrained(current_model.path, subfolder="scheduler"),
67
+ safety_checker=lambda images, clip_input: (images, False)
68
+ )
69
+
70
+ else:
71
+ pipe = StableDiffusionPipeline.from_pretrained(
72
+ current_model.path,
73
+ torch_dtype=torch.float16,
74
+ scheduler=DPMSolverMultistepScheduler.from_pretrained(current_model.path, subfolder="scheduler")
75
+ )
76
+
 
 
 
 
 
 
 
 
 
 
77
  if torch.cuda.is_available():
78
  pipe = pipe.to("cuda")
79
+ pipe.enable_xformers_memory_efficient_attention()
80
 
81
  device = "GPU 🔥" if torch.cuda.is_available() else "CPU 🥶"
82
 
83
+ def error_str(error, title="Error"):
84
+ return f"""#### {title}
85
+ {error}""" if error else ""
86
+
87
+ def update_state(new_state):
88
+ global state
89
+ state = new_state
90
+
91
+ def update_state_info(old_state):
92
+ if state and state != old_state:
93
+ return gr.update(value=state)
94
+
95
  def custom_model_changed(path):
96
  models[0].path = path
97
  global current_model
98
  current_model = models[0]
99
 
100
+ def on_model_change(model_name):
101
+
102
+ prefix = "Enter prompt. \"" + next((m.prefix for m in models if m.name == model_name), None) + "\" is prefixed automatically" if model_name != models[0].name else "Don't forget to use the custom model prefix in the prompt!"
103
+
104
+ return gr.update(visible = model_name == models[0].name), gr.update(placeholder=prefix)
105
+
106
+ def on_steps_change(steps):
107
+ global current_steps
108
+ current_steps = steps
109
+
110
+ def pipe_callback(step: int, timestep: int, latents: torch.FloatTensor):
111
+ update_state(f"{step}/{current_steps} steps")#\nTime left, sec: {timestep/100:.0f}")
112
+
113
+ def inference(model_name, prompt, guidance, steps, n_images=1, width=512, height=512, seed=0, img=None, strength=0.5, neg_prompt=""):
114
+
115
+ update_state(" ")
116
+
117
+ print(psutil.virtual_memory()) # print memory usage
118
 
119
  global current_model
120
  for model in models:
 
122
  current_model = model
123
  model_path = current_model.path
124
 
125
+ # generator = torch.Generator('cuda').manual_seed(seed) if seed != 0 else None
126
+ if seed == 0:
127
+ seed = random.randint(0, 2147483647)
128
+
129
+ generator = torch.Generator('cuda').manual_seed(seed)
130
 
131
+ try:
132
+ if img is not None:
133
+ return img_to_img(model_path, prompt, n_images, neg_prompt, img, strength, guidance, steps, width, height, generator, seed), f"Done. Seed: {seed}"
134
+ else:
135
+ return txt_to_img(model_path, prompt, n_images, neg_prompt, guidance, steps, width, height, generator, seed), f"Done. Seed: {seed}"
136
+ except Exception as e:
137
+ return None, error_str(e)
138
 
139
+ def txt_to_img(model_path, prompt, n_images, neg_prompt, guidance, steps, width, height, generator, seed):
140
+
141
+ print(f"{datetime.datetime.now()} txt_to_img, model: {current_model.name}")
142
 
143
  global last_mode
144
  global pipe
 
146
  if model_path != current_model_path or last_mode != "txt2img":
147
  current_model_path = model_path
148
 
149
+ update_state(f"Loading {current_model.name} text-to-image model...")
150
+
151
  if is_colab or current_model == custom_model:
152
+ pipe = StableDiffusionPipeline.from_pretrained(
153
+ current_model_path,
154
+ torch_dtype=torch.float16,
155
+ scheduler=DPMSolverMultistepScheduler.from_pretrained(current_model.path, subfolder="scheduler"),
156
+ safety_checker=lambda images, clip_input: (images, False)
157
+ )
158
  else:
159
+ pipe = StableDiffusionPipeline.from_pretrained(
160
+ current_model_path,
161
+ torch_dtype=torch.float16,
162
+ scheduler=DPMSolverMultistepScheduler.from_pretrained(current_model.path, subfolder="scheduler")
163
+ )
164
+ # pipe = pipe.to("cpu")
165
+ # pipe = current_model.pipe_t2i
166
 
167
  if torch.cuda.is_available():
168
  pipe = pipe.to("cuda")
169
+ pipe.enable_xformers_memory_efficient_attention()
170
  last_mode = "txt2img"
171
 
172
  prompt = current_model.prefix + prompt
173
  result = pipe(
174
  prompt,
175
  negative_prompt = neg_prompt,
176
+ num_images_per_prompt=n_images,
177
  num_inference_steps = int(steps),
178
  guidance_scale = guidance,
179
  width = width,
180
  height = height,
181
+ generator = generator,
182
+ callback=pipe_callback)
183
 
184
+ # update_state(f"Done. Seed: {seed}")
185
+
186
+ return replace_nsfw_images(result)
187
+
188
+ def img_to_img(model_path, prompt, n_images, neg_prompt, img, strength, guidance, steps, width, height, generator, seed):
189
+
190
+ print(f"{datetime.datetime.now()} img_to_img, model: {model_path}")
191
 
192
  global last_mode
193
  global pipe
 
195
  if model_path != current_model_path or last_mode != "img2img":
196
  current_model_path = model_path
197
 
198
+ update_state(f"Loading {current_model.name} image-to-image model...")
199
+
200
  if is_colab or current_model == custom_model:
201
+ pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
202
+ current_model_path,
203
+ torch_dtype=torch.float16,
204
+ scheduler=DPMSolverMultistepScheduler.from_pretrained(current_model.path, subfolder="scheduler"),
205
+ safety_checker=lambda images, clip_input: (images, False)
206
+ )
207
  else:
208
+ pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
209
+ current_model_path,
210
+ torch_dtype=torch.float16,
211
+ scheduler=DPMSolverMultistepScheduler.from_pretrained(current_model.path, subfolder="scheduler")
212
+ )
213
+ # pipe = pipe.to("cpu")
214
+ # pipe = current_model.pipe_i2i
215
 
216
  if torch.cuda.is_available():
217
  pipe = pipe.to("cuda")
218
+ pipe.enable_xformers_memory_efficient_attention()
219
  last_mode = "img2img"
220
 
221
  prompt = current_model.prefix + prompt
 
224
  result = pipe(
225
  prompt,
226
  negative_prompt = neg_prompt,
227
+ num_images_per_prompt=n_images,
228
+ image = img,
229
  num_inference_steps = int(steps),
230
  strength = strength,
231
  guidance_scale = guidance,
232
+ # width = width,
233
+ # height = height,
234
+ generator = generator,
235
+ callback=pipe_callback)
236
+
237
+ # update_state(f"Done. Seed: {seed}")
238
 
239
+ return replace_nsfw_images(result)
240
+
241
+ def replace_nsfw_images(results):
242
+
243
+ if is_colab:
244
+ return results.images
245
+
246
+ for i in range(len(results.images)):
247
+ if results.nsfw_content_detected[i]:
248
+ results.images[i] = Image.open("nsfw.png")
249
+ return results.images
250
+
251
+ # css = """.finetuned-diffusion-div div{display:inline-flex;align-items:center;gap:.8rem;font-size:1.75rem}.finetuned-diffusion-div div h1{font-weight:900;margin-bottom:7px}.finetuned-diffusion-div p{margin-bottom:10px;font-size:94%}a{text-decoration:underline}.tabs{margin-top:0;margin-bottom:0}#gallery{min-height:20rem}
252
+ # """
253
+ with gr.Blocks(css="style.css") as demo:
254
  gr.HTML(
255
  f"""
256
  <div class="finetuned-diffusion-div">
257
  <div>
258
+ <h1>Finetuned Diffusion</h1>
259
  </div>
260
  <p>
261
  Demo for multiple fine-tuned Stable Diffusion models, trained on different styles: <br>
262
+ <a href="https://huggingface.co/nitrosocke/Arcane-Diffusion">Arcane</a>, <a href="https://huggingface.co/nitrosocke/archer-diffusion">Archer</a>, <a href="https://huggingface.co/nitrosocke/elden-ring-diffusion">Elden Ring</a>, <a href="https://huggingface.co/nitrosocke/spider-verse-diffusion">Spider-Verse</a>, <a href="https://huggingface.co/nitrosocke/mo-di-diffusion">Modern Disney</a>, <a href="https://huggingface.co/nitrosocke/classic-anim-diffusion">Classic Disney</a>, <a href="https://huggingface.co/dallinmackay/Van-Gogh-diffusion">Loving Vincent (Van Gogh)</a>, <a href="https://huggingface.co/nitrosocke/redshift-diffusion">Redshift renderer (Cinema4D)</a>, <a href="https://huggingface.co/prompthero/midjourney-v4-diffusion">Midjourney v4 style</a>, <a href="https://huggingface.co/hakurei/waifu-diffusion">Waifu</a>, <a href="https://huggingface.co/lambdalabs/sd-pokemon-diffusers">Pokémon</a>, <a href="https://huggingface.co/AstraliteHeart/pony-diffusion">Pony Diffusion</a>, <a href="https://huggingface.co/nousr/robo-diffusion">Robo Diffusion</a>, <a href="https://huggingface.co/DGSpitzer/Cyberpunk-Anime-Diffusion">Cyberpunk Anime</a>, <a href="https://huggingface.co/dallinmackay/Tron-Legacy-diffusion">Tron Legacy</a>, <a href="https://huggingface.co/Fictiverse/Stable_Diffusion_BalloonArt_Model">Balloon Art</a> + in colab notebook you can load any other Diffusers 🧨 SD model hosted on HuggingFace 🤗.
263
+ </p>
264
+ <p>You can skip the queue and load custom models in the colab: <a href="https://colab.research.google.com/gist/qunash/42112fb104509c24fd3aa6d1c11dd6e0/copy-of-fine-tuned-diffusion-gradio.ipynb"><img data-canonical-src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab" src="https://camo.githubusercontent.com/84f0493939e0c4de4e6dbe113251b4bfb5353e57134ffd9fcab6b8714514d4d1/68747470733a2f2f636f6c61622e72657365617263682e676f6f676c652e636f6d2f6173736574732f636f6c61622d62616467652e737667"></a></p>
 
265
  Running on <b>{device}</b>{(" in a <b>Google Colab</b>." if is_colab else "")}
266
  </p>
267
+ <p>You can also duplicate this space and upgrade to gpu by going to settings:<br>
268
+ <a style="display:inline-block" href="https://huggingface.co/spaces/anzorq/finetuned_diffusion?duplicate=true"><img src="https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14" alt="Duplicate Space"></a></p>
269
  </div>
270
  """
271
  )
 
283
  generate = gr.Button(value="Generate").style(rounded=(False, True, True, False))
284
 
285
 
286
+ # image_out = gr.Image(height=512)
287
+ gallery = gr.Gallery(label="Generated images", show_label=False, elem_id="gallery").style(grid=[2], height="auto")
288
+
289
+ state_info = gr.Textbox(label="State", show_label=False, max_lines=2).style(container=False)
290
+ error_output = gr.Markdown()
291
 
292
  with gr.Column(scale=45):
293
  with gr.Tab("Options"):
294
  with gr.Group():
295
  neg_prompt = gr.Textbox(label="Negative prompt", placeholder="What to exclude from the image")
296
 
297
+ n_images = gr.Slider(label="Images", value=1, minimum=1, maximum=16, step=1)
298
 
299
  with gr.Row():
300
  guidance = gr.Slider(label="Guidance scale", value=7.5, maximum=15)
301
+ steps = gr.Slider(label="Steps", value=current_steps, minimum=2, maximum=100, step=1)
302
 
303
  with gr.Row():
304
+ width = gr.Slider(label="Width", value=512, minimum=64, maximum=2048, step=8)
305
+ height = gr.Slider(label="Height", value=512, minimum=64, maximum=2048, step=8)
306
 
307
  seed = gr.Slider(0, 2147483647, label='Seed (0 = random)', value=0, step=1)
308
 
 
312
  strength = gr.Slider(label="Transformation strength", minimum=0, maximum=1, step=0.01, value=0.5)
313
 
314
  if is_colab:
315
+ model_name.change(on_model_change, inputs=model_name, outputs=[custom_model_group, prompt], queue=False)
316
+ custom_model_path.change(custom_model_changed, inputs=custom_model_path, outputs=None)
317
  # n_images.change(lambda n: gr.Gallery().style(grid=[2 if n > 1 else 1], height="auto"), inputs=n_images, outputs=gallery)
318
+ steps.change(on_steps_change, inputs=[steps], outputs=[], queue=False)
319
+
320
+ inputs = [model_name, prompt, guidance, steps, n_images, width, height, seed, image, strength, neg_prompt]
321
+ outputs = [gallery, error_output]
322
+ prompt.submit(inference, inputs=inputs, outputs=outputs)
323
+ generate.click(inference, inputs=inputs, outputs=outputs)
324
+
325
+ ex = gr.Examples([
326
+ [models[7].name, "tiny cute and adorable kitten adventurer dressed in a warm overcoat with survival gear on a winters day", 7.5, 25],
327
+ [models[4].name, "portrait of dwayne johnson", 7.0, 35],
328
+ [models[5].name, "portrait of a beautiful alyx vance half life", 10, 25],
329
+ [models[6].name, "Aloy from Horizon: Zero Dawn, half body portrait, smooth, detailed armor, beautiful face, illustration", 7.0, 30],
330
+ [models[5].name, "fantasy portrait painting, digital art", 4.0, 20],
331
+ ], inputs=[model_name, prompt, guidance, steps], outputs=outputs, fn=inference, cache_examples=False)
332
+
333
+ gr.HTML("""
334
+ <div style="border-top: 1px solid #303030;">
335
+ <br>
336
+ <p>Models by <a href="https://huggingface.co/nitrosocke">@nitrosocke</a>, <a href="https://twitter.com/haruu1367">@haruu1367</a>, <a href="https://twitter.com/DGSpitzer">@Helixngc7293</a>, <a href="https://twitter.com/dal_mack">@dal_mack</a>, <a href="https://twitter.com/prompthero">@prompthero</a> and others. ❤️</p>
337
+ <p>This space uses the <a href="https://github.com/LuChengTHU/dpm-solver">DPM-Solver++</a> sampler by <a href="https://arxiv.org/abs/2206.00927">Cheng Lu, et al.</a>.</p>
338
+ <p>Space by:<br>
339
+ <a href="https://twitter.com/hahahahohohe"><img src="https://img.shields.io/twitter/follow/hahahahohohe?label=%40anzorq&style=social" alt="Twitter Follow"></a><br>
340
+ <a href="https://github.com/qunash"><img alt="GitHub followers" src="https://img.shields.io/github/followers/qunash?style=social" alt="Github Follow"></a></p><br><br>
341
+ <a href="https://www.buymeacoffee.com/anzorq" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 45px !important;width: 162px !important;" ></a><br><br>
342
+ <p><img src="https://visitor-badge.glitch.me/badge?page_id=anzorq.finetuned_diffusion" alt="visitors"></p>
343
+ </div>
344
+ """)
345
+
346
+ demo.load(update_state_info, inputs=state_info, outputs=state_info, every=0.5, show_progress=False)
347
+
348
+ print(f"Space built in {time.time() - start_time:.2f} seconds")
349
+
350
+ # if not is_colab:
351
+ demo.queue(concurrency_count=1)
352
+ demo.launch(debug=is_colab, share=is_colab)
requirements (1).txt ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --extra-index-url https://download.pytorch.org/whl/cu113
2
+ numpy
3
+ torch
4
+ torchvision
5
+ diffusers
6
+ #diffusers
7
+ #git+https://github.com/huggingface/diffusers.git
8
+ #git+https://github.com/huggingface/diffusers
9
+ git+https://github.com/huggingface/diffusers.git
10
+ git+https://github.com/huggingface/diffusers
11
+ transformers
12
+ #transformers
13
+ #git+https://github.com/huggingface/transformers
14
+ git+https://github.com/huggingface/transformers
15
+ scipy
16
+ ftfy
17
+ psutil
18
+ accelerate
19
+ OmegaConf
20
+ pytorch_lightning
21
+ #OmegaConf
22
+ #pytorch_lightning
23
+ triton
24
+ xformers
25
+ #xformers
26
+ #https://github.com/apolinario/xformers/releases/download/0.0.3/xformers-0.0.14.dev0-cp38-cp38-linux_x86_64.whl
27
+ https://github.com/camenduru/stable-diffusion-webui-colab/releases/download/0.0.16/xformers-0.0.16+bc08bbc.d20230123-cp38-cp38-linux_x86_64.whl
requirements (2).txt ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --extra-index-url https://download.pytorch.org/whl/cu113
2
+ numpy
3
+ torch
4
+ torchvision
5
+ accelerate
6
+ transformers
7
+ #transformers
8
+ #git+https://github.com/huggingface/transformers
9
+ git+https://github.com/huggingface/transformers
10
+ diffusers
11
+ #diffusers
12
+ #git+https://github.com/huggingface/diffusers.git
13
+ #git+https://github.com/huggingface/diffusers
14
+ git+https://github.com/huggingface/diffusers.git
15
+ git+https://github.com/huggingface/diffusers
16
+ scipy
17
+ ftfy
18
+ psutil
19
+ OmegaConf
20
+ pytorch_lightning
21
+ #OmegaConf
22
+ #pytorch_lightning
23
+ triton
24
+ xformers
25
+ #xformers
26
+ #https://github.com/apolinario/xformers/releases/download/0.0.3/xformers-0.0.14.dev0-cp38-cp38-linux_x86_64.whl
27
+ https://github.com/camenduru/stable-diffusion-webui-colab/releases/download/0.0.16/xformers-0.0.16+bc08bbc.d20230123-cp38-cp38-linux_x86_64.whl
requirements.txt ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --extra-index-url https://download.pytorch.org/whl/cu113
2
+ numpy
3
+ torch
4
+ torchvision
5
+ #diffusers
6
+ git+https://github.com/huggingface/diffusers.git
7
+ #transformers
8
+ git+https://github.com/huggingface/transformers
9
+ scipy
10
+ ftfy
11
+ psutil
12
+ accelerate
13
+ #OmegaConf
14
+ #pytorch_lightning
15
+ triton
16
+ xformers
17
+ #https://github.com/apolinario/xformers/releases/download/0.0.3/xformers-0.0.14.dev0-cp38-cp38-linux_x86_64.whl
18
+ https://github.com/camenduru/stable-diffusion-webui-colab/releases/download/0.0.16/xformers-0.0.16+bc08bbc.d20230123-cp38-cp38-linux_x86_64.whl
19
+ https://github.com/camenduru/stable-diffusion-webui-colab/releases/download/0.0.16/xformers-0.0.16+814314d.d20230119.A10G-cp310-cp310-linux_x86_64.whl