Parmist commited on
Commit
be635d0
·
verified ·
1 Parent(s): 4bce8f9

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +641 -1
app.py CHANGED
@@ -1,3 +1,643 @@
1
  import gradio as gr
 
 
 
 
 
 
 
2
 
3
- gr.load("models/strangerzonehf/Flux-Super-Realism-LoRA").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import requests
3
+ import io
4
+ import random
5
+ import os
6
+ import time
7
+ from PIL import Image
8
+ import json
9
 
10
+ # Project by Nymbo
11
+
12
+ # Base API URL for Hugging Face inference
13
+ API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
14
+ # Retrieve the API token from environment variables
15
+ API_TOKEN = os.getenv("HF_READ_TOKEN")
16
+ headers = {"Authorization": f"Bearer {API_TOKEN}"}
17
+ # Timeout for requests
18
+ timeout = 100
19
+
20
+ def query(prompt, model, custom_lora, is_negative=False, steps=35, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7, width=1024, height=1024):
21
+ # Debug log to indicate function start
22
+ print("Starting query function...")
23
+ # Print the parameters for debugging purposes
24
+ print(f"Prompt: {prompt}")
25
+ print(f"Model: {model}")
26
+ print(f"Custom LoRA: {custom_lora}")
27
+ print(f"Parameters - Steps: {steps}, CFG Scale: {cfg_scale}, Seed: {seed}, Strength: {strength}, Width: {width}, Height: {height}")
28
+
29
+ # Check if the prompt is empty or None
30
+ if prompt == "" or prompt is None:
31
+ print("Prompt is empty or None. Exiting query function.") # Debug log
32
+ return None
33
+
34
+ # Generate a unique key for tracking the generation process
35
+ key = random.randint(0, 999)
36
+ print(f"Generated key: {key}") # Debug log
37
+
38
+ # Randomly select an API token from available options to distribute the load
39
+ API_TOKEN = random.choice([os.getenv("HF_READ_TOKEN"), os.getenv("HF_READ_TOKEN_2"), os.getenv("HF_READ_TOKEN_3"), os.getenv("HF_READ_TOKEN_4"), os.getenv("HF_READ_TOKEN_5")])
40
+ headers = {"Authorization": f"Bearer {API_TOKEN}"}
41
+ print(f"Selected API token: {API_TOKEN}") # Debug log
42
+
43
+ # Enhance the prompt with additional details for better quality
44
+ prompt = f"{prompt} | ultra detail, ultra elaboration, ultra quality, perfect."
45
+ print(f'Generation {key}: {prompt}') # Debug log
46
+
47
+ # Set the API URL based on the selected model or custom LoRA
48
+ if custom_lora.strip() != "":
49
+ API_URL = f"https://api-inference.huggingface.co/models/{custom_lora.strip()}"
50
+ else:
51
+ if model == 'Stable Diffusion XL':
52
+ API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0"
53
+ if model == 'FLUX.1 [Dev]':
54
+ API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
55
+ if model == 'FLUX.1 [Schnell]':
56
+ API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-schnell"
57
+ if model == 'Animagine 4.0':
58
+ API_URL = "https://api-inference.huggingface.co/models/cagliostrolab/animagine-xl-4.0"
59
+ prompt = f"masterpiece, high score, great score, absurdres, {prompt}"
60
+ if model == 'Flux Icon Kit':
61
+ API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Icon-Kit-LoRA"
62
+ prompt = f"Icon Kit, {prompt}"
63
+ if model == 'Pixel Background':
64
+ API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Pixel-Background-LoRA"
65
+ prompt = f"Pixel Background, {prompt}"
66
+ if model == 'Meme XD':
67
+ API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Flux-Meme-Xd-LoRA"
68
+ prompt = f"meme, {prompt}"
69
+ if model == 'Chill Guy':
70
+ API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Flux-Chill-Guy-Zone"
71
+ prompt = f"chill guy, {prompt}"
72
+ if model == 'Pepe':
73
+ API_URL = "https://api-inference.huggingface.co/models/openfree/pepe"
74
+ prompt = f"pepe, {prompt}"
75
+ if model == 'NSFWmodel':
76
+ API_URL = "https://api-inference.huggingface.co/models/lexa862/NSFWmodel"
77
+ prompt = f"nude, {prompt}"
78
+ if model == 'Claude Art':
79
+ API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Claude-Art"
80
+ prompt = f"claude art, {prompt}"
81
+ if model == 'Open Genmoji':
82
+ API_URL = "https://api-inference.huggingface.co/models/EvanZhouDev/open-genmoji"
83
+ prompt = f"emoji, {prompt}"
84
+ if model == 'EBook Creative Cover':
85
+ API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/EBook-Creative-Cover-Flux-LoRA"
86
+ prompt = f"EBook Cover, {prompt}"
87
+ if model == 'Flux Logo Design 2':
88
+ API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Logo-Design-Flux-LoRA"
89
+ prompt = f"Logo Design, {prompt}"
90
+ if model == 'Isometric 3D':
91
+ API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Isometric-3D-LoRA"
92
+ prompt = f"Isometric 3D, {prompt}"
93
+ if model == 'Flux Condensation':
94
+ API_URL = "https://api-inference.huggingface.co/models/fofr/flux-condensation"
95
+ prompt = f"CONDENSATION, {prompt}"
96
+ if model == 'Flux Handwriting':
97
+ API_URL = "https://api-inference.huggingface.co/models/fofr/flux-handwriting"
98
+ prompt = f"HWRIT handwriting, {prompt}"
99
+ if model == 'Shou Xin':
100
+ API_URL = "https://api-inference.huggingface.co/models/Datou1111/shou_xin"
101
+ prompt = f"shou_xin, pencil sketch, {prompt}"
102
+ if model == 'Sketch Smudge':
103
+ API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Sketch-Smudge-LoRA"
104
+ prompt = f"Sketch Smudge, {prompt}"
105
+ if model == '80s Cyberpunk':
106
+ API_URL = "https://api-inference.huggingface.co/models/fofr/flux-80s-cyberpunk"
107
+ prompt = f"80s cyberpunk, {prompt}"
108
+ if model == 'Coloring Book Flux':
109
+ API_URL = "https://api-inference.huggingface.co/models/renderartist/coloringbookflux"
110
+ prompt = f"c0l0ringb00k, coloring book, coloring book page, {prompt}"
111
+ if model == 'Flux Miniature LoRA':
112
+ API_URL = "https://api-inference.huggingface.co/models/gokaygokay/Flux-Miniature-LoRA"
113
+ prompt = f"MNTR, miniature drawing, {prompt}"
114
+ if model == 'Sketch Paint':
115
+ API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Sketch-Paint"
116
+ prompt = f"Sketch paint, {prompt}"
117
+ if model == 'Flux UltraRealism 2.0':
118
+ API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Canopus-LoRA-Flux-UltraRealism-2.0"
119
+ prompt = f"Ultra realistic, {prompt}"
120
+ if model == 'Midjourney Mix':
121
+ API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Midjourney-Mix-LoRA"
122
+ prompt = f"midjourney mix, {prompt}"
123
+ if model == 'Midjourney Mix 2':
124
+ API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Midjourney-Mix2-LoRA"
125
+ prompt = f"MJ v6, {prompt}"
126
+ if model == 'Flux Logo Design':
127
+ API_URL = "https://api-inference.huggingface.co/models/Shakker-Labs/FLUX.1-dev-LoRA-Logo-Design"
128
+ prompt = f"wablogo, logo, Minimalist, {prompt}"
129
+ if model == 'Flux Uncensored':
130
+ API_URL = "https://api-inference.huggingface.co/models/enhanceaiteam/Flux-uncensored"
131
+ if model == 'Flux Uncensored V2':
132
+ API_URL = "https://api-inference.huggingface.co/models/enhanceaiteam/Flux-Uncensored-V2"
133
+ if model == 'Flux Tarot Cards':
134
+ API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Ton618-Tarot-Cards-Flux-LoRA"
135
+ prompt = f"Tarot card, {prompt}"
136
+ if model == 'Pixel Art Sprites':
137
+ API_URL = "https://api-inference.huggingface.co/models/sWizad/pokemon-trainer-sprites-pixelart-flux"
138
+ prompt = f"a pixel image, {prompt}"
139
+ if model == '3D Sketchfab':
140
+ API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Castor-3D-Sketchfab-Flux-LoRA"
141
+ prompt = f"3D Sketchfab, {prompt}"
142
+ if model == 'Retro Comic Flux':
143
+ API_URL = "https://api-inference.huggingface.co/models/renderartist/retrocomicflux"
144
+ prompt = f"c0m1c, comic book panel, {prompt}"
145
+ if model == 'Caricature':
146
+ API_URL = "https://api-inference.huggingface.co/models/TheAwakenOne/caricature"
147
+ prompt = f"CCTUR3, {prompt}"
148
+ if model == 'Huggieverse':
149
+ API_URL = "https://api-inference.huggingface.co/models/Chunte/flux-lora-Huggieverse"
150
+ prompt = f"HGGRE, {prompt}"
151
+ if model == 'Propaganda Poster':
152
+ API_URL = "https://api-inference.huggingface.co/models/AlekseyCalvin/Propaganda_Poster_Schnell_by_doctor_diffusion"
153
+ prompt = f"propaganda poster, {prompt}"
154
+ if model == 'Flux Game Assets V2':
155
+ API_URL = "https://api-inference.huggingface.co/models/gokaygokay/Flux-Game-Assets-LoRA-v2"
156
+ prompt = f"wbgmsst, white background, {prompt}"
157
+ if model == 'SDXL HS Card Style':
158
+ API_URL = "https://api-inference.huggingface.co/models/Norod78/sdxl-hearthstone-card-style-lora"
159
+ prompt = f"Hearthstone Card, {prompt}"
160
+ if model == 'SLDR FLUX NSFW v2 Studio':
161
+ API_URL = "https://api-inference.huggingface.co/models/xey/sldr_flux_nsfw_v2-studio"
162
+ if model == 'SoftPasty Flux':
163
+ API_URL = "https://api-inference.huggingface.co/models/alvdansen/softpasty-flux-dev"
164
+ prompt = f"araminta_illus illustration style, {prompt}"
165
+ if model == 'Flux Stickers':
166
+ API_URL = "https://api-inference.huggingface.co/models/diabolic6045/Flux_Sticker_Lora"
167
+ prompt = f"5t1cker 5ty1e, {prompt}"
168
+ if model == 'Flux Animex V2':
169
+ API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Animex-v2-LoRA"
170
+ prompt = f"Animex, {prompt}"
171
+ if model == 'Flux Animeo V1':
172
+ API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Animeo-v1-LoRA"
173
+ prompt = f"Animeo, {prompt}"
174
+ if model == 'Movie Board':
175
+ API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Flux.1-Dev-Movie-Boards-LoRA"
176
+ prompt = f"movieboard, {prompt}"
177
+ if model == 'Purple Dreamy':
178
+ API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Purple-Dreamy-Flux-LoRA"
179
+ prompt = f"Purple Dreamy, {prompt}"
180
+ if model == 'PS1 Style Flux':
181
+ API_URL = "https://api-inference.huggingface.co/models/veryVANYA/ps1-style-flux"
182
+ prompt = f"ps1 game screenshot, {prompt}"
183
+ if model == 'Softserve Anime':
184
+ API_URL = "https://api-inference.huggingface.co/models/alvdansen/softserve_anime"
185
+ prompt = f"sftsrv style illustration, {prompt}"
186
+ if model == 'Flux Tarot v1':
187
+ API_URL = "https://api-inference.huggingface.co/models/multimodalart/flux-tarot-v1"
188
+ prompt = f"in the style of TOK a trtcrd tarot style, {prompt}"
189
+ if model == 'Half Illustration':
190
+ API_URL = "https://api-inference.huggingface.co/models/davisbro/half_illustration"
191
+ prompt = f"in the style of TOK, {prompt}"
192
+ if model == 'OpenDalle v1.1':
193
+ API_URL = "https://api-inference.huggingface.co/models/dataautogpt3/OpenDalleV1.1"
194
+ if model == 'Flux Ghibsky Illustration':
195
+ API_URL = "https://api-inference.huggingface.co/models/aleksa-codes/flux-ghibsky-illustration"
196
+ prompt = f"GHIBSKY style, {prompt}"
197
+ if model == 'Flux Koda':
198
+ API_URL = "https://api-inference.huggingface.co/models/alvdansen/flux-koda"
199
+ prompt = f"flmft style, {prompt}"
200
+ if model == 'Soviet Diffusion XL':
201
+ API_URL = "https://api-inference.huggingface.co/models/openskyml/soviet-diffusion-xl"
202
+ prompt = f"soviet poster, {prompt}"
203
+ if model == 'Flux Realism LoRA':
204
+ API_URL = "https://api-inference.huggingface.co/models/XLabs-AI/flux-RealismLora"
205
+ if model == 'Frosting Lane Flux':
206
+ API_URL = "https://api-inference.huggingface.co/models/alvdansen/frosting_lane_flux"
207
+ prompt = f"frstingln illustration, {prompt}"
208
+ if model == 'Phantasma Anime':
209
+ API_URL = "https://api-inference.huggingface.co/models/alvdansen/phantasma-anime"
210
+ if model == 'Boreal':
211
+ API_URL = "https://api-inference.huggingface.co/models/kudzueye/Boreal"
212
+ prompt = f"photo, {prompt}"
213
+ if model == 'How2Draw':
214
+ API_URL = "https://api-inference.huggingface.co/models/glif/how2draw"
215
+ prompt = f"How2Draw, {prompt}"
216
+ if model == 'Flux AestheticAnime':
217
+ API_URL = "https://api-inference.huggingface.co/models/dataautogpt3/FLUX-AestheticAnime"
218
+ if model == 'Fashion Hut Modeling LoRA':
219
+ API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Fashion-Hut-Modeling-LoRA"
220
+ prompt = f"Modeling of, {prompt}"
221
+ if model == 'Flux SyntheticAnime':
222
+ API_URL = "https://api-inference.huggingface.co/models/dataautogpt3/FLUX-SyntheticAnime"
223
+ prompt = f"1980s anime screengrab, VHS quality, syntheticanime, {prompt}"
224
+ if model == 'Flux Midjourney Anime':
225
+ API_URL = "https://api-inference.huggingface.co/models/brushpenbob/flux-midjourney-anime"
226
+ prompt = f"egmid, {prompt}"
227
+ if model == 'Coloring Book Generator':
228
+ API_URL = "https://api-inference.huggingface.co/models/robert123231/coloringbookgenerator"
229
+ if model == 'Collage Flux':
230
+ API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Castor-Collage-Dim-Flux-LoRA"
231
+ prompt = f"collage, {prompt}"
232
+ if model == 'Flux Product Ad Backdrop':
233
+ API_URL = "https://api-inference.huggingface.co/models/prithivMLmods/Flux-Product-Ad-Backdrop"
234
+ prompt = f"Product Ad, {prompt}"
235
+ if model == 'Product Design':
236
+ API_URL = "https://api-inference.huggingface.co/models/multimodalart/product-design"
237
+ prompt = f"product designed by prdsgn, {prompt}"
238
+ if model == '90s Anime Art':
239
+ API_URL = "https://api-inference.huggingface.co/models/glif/90s-anime-art"
240
+ if model == 'Brain Melt Acid Art':
241
+ API_URL = "https://api-inference.huggingface.co/models/glif/Brain-Melt-Acid-Art"
242
+ prompt = f"maximalism, in an acid surrealism style, {prompt}"
243
+ if model == 'Lustly Flux Uncensored v1':
244
+ API_URL = "https://api-inference.huggingface.co/models/lustlyai/Flux_Lustly.ai_Uncensored_nsfw_v1"
245
+ if model == 'NSFW Master Flux':
246
+ API_URL = "https://api-inference.huggingface.co/models/Keltezaa/NSFW_MASTER_FLUX"
247
+ prompt = f"NSFW, {prompt}"
248
+ if model == 'Flux Outfit Generator':
249
+ API_URL = "https://api-inference.huggingface.co/models/tryonlabs/FLUX.1-dev-LoRA-Outfit-Generator"
250
+ if model == 'Midjourney':
251
+ API_URL = "https://api-inference.huggingface.co/models/Jovie/Midjourney"
252
+ if model == 'DreamPhotoGASM':
253
+ API_URL = "https://api-inference.huggingface.co/models/Yntec/DreamPhotoGASM"
254
+ if model == 'Flux Super Realism LoRA':
255
+ API_URL = "https://api-inference.huggingface.co/models/strangerzonehf/Flux-Super-Realism-LoRA"
256
+ if model == 'Stable Diffusion 2-1':
257
+ API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-2-1-base"
258
+ if model == 'Stable Diffusion 3.5 Large':
259
+ API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-3.5-large"
260
+ if model == 'Stable Diffusion 3.5 Large Turbo':
261
+ API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-3.5-large-turbo"
262
+ if model == 'Stable Diffusion 3 Medium':
263
+ API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-3-medium-diffusers"
264
+ prompt = f"A, {prompt}"
265
+ if model == 'Duchaiten Real3D NSFW XL':
266
+ API_URL = "https://api-inference.huggingface.co/models/stablediffusionapi/duchaiten-real3d-nsfw-xl"
267
+ if model == 'Pixel Art XL':
268
+ API_URL = "https://api-inference.huggingface.co/models/nerijs/pixel-art-xl"
269
+ prompt = f"pixel art, {prompt}"
270
+ if model == 'Character Design':
271
+ API_URL = "https://api-inference.huggingface.co/models/KappaNeuro/character-design"
272
+ prompt = f"Character Design, {prompt}"
273
+ if model == 'Sketched Out Manga':
274
+ API_URL = "https://api-inference.huggingface.co/models/alvdansen/sketchedoutmanga"
275
+ prompt = f"daiton, {prompt}"
276
+ if model == 'Archfey Anime':
277
+ API_URL = "https://api-inference.huggingface.co/models/alvdansen/archfey_anime"
278
+ if model == 'Lofi Cuties':
279
+ API_URL = "https://api-inference.huggingface.co/models/alvdansen/lofi-cuties"
280
+ if model == 'YiffyMix':
281
+ API_URL = "https://api-inference.huggingface.co/models/Yntec/YiffyMix"
282
+ if model == 'Analog Madness Realistic v7':
283
+ API_URL = "https://api-inference.huggingface.co/models/digiplay/AnalogMadness-realistic-model-v7"
284
+ if model == 'Selfie Photography':
285
+ API_URL = "https://api-inference.huggingface.co/models/artificialguybr/selfiephotographyredmond-selfie-photography-lora-for-sdxl"
286
+ prompt = f"instagram model, discord profile picture, {prompt}"
287
+ if model == 'Filmgrain':
288
+ API_URL = "https://api-inference.huggingface.co/models/artificialguybr/filmgrain-redmond-filmgrain-lora-for-sdxl"
289
+ prompt = f"Film Grain, FilmGrainAF, {prompt}"
290
+ if model == 'Leonardo AI Style Illustration':
291
+ API_URL = "https://api-inference.huggingface.co/models/goofyai/Leonardo_Ai_Style_Illustration"
292
+ prompt = f"leonardo style, illustration, vector art, {prompt}"
293
+ if model == 'Cyborg Style XL':
294
+ API_URL = "https://api-inference.huggingface.co/models/goofyai/cyborg_style_xl"
295
+ prompt = f"cyborg style, {prompt}"
296
+ if model == 'Little Tinies':
297
+ API_URL = "https://api-inference.huggingface.co/models/alvdansen/littletinies"
298
+ if model == 'NSFW XL':
299
+ API_URL = "https://api-inference.huggingface.co/models/Dremmar/nsfw-xl"
300
+ if model == 'Analog Redmond':
301
+ API_URL = "https://api-inference.huggingface.co/models/artificialguybr/analogredmond"
302
+ prompt = f"timeless style, {prompt}"
303
+ if model == 'Pixel Art Redmond':
304
+ API_URL = "https://api-inference.huggingface.co/models/artificialguybr/PixelArtRedmond"
305
+ prompt = f"Pixel Art, {prompt}"
306
+ if model == 'Ascii Art':
307
+ API_URL = "https://api-inference.huggingface.co/models/CiroN2022/ascii-art"
308
+ prompt = f"ascii art, {prompt}"
309
+ if model == 'Analog':
310
+ API_URL = "https://api-inference.huggingface.co/models/Yntec/Analog"
311
+ if model == 'Maple Syrup':
312
+ API_URL = "https://api-inference.huggingface.co/models/Yntec/MapleSyrup"
313
+ if model == 'Perfect Lewd Fantasy':
314
+ API_URL = "https://api-inference.huggingface.co/models/digiplay/perfectLewdFantasy_v1.01"
315
+ if model == 'AbsoluteReality 1.8.1':
316
+ API_URL = "https://api-inference.huggingface.co/models/digiplay/AbsoluteReality_v1.8.1"
317
+ if model == 'Disney':
318
+ API_URL = "https://api-inference.huggingface.co/models/goofyai/disney_style_xl"
319
+ prompt = f"Disney style, {prompt}"
320
+ if model == 'Redmond SDXL':
321
+ API_URL = "https://api-inference.huggingface.co/models/artificialguybr/LogoRedmond-LogoLoraForSDXL-V2"
322
+ if model == 'epiCPhotoGasm':
323
+ API_URL = "https://api-inference.huggingface.co/models/Yntec/epiCPhotoGasm"
324
+ print(f"API URL set to: {API_URL}") # Debug log
325
+
326
+ # Define the payload for the request
327
+ payload = {
328
+ "inputs": prompt,
329
+ "is_negative": is_negative, # Whether to use a negative prompt
330
+ "steps": steps, # Number of sampling steps
331
+ "cfg_scale": cfg_scale, # Scale for controlling adherence to prompt
332
+ "seed": seed if seed != -1 else random.randint(1, 1000000000), # Random seed for reproducibility
333
+ "strength": strength, # How strongly the model should transform the image
334
+ "parameters": {
335
+ "width": width, # Width of the generated image
336
+ "height": height # Height of the generated image
337
+ }
338
+ }
339
+ print(f"Payload: {json.dumps(payload, indent=2)}") # Debug log
340
+
341
+ # Make a request to the API to generate the image
342
+ try:
343
+ response = requests.post(API_URL, headers=headers, json=payload, timeout=timeout)
344
+ print(f"Response status code: {response.status_code}") # Debug log
345
+ except requests.exceptions.RequestException as e:
346
+ # Log any request exceptions and raise an error for the user
347
+ print(f"Request failed: {e}") # Debug log
348
+ raise gr.Error(f"Request failed: {e}")
349
+
350
+ # Check if the response status is not successful
351
+ if response.status_code != 200:
352
+ print(f"Error: Failed to retrieve image. Response status: {response.status_code}") # Debug log
353
+ print(f"Response content: {response.text}") # Debug log
354
+ if response.status_code == 400:
355
+ raise gr.Error(f"{response.status_code}: Bad Request - There might be an issue with the input parameters.")
356
+ elif response.status_code == 401:
357
+ raise gr.Error(f"{response.status_code}: Unauthorized - Please check your API token.")
358
+ elif response.status_code == 403:
359
+ raise gr.Error(f"{response.status_code}: Forbidden - You do not have permission to access this model.")
360
+ elif response.status_code == 404:
361
+ raise gr.Error(f"{response.status_code}: Not Found - The requested model could not be found.")
362
+ elif response.status_code == 503:
363
+ raise gr.Error(f"{response.status_code}: The model is being loaded. Please try again later.")
364
+ else:
365
+ raise gr.Error(f"{response.status_code}: An unexpected error occurred.")
366
+
367
+ try:
368
+ # Attempt to read the image from the response content
369
+ image_bytes = response.content
370
+ image = Image.open(io.BytesIO(image_bytes))
371
+ print(f'Generation {key} completed! ({prompt})') # Debug log
372
+ return image
373
+ except Exception as e:
374
+ # Handle any errors that occur when opening the image
375
+ print(f"Error while trying to open image: {e}") # Debug log
376
+ return None
377
+
378
+ # Custom CSS to hide the footer in the interface
379
+ css = """
380
+ * {}
381
+ footer {visibility: hidden !important;}
382
+ """
383
+
384
+ print("Initializing Gradio interface...") # Debug log
385
+
386
+ # Define the Gradio interface
387
+ with gr.Blocks(theme='Nymbo/Nymbo_Theme_5') as dalle:
388
+ # Tab for basic settings
389
+ with gr.Tab("Basic Settings"):
390
+ with gr.Row():
391
+ with gr.Column(elem_id="prompt-container"):
392
+ with gr.Row():
393
+ # Textbox for user to input the prompt
394
+ text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=3, elem_id="prompt-text-input")
395
+ with gr.Row():
396
+ # Textbox for custom LoRA input
397
+ custom_lora = gr.Textbox(label="Custom LoRA", info="LoRA Hugging Face path (optional)", placeholder="multimodalart/vintage-ads-flux")
398
+ with gr.Row():
399
+ # Accordion for selecting the model
400
+ with gr.Accordion("Featured Models", open=True):
401
+ # Textbox for searching models
402
+ model_search = gr.Textbox(label="Filter Models", placeholder="Search for a featured model...", lines=1, elem_id="model-search-input")
403
+ models_list = (
404
+ "3D Sketchfab",
405
+ "80s Cyberpunk",
406
+ "90s Anime Art",
407
+ "AbsoluteReality 1.8.1",
408
+ "Analog",
409
+ "Analog Madness Realistic v7",
410
+ "Analog Redmond",
411
+ "Animagine 4.0",
412
+ "Archfey Anime",
413
+ "Ascii Art",
414
+ "Brain Melt Acid Art",
415
+ "Boreal",
416
+ "Caricature",
417
+ "Collage Flux",
418
+ "Coloring Book Flux",
419
+ "Character Design",
420
+ "Chill Guy",
421
+ "Claude Art",
422
+ "Coloring Book Generator",
423
+ "Cyborg Style XL",
424
+ "Disney",
425
+ "DreamPhotoGASM",
426
+ "Duchaiten Real3D NSFW XL",
427
+ "EBook Creative Cover",
428
+ "EpiCPhotoGasm",
429
+ "Fashion Hut Modeling LoRA",
430
+ "Filmgrain",
431
+ "FLUX.1 [Dev]",
432
+ "FLUX.1 [Schnell]",
433
+ "FLux Condensation",
434
+ "Flux Handwriting",
435
+ "Flux Realism LoRA",
436
+ "Flux Super Realism LoRA",
437
+ "Flux Uncensored",
438
+ "Flux Uncensored V2",
439
+ "Flux Game Assets V2",
440
+ "Flux Icon Kit",
441
+ "Flux Ghibsky Illustration",
442
+ "Flux Animex V2",
443
+ "Flux Animeo V1",
444
+ "Flux AestheticAnime",
445
+ "Flux SyntheticAnime",
446
+ "Flux Stickers",
447
+ "Flux Koda",
448
+ "Flux Tarot v1",
449
+ "Flux Tarot Cards",
450
+ "Flux UltraRealism 2.0",
451
+ "Flux Midjourney Anime",
452
+ "Flux Miniature LoRA",
453
+ "Flux Logo Design",
454
+ "Flux Logo Design 2",
455
+ "Flux Product Ad Backdrop",
456
+ "Flux Outfit Generator",
457
+ "Frosting Lane Flux",
458
+ "Half Illustration",
459
+ "How2Draw",
460
+ "Huggieverse",
461
+ "Isometric 3D",
462
+ "Leonardo AI Style Illustration",
463
+ "Little Tinies",
464
+ "Lofi Cuties",
465
+ "Lustly Flux Uncensored v1",
466
+ "Maple Syrup",
467
+ "Meme XD",
468
+ "Midjourney",
469
+ "Midjourney Mix",
470
+ "Midjourney Mix 2",
471
+ "Movie Board",
472
+ "NSFWmodel",
473
+ "NSFW Master Flux",
474
+ "NSFW XL",
475
+ "OpenDalle v1.1",
476
+ "Open Genmoji",
477
+ "Pepe",
478
+ "Perfect Lewd Fantasy",
479
+ "Pixel Art Redmond",
480
+ "Pixel Art XL",
481
+ "Pixel Art Sprites",
482
+ "Pixel Background",
483
+ "Product Design",
484
+ "Propaganda Poster",
485
+ "Purple Dreamy",
486
+ "Phantasma Anime",
487
+ "PS1 Style Flux",
488
+ "Redmond SDXL",
489
+ "Retro Comic Flux",
490
+ "SDXL HS Card Style",
491
+ "Sketch Smudge",
492
+ "Shou Xin",
493
+ "Softserve Anime",
494
+ "SoftPasty Flux",
495
+ "Soviet Diffusion XL",
496
+ "Sketched Out Manga",
497
+ "Sketch Paint",
498
+ "SLDR FLUX NSFW v2 Studio",
499
+ "Selfie Photography",
500
+ "Stable Diffusion 2-1",
501
+ "Stable Diffusion XL",
502
+ "Stable Diffusion 3 Medium",
503
+ "Stable Diffusion 3.5 Large",
504
+ "Stable Diffusion 3.5 Large Turbo",
505
+ "YiffyMix",
506
+ )
507
+
508
+ # Radio buttons to select the desired model
509
+ model = gr.Radio(label="Select a model below", value="FLUX.1 [Schnell]", choices=models_list, interactive=True, elem_id="model-radio")
510
+
511
+ # Filtering models based on search input
512
+ def filter_models(search_term):
513
+ filtered_models = [m for m in models_list if search_term.lower() in m.lower()]
514
+ return gr.update(choices=filtered_models)
515
+
516
+ # Update model list when search box is used
517
+ model_search.change(filter_models, inputs=model_search, outputs=model)
518
+
519
+ # Tab for advanced settings
520
+ with gr.Tab("Advanced Settings"):
521
+ with gr.Row():
522
+ # Textbox for specifying elements to exclude from the image
523
+ negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="What should not be in the image", value="(deformed, distorted, disfigured), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, misspellings, typos", lines=3, elem_id="negative-prompt-text-input")
524
+ with gr.Row():
525
+ # Slider for selecting the image width
526
+ width = gr.Slider(label="Width", value=1024, minimum=64, maximum=1216, step=32)
527
+ # Slider for selecting the image height
528
+ height = gr.Slider(label="Height", value=1024, minimum=64, maximum=1216, step=32)
529
+ with gr.Row():
530
+ # Slider for setting the number of sampling steps
531
+ steps = gr.Slider(label="Sampling steps", value=35, minimum=1, maximum=100, step=1)
532
+ with gr.Row():
533
+ # Slider for adjusting the CFG scale (guidance scale)
534
+ cfg = gr.Slider(label="CFG Scale", value=7, minimum=1, maximum=20, step=1)
535
+ with gr.Row():
536
+ # Slider for adjusting the transformation strength
537
+ strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
538
+ with gr.Row():
539
+ # Slider for setting the seed for reproducibility
540
+ seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
541
+ with gr.Row():
542
+ # Radio buttons for selecting the sampling method
543
+ method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"])
544
+
545
+ # Tab for image editing options
546
+ with gr.Tab("Image Editor"):
547
+ # Function to simulate a delay for processing
548
+ def sleep(im):
549
+ print("Sleeping for 5 seconds...") # Debug log
550
+ time.sleep(5)
551
+ return [im["background"], im["layers"][0], im["layers"][1], im["composite"]]
552
+
553
+ # Function to return the composite image
554
+ def predict(im):
555
+ print("Predicting composite image...") # Debug log
556
+ return im["composite"]
557
+
558
+ with gr.Blocks() as demo:
559
+ with gr.Row():
560
+ # Image editor component for user adjustments
561
+ im = gr.ImageEditor(
562
+ type="numpy",
563
+ crop_size="1:1", # Set crop size to a square aspect ratio
564
+ )
565
+
566
+ # Tab to provide information to the user
567
+ with gr.Tab("Information"):
568
+ with gr.Row():
569
+ # Display a sample prompt for guidance
570
+ gr.Textbox(label="Sample prompt", value="{prompt} | ultra detail, ultra elaboration, ultra quality, perfect.")
571
+
572
+ # Accordion displaying featured models
573
+ with gr.Accordion("Featured Models (WiP)", open=False):
574
+ gr.HTML(
575
+ """
576
+ <p><a href="https://huggingface.co/models?inference=warm&pipeline_tag=text-to-image&sort=trending">See all available models</a></p>
577
+ <table style="width:100%; text-align:center; margin:auto;">
578
+ <tr>
579
+ <th>Model Name</th>
580
+ <th>Typography</th>
581
+ <th>Notes</th>
582
+ </tr>
583
+ <tr>
584
+ <td>FLUX.1 Dev</td>
585
+ <td>✅</td>
586
+ <td></td>
587
+ </tr>
588
+ <tr>
589
+ <td>FLUX.1 Schnell</td>
590
+ <td>✅</td>
591
+ <td></td>
592
+ </tr>
593
+ <tr>
594
+ <td>Stable Diffusion 3.5 Large</td>
595
+ <td>✅</td>
596
+ <td></td>
597
+ </tr>
598
+ </table>
599
+ """
600
+ )
601
+
602
+ # Accordion providing an overview of advanced settings
603
+ with gr.Accordion("Advanced Settings Overview", open=False):
604
+ gr.Markdown(
605
+ """
606
+ ## Negative Prompt
607
+ ###### This box is for telling the AI what you don't want in your images. Think of it as a way to avoid certain elements. For instance, if you don't want blurry images or extra limbs showing up, this is where you'd mention it.
608
+
609
+ ## Width & Height
610
+ ###### These sliders allow you to specify the resolution of your image. Default value is 1024x1024, and maximum output is 1216x1216.
611
+
612
+ ## Sampling Steps
613
+ ###### Think of this like the number of brushstrokes in a painting. A higher number can give you a more detailed picture, but it also takes a bit longer. Generally, a middle-ground number like 35 is a good balance between quality and speed.
614
+
615
+ ## CFG Scale
616
+ ###### CFG stands for "Control Free Guidance." The scale adjusts how closely the AI follows your prompt. A lower number makes the AI more creative and free-flowing, while a higher number makes it stick closely to what you asked for. If you want the AI to take fewer artistic liberties, slide this towards a higher number. Just think "Control Freak Gauge".
617
+
618
+ ## Sampling Method
619
+ ###### This is the technique the AI uses to create your image. Each option is a different approach, like choosing between pencils, markers, or paint. You don't need to worry too much about this; the default setting is usually the best choice for most users.
620
+
621
+ ## Strength
622
+ ###### This setting is a bit like the 'intensity' knob. It determines how much the AI modifies the base image it starts with. If you're looking to make subtle changes, keep this low. For more drastic transformations, turn it up.
623
+
624
+ ## Seed
625
+ ###### You can think of the seed as a 'recipe' for creating an image. If you find a seed that gives you a result you love, you can use it again to create a similar image. If you leave it at -1, the AI will generate a new seed every time.
626
+
627
+ ### Remember, these settings are all about giving you control over the image generation process. Feel free to experiment and see what each one does. And if you're ever in doubt, the default settings are a great place to start. Happy creating!
628
+ """
629
+ )
630
+
631
+ # Row containing the 'Run' button to trigger the image generation
632
+ with gr.Row():
633
+ text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
634
+ # Row for displaying the generated image output
635
+ with gr.Row():
636
+ image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
637
+
638
+ # Set up button click event to call the query function
639
+ text_button.click(query, inputs=[text_prompt, model, custom_lora, negative_prompt, steps, cfg, method, seed, strength, width, height], outputs=image_output)
640
+
641
+ print("Launching Gradio interface...") # Debug log
642
+ # Launch the Gradio interface without showing the API or sharing externally
643
+ dalle.launch(show_api=False, share=False)