Omnibus commited on
Commit
5b6d22e
1 Parent(s): d63fe35

Create flood.py

Browse files
Files changed (1) hide show
  1. flood.py +240 -0
flood.py ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import cv2
3
+ import sys
4
+ import time
5
+ import uuid as bandaid
6
+ import tarfile
7
+ import gradio as gr
8
+ from pathlib import Path
9
+ from PIL import Image
10
+
11
+
12
+ models = [
13
+ "johnslegers/epic-diffusion-v1.1",
14
+ "andite/anything-v4.0",
15
+ "runwayml/stable-diffusion-v1-5",
16
+ "claudfuen/photorealistic-fuen-v1",
17
+ "naclbit/trinart_stable_diffusion_v2",
18
+ "nitrosocke/Arcane-Diffusion",
19
+ "nitrosocke/archer-diffusion",
20
+ "nitrosocke/elden-ring-diffusion",
21
+ "nitrosocke/redshift-diffusion",
22
+ "nitrosocke/spider-verse-diffusion",
23
+ "nitrosocke/mo-di-diffusion",
24
+ "nitrosocke/classic-anim-diffusion",
25
+ "dreamlike-art/dreamlike-diffusion-1.0",
26
+ "dreamlike-art/dreamlike-photoreal-2.0",
27
+ "wavymulder/wavyfusion",
28
+ "wavymulder/Analog-Diffusion",
29
+ "prompthero/midjourney-v4-diffusion",
30
+ "prompthero/openjourney",
31
+ "dallinmackay/Van-Gogh-diffusion",
32
+ "hakurei/waifu-diffusion",
33
+ "DGSpitzer/Cyberpunk-Anime-Diffusion",
34
+ "Fictiverse/Stable_Diffusion_BalloonArt_Model",
35
+ "dallinmackay/Tron-Legacy-diffusion",
36
+ "AstraliteHeart/pony-diffusion",
37
+ "nousr/robo-diffusion",
38
+ "CompVis/stable-diffusion-v1-4",
39
+
40
+ ]
41
+ current_model = models[0]
42
+
43
+ text_gen1=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
44
+ text_gen2=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
45
+ text_gen3=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
46
+ text_gen4=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
47
+ text_gen5=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
48
+ text_gen6=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
49
+ text_gen7=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
50
+ text_gen8=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
51
+
52
+ models2=[
53
+ gr.Interface.load(f"models/{models[0]}",live=True,preprocess=True),
54
+ gr.Interface.load(f"models/{models[1]}",live=True,preprocess=True),
55
+ gr.Interface.load(f"models/{models[2]}",live=True,preprocess=True),
56
+ gr.Interface.load(f"models/{models[3]}",live=True,preprocess=True),
57
+ gr.Interface.load(f"models/{models[4]}",live=True,preprocess=True),
58
+ gr.Interface.load(f"models/{models[5]}",live=True,preprocess=True),
59
+ gr.Interface.load(f"models/{models[6]}",live=True,preprocess=True),
60
+ gr.Interface.load(f"models/{models[7]}",live=True,preprocess=True),
61
+ gr.Interface.load(f"models/{models[8]}",live=True,preprocess=True),
62
+ gr.Interface.load(f"models/{models[9]}",live=True,preprocess=True),
63
+ gr.Interface.load(f"models/{models[10]}",live=True,preprocess=True),
64
+ gr.Interface.load(f"models/{models[11]}",live=True,preprocess=True),
65
+ gr.Interface.load(f"models/{models[12]}",live=True,preprocess=True),
66
+ gr.Interface.load(f"models/{models[13]}",live=True,preprocess=True),
67
+ gr.Interface.load(f"models/{models[14]}",live=True,preprocess=True),
68
+ gr.Interface.load(f"models/{models[15]}",live=True,preprocess=True),
69
+ gr.Interface.load(f"models/{models[16]}",live=True,preprocess=True),
70
+ gr.Interface.load(f"models/{models[17]}",live=True,preprocess=True),
71
+ gr.Interface.load(f"models/{models[18]}",live=True,preprocess=True),
72
+ gr.Interface.load(f"models/{models[19]}",live=True,preprocess=True),
73
+ gr.Interface.load(f"models/{models[20]}",live=True,preprocess=True),
74
+ gr.Interface.load(f"models/{models[21]}",live=True,preprocess=True),
75
+ gr.Interface.load(f"models/{models[22]}",live=True,preprocess=True),
76
+ gr.Interface.load(f"models/{models[23]}",live=True,preprocess=True),
77
+ gr.Interface.load(f"models/{models[24]}",live=True,preprocess=True),
78
+ gr.Interface.load(f"models/{models[25]}",live=True,preprocess=True),
79
+
80
+ ]
81
+
82
+
83
+ def text_it(inputs,text_gen1=text_gen1):
84
+ go_t1=text_gen1(inputs)
85
+ return(go_t1)
86
+
87
+ def set_model(current_model):
88
+ current_model = models[current_model]
89
+ return gr.update(label=(f"{current_model}")),gr.update(label=(f"{current_model}")),gr.update(label=(f"{current_model}")),gr.update(label=(f"{current_model}")),gr.update(label=(f"{current_model}")),gr.update(label=(f"{current_model}")),gr.update(label=(f"{current_model}")),gr.update(label=(f"{current_model}")),
90
+
91
+ def prime_the_thing():
92
+ #timestr = time.strftime("%Y%m%d-%H%M%S")
93
+ timestr = bandaid.uuid4()
94
+ if not os.path.exists(f'./frames{timestr}'):
95
+ os.mkdir(f'./frames{timestr}')
96
+ global frame_box
97
+ global frame_file_box
98
+ global frame_tar_box
99
+ frame_box=[]
100
+ frame_file_box=[]
101
+ frame_tar_box=[]
102
+ go=1
103
+ return timestr, go
104
+
105
+ def go_fn():
106
+ num=1
107
+ return num
108
+
109
+ def the_thing(inputs,input_rand, model_choice,num,top_num,timestr):
110
+ if num != 0:
111
+ if int(num) <= int(top_num):
112
+ #proc1=
113
+ inputs=f"{inputs}{input_rand}"
114
+ proc1=models2[model_choice]
115
+ output=proc1(inputs)
116
+ #output_pro=Image.open(output)
117
+ output_pro=cv2.imread(output)
118
+ cv2.imwrite(f"./frames{timestr}/frame-{num}.png",output_pro)
119
+ frame_file_box.append(Path(f"./frames{timestr}/frame-{num}.png"))
120
+ frame_box.append(output)
121
+ input_rand=f"{input_rand} "
122
+ if int(num) < int(top_num):
123
+ num=int(num)+1
124
+ elif int(num)==int(top_num):
125
+ #frame_tar_box=[]
126
+ with tarfile.open(f'frames{timestr}.tar.gz','w:gz') as tar:
127
+ tar.add(f"./frames{timestr}",arcname=os.path.basename(f"./frames{timestr}"))
128
+ frame_tar_box.append(Path(f'frames{timestr}.tar.gz'))
129
+ else:
130
+ pass
131
+ else:
132
+ num=0
133
+ pass
134
+
135
+ else:
136
+ print("ending")
137
+ return frame_box,frame_file_box,frame_tar_box,num,input_rand
138
+
139
+
140
+ css=""""""
141
+ css="""
142
+ .max-h-\[55vh\]{
143
+ max-height:10vh;!important;
144
+ }
145
+ """
146
+ with gr.Blocks(css=css) as myface:
147
+ with gr.Row():
148
+ with gr.Tab("Title"):
149
+ gr.HTML(""" <title>Diffusion Flood</title>
150
+ <div style="text-align: center;text-shadow:0px 0px 2px white,0px 0px 5px cornflowerblue;max-width:1500px;margin-top:5px;font-size:50px;height:50px;">
151
+ <h1>Diffusion Flood</h1></div>
152
+ <br>
153
+ <div style="text-align:center;font-size:30px;margin-bottom:5px;"><h4>Grab a bucket!</h4></div>""")
154
+ with gr.Tab("Description"):
155
+ gr.HTML("""<div style="text-align:center;">
156
+ <h4>Developing...</h4>
157
+ <br><h4>Select how many image you would like returned</h4>
158
+ <h4>Enter your Prompt</h4>
159
+ <h4>Select a Model (some are fast, others are slow)</h4>
160
+ <h4>Send it!</h4>
161
+ </div>""")
162
+
163
+ with gr.Tab("Tools"):
164
+ with gr.Tab("View"):
165
+ with gr.Row():
166
+ with gr.Column(style="width=50%, height=70%"):
167
+ gr.Pil(label="Crop")
168
+ with gr.Column(style="width=50%, height=70%"):
169
+ gr.Pil(label="Crop")
170
+ with gr.Tab("Draw"):
171
+ with gr.Column(style="width=50%, height=70%"):
172
+ gr.Pil(label="Crop")
173
+ with gr.Column(style="width=50%, height=70%"):
174
+ gr.Pil(label="Draw")
175
+ gr.ImagePaint(label="Draw")
176
+ with gr.Tab("Text"):
177
+ with gr.Row():
178
+ with gr.Column(scale=50):
179
+ gr.Textbox(label="", lines=8, interactive=True)
180
+ with gr.Column(scale=50):
181
+ gr.Textbox(label="", lines=8, interactive=True)
182
+ with gr.Tab("Color Picker"):
183
+ with gr.Row():
184
+ with gr.Column(scale=50):
185
+ gr.ColorPicker(label="Color", interactive=True)
186
+ with gr.Column(scale=50):
187
+ gr.ImagePaint(label="Draw", interactive=True)
188
+ with gr.Tab("Style"):
189
+ style_switch=gr.Radio(["1", "2", "3"])
190
+ style_button=gr.Button("Load Style")
191
+
192
+
193
+
194
+
195
+
196
+
197
+ with gr.Row():
198
+ with gr.Column():
199
+ with gr.Row():
200
+ frame_num=gr.Textbox(label="Current",value=0,interactive=False)
201
+ time_box=gr.Textbox(label="Time String", interactive=False)
202
+ frame_top=gr.Textbox(label="How many images?", value=10)
203
+ with gr.Row():
204
+ model_name1 = gr.Dropdown(show_label=False, choices=[m for m in models], type="index", value=current_model, interactive=True)
205
+ #magic_text=gr.Textbox(label="Magic Prompt",lines=3)
206
+ with gr.Column():
207
+ #use_short=gr.Button("Use Short Prompt")
208
+ #see_prompt=gr.Button("Generate Magic Prompt")
209
+ magic_text=gr.Textbox(label="Short Prompt",lines=1)
210
+ run=gr.Button("Send it!")
211
+
212
+ with gr.Tab("Bucket"):
213
+ with gr.Column():
214
+ with gr.Row():
215
+ with gr.Column():
216
+ frames=gr.Gallery(label="Bucket o' Frames", type="filepath").style(grid=10)
217
+ frame_files=gr.Files()
218
+ frame_tar=gr.Files()
219
+
220
+ with gr.Row():
221
+ batch_bot1=gr.Textbox(label="BB1")
222
+ start_frame1=gr.Textbox(label="Start Frame")
223
+
224
+
225
+
226
+ rand_box=gr.Textbox(value="",visible=False)
227
+ go_box=gr.Textbox(value=0,visible=False)
228
+ def short_prompt(inputs):
229
+ return(inputs)
230
+
231
+ run.click(prime_the_thing, inputs=[], outputs=[time_box,frame_num])
232
+ go_box.change(go_fn,inputs=[],outputs=[frame_num])
233
+ frame_num.change(the_thing, inputs=[magic_text,rand_box, model_name1, frame_num, frame_top,time_box], outputs=[frames,frame_files,frame_tar,frame_num,rand_box])
234
+ #use_short.click(short_prompt,inputs=[input_text],outputs=magic_text)
235
+ #see_prompt.click(text_it,inputs=[input_text],outputs=[magic_text])
236
+ #model_name1.change(set_model,inputs=model_name1,outputs=[output1,output2,output3,output4,output5,output6,output7,output8])
237
+
238
+
239
+ myface.queue(concurrency_count=200)
240
+ myface.launch(enable_queue=True, inline=True, max_threads=200)