Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,245 +1,44 @@
|
|
1 |
import gradio as gr
|
2 |
-
import os
|
|
|
|
|
3 |
import sys
|
4 |
from pathlib import Path
|
5 |
|
6 |
-
models
|
7 |
-
|
8 |
-
{"name": "Dreamlike Anime", "url": "dreamlike-art/dreamlike-anime-1.0"},
|
9 |
-
# {"name": "Dreamlike Diffusion", "url": "dreamlike-art/dreamlike-diffusion-1.0"},
|
10 |
-
# {"name": "Dreamlike Photoreal", "url": "dreamlike-art/dreamlike-photoreal-2.0"},
|
11 |
-
# {"name": "Dreamshaper", "url": "Lykon/DreamShaper"},
|
12 |
-
# {"name": "Never Ending Dream 2", "url": "luongphamit/NeverEnding-Dream2"},
|
13 |
-
# {"name": "Protogen X 5.8", "url": "darkstorm2150/Protogen_x5.8_Official_Release"},
|
14 |
-
# {"name": "β€ ART MODELS ==========", "url": "dreamlike-art/dreamlike-diffusion-1.0"},
|
15 |
-
# {"name": "Alice in Diffusion Land", "url": "Guizmus/SDArt_AliceInDiffusionLand"},
|
16 |
-
# {"name": "Alt Clip", "url": "BAAI/AltCLIP"},
|
17 |
-
# {"name": "Anything Midjourney 4.1", "url": "Joeythemonster/anything-midjourney-v-4-1"},
|
18 |
-
# {"name": "Chaos and Order", "url": "Guizmus/SDArt_ChaosAndOrder768"},
|
19 |
-
# {"name": "Chilloutclara", "url": "Fred99774/chilloutvlara"},
|
20 |
-
# {"name": "Comic Diffusion", "url": "ogkalu/Comic-Diffusion"},
|
21 |
-
# {"name": "Cosmic Horros 768", "url": "Guizmus/SDArt_cosmichorrors768"},
|
22 |
-
# {"name": "Cosmic Horros", "url": "Guizmus/SDArt_cosmichorrors"},
|
23 |
-
# {"name": "DGSpitzer", "url": "DGSpitzer/DGSpitzer-Art-Diffusion"},
|
24 |
-
# {"name": "Dreamlike Diffusion", "url": "dreamlike-art/dreamlike-diffusion-1.0"},
|
25 |
-
# {"name": "Dungeons and Diffusion", "url": "0xJustin/Dungeons-and-Diffusion"},
|
26 |
-
# {"name": "Elden Ring", "url": "nitrosocke/elden-ring-diffusion"},
|
27 |
-
# {"name": "Epic Diffusion 1.1", "url": "johnslegers/epic-diffusion-v1.1"},
|
28 |
-
# {"name": "Epic Diffusion", "url": "johnslegers/epic-diffusion"},
|
29 |
-
# {"name": "EpicMix Realism", "url": "Duskfallcrew/EpicMix_Realism"},
|
30 |
-
# {"name": "Fantasy Mix", "url": "theintuitiveye/FantasyMix"},
|
31 |
-
# {"name": "Girl New 1", "url": "Fred99774/girlnew1"},
|
32 |
-
# {"name": "Lit 6B", "url": "hakurei/lit-6B"},
|
33 |
-
# {"name": "Luna Diffusion", "url": "proximasanfinetuning/luna-diffusion"},
|
34 |
-
# {"name": "Midjourney 4.0", "url": "flax/midjourney-v4-diffusion"},
|
35 |
-
# {"name": "Midjourney 4.1", "url": "Joeythemonster/anything-midjourney-v-4-1"},
|
36 |
-
# {"name": "Mo-Di Diffusion", "url": "nitrosocke/mo-di-diffusion"},
|
37 |
-
# {"name": "Nitro Diffusion", "url": "nitrosocke/Nitro-Diffusion"},
|
38 |
-
# {"name": "Openjourney V2", "url": "prompthero/openjourney-v2"},
|
39 |
-
# {"name": "Openjourney", "url": "prompthero/openjourney"},
|
40 |
-
# {"name": "Seek Art Mega", "url": "coreco/seek.art_MEGA"},
|
41 |
-
# {"name": "Something", "url": "Guizmus/SDArt_something"},
|
42 |
-
# {"name": "Spider Verse diffusion", "url": "nitrosocke/spider-verse-diffusion"},
|
43 |
-
# {"name": "Vintedois 1.0", "url": "22h/vintedois-diffusion-v0-1"},
|
44 |
-
# {"name": "Vintedois 2.0", "url": "22h/vintedois-diffusion-v0-2"},
|
45 |
-
# {"name": "β€ ART STYLES ==========", "url": "joachimsallstrom/Double-Exposure-Diffusion"},
|
46 |
-
# {"name": "Balloon Art", "url": "Fictiverse/Stable_Diffusion_BalloonArt_Model"},
|
47 |
-
# {"name": "Double Exposure Diffusion", "url": "joachimsallstrom/Double-Exposure-Diffusion"},
|
48 |
-
# {"name": "Fluid Art", "url": "Fictiverse/Stable_Diffusion_FluidArt_Model"},
|
49 |
-
# {"name": "GTA5 Artwork Diffusion", "url": "ItsJayQz/GTA5_Artwork_Diffusion"},
|
50 |
-
# {"name": "Marvel WhatIf Diffusion", "url": "ItsJayQz/Marvel_WhatIf_Diffusion"},
|
51 |
-
# {"name": "Naruto Diffuser", "url": "lambdalabs/sd-naruto-diffusers"},
|
52 |
-
# {"name": "Papercut", "url": "Fictiverse/Stable_Diffusion_PaperCut_Model"},
|
53 |
-
# {"name": "Pokemon Diffuser", "url": "lambdalabs/sd-pokemon-diffusers"},
|
54 |
-
# {"name": "Synthwave Punk 2", "url": "ItsJayQz/SynthwavePunk-v2"},
|
55 |
-
# {"name": "Valorant Diffusion", "url": "ItsJayQz/Valorant_Diffusion"},
|
56 |
-
# {"name": "Van Gogh Diffusion", "url": "dallinmackay/Van-Gogh-diffusion"},
|
57 |
-
# {"name": "Vectorartz Diffusion", "url": "coder119/Vectorartz_Diffusion"},
|
58 |
-
# {"name": "VoxelArt", "url": "Fictiverse/Stable_Diffusion_VoxelArt_Model"},
|
59 |
-
# {"name": "β€ ANIME MODELS ==========", "url": "dreamlike-art/dreamlike-anime-1.0"},
|
60 |
-
# {"name": "7 Pa", "url": "AIARTCHAN/7pa"},
|
61 |
-
# {"name": "A Certain Model", "url": "JosephusCheung/ACertainModel"},
|
62 |
-
# {"name": "A Certain Thing", "url": "JosephusCheung/ACertainThing"},
|
63 |
-
# {"name": "A Certainity", "url": "JosephusCheung/ACertainty"},
|
64 |
-
# {"name": "Abyss Hell Hero", "url": "AIARTCHAN/AbyssHellHero"},
|
65 |
-
# {"name": "Abyss Maple 3", "url": "AIARTCHAN/AbyssMapleVer3"},
|
66 |
-
# {"name": "Abyss Orange Mix 2", "url": "WarriorMama777/AbyssOrangeMix2"},
|
67 |
-
# {"name": "Abyss Orange Mix", "url": "WarriorMama777/AbyssOrangeMix"},
|
68 |
-
# {"name": "AbyssHell 3", "url": "AIARTCHAN/AbyssHellVer3"},
|
69 |
-
# {"name": "All 526 Animated", "url": "stablediffusionapi/all-526-animated"},
|
70 |
-
# {"name": "Anidosmix 3", "url": "AIARTCHAN/anidosmixV2"},
|
71 |
-
# {"name": "Anime Kawai Diffusion", "url": "Ojimi/anime-kawai-diffusion"},
|
72 |
-
# {"name": "Anireal 3D V2", "url": "circulus/sd-anireal-3d-v2"},
|
73 |
-
# {"name": "AnyLORA", "url": "kubanemil/AnyLORA"},
|
74 |
-
# {"name": "Anything 2.1", "url": "swl-models/anything-v2.1"},
|
75 |
-
# {"name": "Anything 3.0 Light", "url": "mm00/anything-v3.0-light"},
|
76 |
-
# {"name": "Anything 3.0", "url": "Linaqruf/anything-v3.0"},
|
77 |
-
# {"name": "Anything 3.1", "url": "cag/anything-v3-1"},
|
78 |
-
# {"name": "Anything 3X", "url": "iZELX1/Anything-V3-X"},
|
79 |
-
# {"name": "Anything 4.0", "url": "andite/anything-v4.0"},
|
80 |
-
# {"name": "Anything 5.0", "url": "stablediffusionapi/anything-v5"},
|
81 |
-
# {"name": "Anything Else 4", "url": "stablediffusionapi/anythingelse-v4"},
|
82 |
-
# {"name": "Anything Else 5", "url": "stablediffusionapi/anything-v5"},
|
83 |
-
# {"name": "Arcane Diffusion", "url": "nitrosocke/Arcane-Diffusion"},
|
84 |
-
# {"name": "Archer Diffusion", "url": "nitrosocke/archer-diffusion"},
|
85 |
-
# {"name": "Asian Mix", "url": "D1b4l4p/AsianMix"},
|
86 |
-
# {"name": "Blood Orange Mix", "url": "WarriorMama777/BloodOrangeMix"},
|
87 |
-
# {"name": "CamelliaMix 2.5D","url": "stablediffusionapi/camelliamix25d"},
|
88 |
-
# {"name": "CamelliaMix Line","url": "stablediffusionapi/camelliamixline"},
|
89 |
-
# {"name": "CamelliaMix","url": "Powidl43/CamelliaMix"},
|
90 |
-
# {"name": "Cetusmix", "url": "stablediffusionapi/cetusmix"},
|
91 |
-
# {"name": "Chik Mix", "url": "stablediffusionapi/chikmix"},
|
92 |
-
# {"name": "Chikmix", "url": "stablediffusionapi/chikmix"},
|
93 |
-
# {"name": "Chillout App Factory","url": "stablediffusionapi/chillout-app-factory"},
|
94 |
-
# {"name": "Classic Anime", "url": "nitrosocke/classic-anim-diffusion"},
|
95 |
-
# {"name": "Cool Japan Diffusion 2.1.2", "url": "aipicasso/cool-japan-diffusion-2-1-2"},
|
96 |
-
# {"name": "Cosmic Babes", "url": "stablediffusionapi/cosmic-babes"},
|
97 |
-
# {"name": "Counterfeit 1.0", "url": "gsdf/counterfeit-v1.0"},
|
98 |
-
# {"name": "Counterfeit 2", "url": "gsdf/Counterfeit-V2.0"},
|
99 |
-
# {"name": "Counterfeit 2.0", "url": "gsdf/Counterfeit-V2.0"},
|
100 |
-
# {"name": "Counterfeit 3.0", "url": "stablediffusionapi/counterfeit-v30"},
|
101 |
-
# {"name": "CuteSexyRobutts", "url": "andite/cutesexyrobutts-diffusion"},
|
102 |
-
# {"name": "CyberPunk Anime", "url": "DGSpitzer/Cyberpunk-Anime-Diffusion"},
|
103 |
-
# {"name": "Dark Sushi Mix", "url": "stablediffusionapi/dark-sushi-mix"},
|
104 |
-
# {"name": "Dash Sushi 25d", "url": "stablediffusionapi/dark-sushi-25d"},
|
105 |
-
# {"name": "Dreamlike Anime", "url": "dreamlike-art/dreamlike-anime-1.0"},
|
106 |
-
# {"name": "DucHaiten Anime", "url": "DucHaiten/DucHaitenAnime"},
|
107 |
-
# {"name": "Eerie Orange Mix", "url": "WarriorMama777/EerieOrangeMix"},
|
108 |
-
# {"name": "Eimis Anime Diffusion", "url": "eimiss/EimisAnimeDiffusion_1.0v"},
|
109 |
-
# {"name": "Ghibli Diffusion", "url": "nitrosocke/Ghibli-Diffusion"},
|
110 |
-
# {"name": "GrapeFruit", "url": "iZELX1/Grapefruit"},
|
111 |
-
# {"name": "GuoFeng 3", "url": "xiaolxl/GuoFeng3"},
|
112 |
-
# {"name": "Guweiz Diffusion", "url": "andite/guweiz-diffusion"},
|
113 |
-
# {"name": "Hiten Diffusion", "url": "andite/hiten-diffusion"},
|
114 |
-
# {"name": "Icomix 2", "url": "stablediffusionapi/icomix-2"},
|
115 |
-
# {"name": "InkPunk Diffusion", "url": "Envvi/Inkpunk-Diffusion"},
|
116 |
-
# {"name": "Mama Orange Mixs", "url": "WarriorMama777/OrangeMixs"},
|
117 |
-
# {"name": "Mashuu Diffusion", "url": "andite/mashuu-diffusion"},
|
118 |
-
# {"name": "Meina Alter", "url": "stablediffusionapi/meinaalter"},
|
119 |
-
# {"name": "Meina Pastel", "url": "stablediffusionapi/meinapastel"},
|
120 |
-
# {"name": "MeinaMix 7", "url": "Nacholmo/meinamixv7-diffusers"},
|
121 |
-
# {"name": "Mignon Diffusion", "url": "andite/mignon-diffusion"},
|
122 |
-
# {"name": "MikaPikazo Diffusion", "url": "andite/mikapikazo-diffusion"},
|
123 |
-
# {"name": "Mikapikazo", "url": "andite/mikapikazo-diffusion"},
|
124 |
-
# {"name": "Mix Pro V4", "url": "AIARTCHAN/MIX-Pro-V4"},
|
125 |
-
# {"name": "NeverEnding-Dream", "url": "Lykon/NeverEnding-Dream"},
|
126 |
-
# {"name": "Openjourney 4", "url": "prompthero/openjourney-v4"},
|
127 |
-
# {"name": "OpenNiji", "url": "Korakoe/OpenNiji"},
|
128 |
-
# {"name": "Pastel Mix", "url": "andite/pastel-mix"},
|
129 |
-
# {"name": "Picasso Diffusion 1.1", "url": "aipicasso/picasso-diffusion-1-1"},
|
130 |
-
# {"name": "Piromizu Diffusion", "url": "andite/piromizu-diffusion"},
|
131 |
-
# {"name": "Protogen 2.2", "url": "darkstorm2150/Protogen_v2.2_Official_Release"},
|
132 |
-
# {"name": "Protogen Infinity", "url": "darkstorm2150/Protogen_Infinity_Official_Release"},
|
133 |
-
# {"name": "Protogen X 3.4", "url": "darkstorm2150/Protogen_x3.4_Official_Release"},
|
134 |
-
# {"name": "Rev Anim", "url": "stablediffusionapi/rev-anim"},
|
135 |
-
# {"name": "Rev Animated", "url": "coreml/coreml-ReV-Animated"},
|
136 |
-
# {"name": "Rev Animated", "url": "LottePeisch/RevAnimated-Diffusers"},
|
137 |
-
# {"name": "Something V 2.2","url": "NoCrypt/SomethingV2_2"},
|
138 |
-
# {"name": "Something V2","url": "NoCrypt/SomethingV2"},
|
139 |
-
# {"name": "Three Delicacy", "url": "stablediffusionapi/three-delicacy"},
|
140 |
-
# {"name": "Three Delicacy wonto", "url": "stablediffusionapi/three-delicacy-wonto"},
|
141 |
-
# {"name": "TMND mix", "url": "stablediffusionapi/tmnd-mix"},
|
142 |
-
# {"name": "Waifu Diffusion", "url": "hakurei/waifu-diffusion"},
|
143 |
-
# {"name": "β€ REALISTIC PHOTO MODELS ==========", "url": "dreamlike-art/dreamlike-photoreal-2.0"},
|
144 |
-
# {"name": "AmiIReal", "url": "stablediffusionapi/amireal"},
|
145 |
-
# {"name": "Analog Diffusion", "url": "wavymulder/Analog-Diffusion"},
|
146 |
-
# {"name": "Circulus 2.8", "url": "circulus/sd-photoreal-v2.8"},
|
147 |
-
# {"name": "Circulus Photoreal V2", "url": "circulus/sd-photoreal-real-v2"},
|
148 |
-
# {"name": "Claudfuen 1", "url": "claudfuen/photorealistic-fuen-v1"},
|
149 |
-
# {"name": "Collage Diffusion", "url": "wavymulder/collage-diffusion"},
|
150 |
-
# {"name": "Cyberrealistic", "url": "stablediffusionapi/cyberrealistic"},
|
151 |
-
# {"name": "Dreamlike Photoreal", "url": "dreamlike-art/dreamlike-photoreal-2.0"},
|
152 |
-
# {"name": "Dreamful 2", "url": "Hius/DreamFul-V2"},
|
153 |
-
# {"name": "GakkiMix768", "url": "Sa1i/gakki-mix-768"},
|
154 |
-
# {"name": "Grimoeresigils", "url": "ECarbenia/grimoiresigils"},
|
155 |
-
# {"name": "HARDBlend", "url": "theintuitiveye/HARDblend"},
|
156 |
-
# {"name": "HassanBlend 1.4", "url": "hassanblend/hassanblend1.4"},
|
157 |
-
# {"name": "HassanBlend 1.5.1.2", "url": "hassanblend/HassanBlend1.5.1.2"},
|
158 |
-
# {"name": "Lomo Diffusion", "url": "wavymulder/lomo-diffusion"},
|
159 |
-
# {"name": "Model Shoot", "url": "wavymulder/modelshoot"},
|
160 |
-
# {"name": "Portrait Plus", "url": "wavymulder/portraitplus"},
|
161 |
-
# {"name": "QuinceMix", "url": "Hemlok/QuinceMix"},
|
162 |
-
# {"name": "Realistic Vision 1.4", "url": "SG161222/Realistic_Vision_V1.4"},
|
163 |
-
# {"name": "The Ally", "url": "stablediffusionapi/the-ally"},
|
164 |
-
# {"name": "Timeless Diffusion", "url": "wavymulder/timeless-diffusion"},
|
165 |
-
# {"name": "UltraSkin", "url": "VegaKH/Ultraskin"},
|
166 |
-
# {"name": "Wavyfusion", "url": "wavymulder/wavyfusion"},
|
167 |
-
# {"name": "β€ SEMI-REALISTIC MODELS ==========", "url": "stablediffusionapi/all-526"},
|
168 |
-
# {"name": "All 526", "url": "stablediffusionapi/all-526"},
|
169 |
-
# {"name": "All 526 animated", "url": "stablediffusionapi/all-526-animated"},
|
170 |
-
# {"name": "Circulus Semi Real 2", "url": "circulus/sd-photoreal-semi-v2"},
|
171 |
-
# {"name": "Semi Real Mix", "url": "robotjung/SemiRealMix"},
|
172 |
-
# {"name": "SpyBG", "url": "stablediffusionapi/spybg"},
|
173 |
-
# {"name": "β€ STABLE DIFFUSION MODELS ==========", "url": "stabilityai/stable-diffusion-2-1"},
|
174 |
-
# {"name": "Stable Diffusion 1.4","url": "CompVis/stable-diffusion-v1-4"},
|
175 |
-
# {"name": "Stable Diffusion 1.5","url": "runwayml/stable-diffusion-v1-5"},
|
176 |
-
# {"name": "Stable Diffusion 2.1","url": "stabilityai/stable-diffusion-2-1"},
|
177 |
-
# {"name": "Stable Diffusion 2.1 Base","url": "stabilityai/stable-diffusion-2-1-base"},
|
178 |
-
# {"name": "Stable Diffusion 2.1 Unclip","url": "stabilityai/stable-diffusion-2-1-unclip"},
|
179 |
-
# {"name": "β€ SCI FI MODELS ==========", "url": "nitrosocke/Future-Diffusion"},
|
180 |
-
# {"name": "Future Diffusion", "url": "nitrosocke/Future-Diffusion"},
|
181 |
-
# {"name": "JWST Deep Space Diffusion", "url": "dallinmackay/JWST-Deep-Space-diffusion"},
|
182 |
-
# {"name": "Robo Diffusion 3 Base", "url": "nousr/robo-diffusion-2-base"},
|
183 |
-
# {"name": "Robo Diffusion", "url": "nousr/robo-diffusion"},
|
184 |
-
# {"name": "Tron Legacy Diffusion", "url": "dallinmackay/Tron-Legacy-diffusion"},
|
185 |
-
# {"name": "β€ 3D ART MODELS ==========", "url": "DucHaiten/DucHaitenAIart"},
|
186 |
-
# {"name": "DucHaiten Art", "url": "DucHaiten/DucHaitenAIart"},
|
187 |
-
# {"name": "DucHaiten ClassicAnime", "url": "DucHaiten/DH_ClassicAnime"},
|
188 |
-
# {"name": "DucHaiten DreamWorld", "url": "DucHaiten/DucHaitenDreamWorld"},
|
189 |
-
# {"name": "DucHaiten Journey", "url": "DucHaiten/DucHaitenJourney"},
|
190 |
-
# {"name": "DucHaiten StyleLikeMe", "url": "DucHaiten/DucHaiten-StyleLikeMe"},
|
191 |
-
# {"name": "DucHaiten SuperCute", "url": "DucHaiten/DucHaitenSuperCute"},
|
192 |
-
# {"name": "Redshift Diffusion 768", "url": "nitrosocke/redshift-diffusion-768"},
|
193 |
-
# {"name": "Redshift Diffusion", "url": "nitrosocke/redshift-diffusion"},
|
194 |
-
]
|
195 |
-
|
196 |
current_model = models[0]
|
197 |
|
198 |
-
|
199 |
-
import gradio as grad, random, re
|
200 |
-
|
201 |
-
|
202 |
gpt2_pipe = pipeline('text-generation', model='Gustavosta/MagicPrompt-Stable-Diffusion', tokenizer='gpt2')
|
203 |
with open("ideas.txt", "r") as f:
|
204 |
line = f.readlines()
|
205 |
|
206 |
-
|
207 |
def generate(starting_text):
|
208 |
seed = random.randint(100, 1000000)
|
209 |
set_seed(seed)
|
210 |
-
|
211 |
if starting_text == "":
|
212 |
starting_text: str = line[random.randrange(0, len(line))].replace("\n", "").lower().capitalize()
|
213 |
starting_text: str = re.sub(r"[,:\-β.!;?_]", '', starting_text)
|
214 |
-
|
215 |
response = gpt2_pipe(starting_text, max_length=(len(starting_text) + random.randint(60, 90)), num_return_sequences=4)
|
216 |
response_list = []
|
217 |
for x in response:
|
218 |
resp = x['generated_text'].strip()
|
219 |
if resp != starting_text and len(resp) > (len(starting_text) + 4) and resp.endswith((":", "-", "β")) is False:
|
220 |
response_list.append(resp+'\n')
|
221 |
-
|
222 |
response_end = "\n".join(response_list)
|
223 |
response_end = re.sub('[^ ]+\.[^ ]+','', response_end)
|
224 |
response_end = response_end.replace("<", "").replace(">", "")
|
225 |
-
|
226 |
if response_end != "":
|
227 |
return response_end
|
228 |
|
229 |
-
|
230 |
-
# txt = grad.Textbox(lines=1, label="Initial Text", placeholder="English Text here")
|
231 |
-
# out = grad.Textbox(lines=4, label="Generated Prompts")
|
232 |
-
|
233 |
examples = []
|
234 |
for x in range(8):
|
235 |
examples.append(line[random.randrange(0, len(line))].replace("\n", "").lower().capitalize())
|
236 |
-
|
237 |
-
# title = "Stable Diffusion Prompt Generator"
|
238 |
-
# description = 'This is a demo of the model series: "MagicPrompt", in this case, aimed at: "Stable Diffusion". To use it, simply submit your text or click on one of the examples. To learn more about the model, [click here](https://huggingface.co/Gustavosta/MagicPrompt-Stable-Diffusion).<br>'
|
239 |
|
240 |
# text_gen = gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
|
241 |
|
242 |
-
models2 = []
|
243 |
for model in models:
|
244 |
model_url = f"models/{model['url']}"
|
245 |
loaded_model = gr.Interface.load(model_url, live=True, preprocess=True)
|
@@ -247,13 +46,6 @@ for model in models:
|
|
247 |
|
248 |
|
249 |
def text_it(inputs,text_gen=generate):
|
250 |
-
# grad.Interface(fn=generate,
|
251 |
-
# inputs=inputs,
|
252 |
-
# outputs=outputs,
|
253 |
-
# examples=examples,
|
254 |
-
# allow_flagging='never',
|
255 |
-
# cache_examples=False,
|
256 |
-
# theme="default").launch(enable_queue=True, debug=True)
|
257 |
return text_gen(inputs)
|
258 |
|
259 |
|
@@ -269,10 +61,7 @@ def send_it(inputs, model_choice):
|
|
269 |
|
270 |
|
271 |
with gr.Blocks() as myface:
|
272 |
-
gr.HTML(
|
273 |
-
|
274 |
-
)
|
275 |
-
|
276 |
with gr.Row():
|
277 |
with gr.Row():
|
278 |
input_text = gr.Textbox(label="Prompt idea", lines=1)
|
@@ -315,25 +104,25 @@ with gr.Blocks() as myface:
|
|
315 |
|
316 |
model_name1.change(set_model, inputs=model_name1, outputs=[output1, output2, output3, output4, output5, output6, output7, output8, output9])
|
317 |
|
318 |
-
run.click(send_it, inputs=[magic1, model_name1], outputs=[output1])
|
319 |
-
run.click(send_it, inputs=[magic2, model_name1], outputs=[output2])
|
320 |
-
run.click(send_it, inputs=[magic3, model_name1], outputs=[output3])
|
321 |
-
run.click(send_it, inputs=[magic4, model_name1], outputs=[output4])
|
322 |
-
run.click(send_it, inputs=[magic5, model_name1], outputs=[output5])
|
323 |
-
run.click(send_it, inputs=[magic6, model_name1], outputs=[output6])
|
324 |
-
run.click(send_it, inputs=[magic7, model_name1], outputs=[output7])
|
325 |
-
run.click(send_it, inputs=[magic8, model_name1], outputs=[output8])
|
326 |
-
run.click(send_it, inputs=[magic9, model_name1], outputs=[output9])
|
327 |
-
|
328 |
-
see_prompts.click(text_it, inputs=[input_text], outputs=[magic1])
|
329 |
-
see_prompts.click(text_it, inputs=[input_text], outputs=[magic2])
|
330 |
-
see_prompts.click(text_it, inputs=[input_text], outputs=[magic3])
|
331 |
-
see_prompts.click(text_it, inputs=[input_text], outputs=[magic4])
|
332 |
-
see_prompts.click(text_it, inputs=[input_text], outputs=[magic5])
|
333 |
-
see_prompts.click(text_it, inputs=[input_text], outputs=[magic6])
|
334 |
-
see_prompts.click(text_it, inputs=[input_text], outputs=[magic7])
|
335 |
-
see_prompts.click(text_it, inputs=[input_text], outputs=[magic8])
|
336 |
-
see_prompts.click(text_it, inputs=[input_text], outputs=[magic9])
|
337 |
-
|
338 |
-
myface.queue(concurrency_count=
|
339 |
-
myface.launch(inline=True, show_api=False, max_threads=
|
|
|
1 |
import gradio as gr
|
2 |
+
import os, pandas as pd
|
3 |
+
from transformers import pipeline, set_seed
|
4 |
+
import random, re
|
5 |
import sys
|
6 |
from pathlib import Path
|
7 |
|
8 |
+
# read models from csv and init
|
9 |
+
models = [_ for _ in pd.read_csv('models.csv').iterrows()]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
current_model = models[0]
|
11 |
|
12 |
+
# pipeline and core fncn for prompt generation
|
|
|
|
|
|
|
13 |
gpt2_pipe = pipeline('text-generation', model='Gustavosta/MagicPrompt-Stable-Diffusion', tokenizer='gpt2')
|
14 |
with open("ideas.txt", "r") as f:
|
15 |
line = f.readlines()
|
16 |
|
|
|
17 |
def generate(starting_text):
|
18 |
seed = random.randint(100, 1000000)
|
19 |
set_seed(seed)
|
|
|
20 |
if starting_text == "":
|
21 |
starting_text: str = line[random.randrange(0, len(line))].replace("\n", "").lower().capitalize()
|
22 |
starting_text: str = re.sub(r"[,:\-β.!;?_]", '', starting_text)
|
|
|
23 |
response = gpt2_pipe(starting_text, max_length=(len(starting_text) + random.randint(60, 90)), num_return_sequences=4)
|
24 |
response_list = []
|
25 |
for x in response:
|
26 |
resp = x['generated_text'].strip()
|
27 |
if resp != starting_text and len(resp) > (len(starting_text) + 4) and resp.endswith((":", "-", "β")) is False:
|
28 |
response_list.append(resp+'\n')
|
|
|
29 |
response_end = "\n".join(response_list)
|
30 |
response_end = re.sub('[^ ]+\.[^ ]+','', response_end)
|
31 |
response_end = response_end.replace("<", "").replace(">", "")
|
|
|
32 |
if response_end != "":
|
33 |
return response_end
|
34 |
|
|
|
|
|
|
|
|
|
35 |
examples = []
|
36 |
for x in range(8):
|
37 |
examples.append(line[random.randrange(0, len(line))].replace("\n", "").lower().capitalize())
|
|
|
|
|
|
|
38 |
|
39 |
# text_gen = gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
|
40 |
|
41 |
+
models2 = [] #can improve this, no need to load and keep all models in memory, increases cpu usage + latency
|
42 |
for model in models:
|
43 |
model_url = f"models/{model['url']}"
|
44 |
loaded_model = gr.Interface.load(model_url, live=True, preprocess=True)
|
|
|
46 |
|
47 |
|
48 |
def text_it(inputs,text_gen=generate):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
return text_gen(inputs)
|
50 |
|
51 |
|
|
|
61 |
|
62 |
|
63 |
with gr.Blocks() as myface:
|
64 |
+
gr.HTML()
|
|
|
|
|
|
|
65 |
with gr.Row():
|
66 |
with gr.Row():
|
67 |
input_text = gr.Textbox(label="Prompt idea", lines=1)
|
|
|
104 |
|
105 |
model_name1.change(set_model, inputs=model_name1, outputs=[output1, output2, output3, output4, output5, output6, output7, output8, output9])
|
106 |
|
107 |
+
run.click(send_it, inputs=[magic1, model_name1], outputs=[output1], batch=True, max_batch_size=32)
|
108 |
+
run.click(send_it, inputs=[magic2, model_name1], outputs=[output2], batch=True, max_batch_size=32)
|
109 |
+
run.click(send_it, inputs=[magic3, model_name1], outputs=[output3], batch=True, max_batch_size=32)
|
110 |
+
run.click(send_it, inputs=[magic4, model_name1], outputs=[output4], batch=True, max_batch_size=32)
|
111 |
+
run.click(send_it, inputs=[magic5, model_name1], outputs=[output5], batch=True, max_batch_size=32)
|
112 |
+
run.click(send_it, inputs=[magic6, model_name1], outputs=[output6], batch=True, max_batch_size=32)
|
113 |
+
run.click(send_it, inputs=[magic7, model_name1], outputs=[output7], batch=True, max_batch_size=32)
|
114 |
+
run.click(send_it, inputs=[magic8, model_name1], outputs=[output8], batch=True, max_batch_size=32)
|
115 |
+
run.click(send_it, inputs=[magic9, model_name1], outputs=[output9], batch=True, max_batch_size=32)
|
116 |
+
|
117 |
+
see_prompts.click(text_it, inputs=[input_text], outputs=[magic1], batch=True, max_batch_size=32)
|
118 |
+
see_prompts.click(text_it, inputs=[input_text], outputs=[magic2], batch=True, max_batch_size=32)
|
119 |
+
see_prompts.click(text_it, inputs=[input_text], outputs=[magic3], batch=True, max_batch_size=32)
|
120 |
+
see_prompts.click(text_it, inputs=[input_text], outputs=[magic4], batch=True, max_batch_size=32)
|
121 |
+
see_prompts.click(text_it, inputs=[input_text], outputs=[magic5], batch=True, max_batch_size=32)
|
122 |
+
see_prompts.click(text_it, inputs=[input_text], outputs=[magic6], batch=True, max_batch_size=32)
|
123 |
+
see_prompts.click(text_it, inputs=[input_text], outputs=[magic7], batch=True, max_batch_size=32)
|
124 |
+
see_prompts.click(text_it, inputs=[input_text], outputs=[magic8], batch=True, max_batch_size=32)
|
125 |
+
see_prompts.click(text_it, inputs=[input_text], outputs=[magic9], batch=True, max_batch_size=32)
|
126 |
+
|
127 |
+
myface.queue(concurrency_count=64)
|
128 |
+
myface.launch(inline=True, show_api=False, max_threads=64)
|