Diffusion-Flood / flood.py
Omnibus's picture
Update flood.py
ce6f474
import os
import cv2
import sys
import time
import uuid as bandaid
import tarfile
import gradio as gr
from pathlib import Path
from PIL import Image
models = [
"johnslegers/epic-diffusion-v1.1",
"andite/anything-v4.0",
"runwayml/stable-diffusion-v1-5",
"claudfuen/photorealistic-fuen-v1",
"naclbit/trinart_stable_diffusion_v2",
"nitrosocke/Arcane-Diffusion",
"nitrosocke/archer-diffusion",
"nitrosocke/elden-ring-diffusion",
"nitrosocke/redshift-diffusion",
"nitrosocke/spider-verse-diffusion",
"nitrosocke/mo-di-diffusion",
"nitrosocke/classic-anim-diffusion",
"dreamlike-art/dreamlike-diffusion-1.0",
"dreamlike-art/dreamlike-photoreal-2.0",
"wavymulder/wavyfusion",
"wavymulder/Analog-Diffusion",
"prompthero/midjourney-v4-diffusion",
"prompthero/openjourney",
"dallinmackay/Van-Gogh-diffusion",
"hakurei/waifu-diffusion",
"DGSpitzer/Cyberpunk-Anime-Diffusion",
"Fictiverse/Stable_Diffusion_BalloonArt_Model",
"dallinmackay/Tron-Legacy-diffusion",
"AstraliteHeart/pony-diffusion",
"nousr/robo-diffusion",
"CompVis/stable-diffusion-v1-4",
]
current_model = models[0]
text_gen1=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
text_gen2=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
text_gen3=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
text_gen4=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
text_gen5=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
text_gen6=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
text_gen7=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
text_gen8=gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
models2=[
gr.Interface.load(f"models/{models[0]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[1]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[2]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[3]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[4]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[5]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[6]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[7]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[8]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[9]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[10]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[11]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[12]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[13]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[14]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[15]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[16]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[17]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[18]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[19]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[20]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[21]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[22]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[23]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[24]}",live=True,preprocess=True),
gr.Interface.load(f"models/{models[25]}",live=True,preprocess=True),
]
def text_it(inputs,text_gen1=text_gen1):
go_t1=text_gen1(inputs)
return(go_t1)
def set_model(current_model):
current_model = models[current_model]
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}")),
def prime_the_thing():
#timestr = time.strftime("%Y%m%d-%H%M%S")
timestr = bandaid.uuid4()
if not os.path.exists(f'./frames{timestr}'):
os.mkdir(f'./frames{timestr}')
frame_box=[]
frame_file_box=[]
frame_tar_box=[]
go=1
return timestr, go, frame_box, frame_file_box, frame_tar_box
def go_fn():
num=1
return num
def the_thing(inputs,input_rand, model_choice,num,top_num,timestr, frame_box, frame_file_box, frame_tar_box):
if num != 0:
if int(num) <= int(top_num) and int(num) <= 20:
#proc1=
inputs=f"{inputs}{input_rand}"
proc1=models2[model_choice]
output=proc1(inputs)
#output_pro=Image.open(output)
output_pro=cv2.imread(output)
cv2.imwrite(f"./frames{timestr}/frame-{timestr}-{num}.png",output_pro)
frame_file_box.append(Path(f"./frames{timestr}/frame-{timestr}-{num}.png"))
frame_box.append(output)
input_rand=f"{input_rand} "
if int(num) < int(top_num):
num=int(num)+1
elif int(num)==int(top_num):
#frame_tar_box=[]
with tarfile.open(f'frames{timestr}.tar.gz','w:gz') as tar:
tar.add(f"./frames{timestr}",arcname=os.path.basename(f"./frames{timestr}"))
frame_tar_box.append(Path(f'frames{timestr}.tar.gz'))
else:
pass
else:
num=0
pass
else:
print("ending")
return frame_box,frame_file_box,frame_tar_box,num,input_rand,frame_box,frame_file_box,frame_tar_box
css=""""""
css="""
.max-h-\[55vh\]{
max-height:10vh;!important;
}
"""
with gr.Blocks(css=css) as myface:
frame_box = gr.State([])
frame_file_box = gr.State([])
frame_tar_box = gr.State([])
with gr.Row():
with gr.Tab("Title"):
gr.HTML(""" <title>Diffusion Flood</title>
<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;">
<h1>Diffusion Flood</h1></div>
<br>
<div style="text-align:center;font-size:30px;margin-bottom:5px;"><h4>Grab a bucket!</h4></div>""")
with gr.Tab("Description"):
gr.HTML("""<div style="text-align:center;">
<h4>Developing...</h4>
<br><h4>Select how many image you would like returned</h4>
<h4>Enter your Prompt</h4>
<h4>Select a Model (some are fast, others are slow)</h4>
<h4>Send it!</h4>
</div>""")
with gr.Tab("Tools"):
with gr.Tab("View"):
with gr.Row():
with gr.Column(style="width=50%, height=70%"):
gr.Pil(label="Crop")
with gr.Column(style="width=50%, height=70%"):
gr.Pil(label="Crop")
with gr.Tab("Draw"):
with gr.Column(style="width=50%, height=70%"):
gr.Pil(label="Crop")
with gr.Column(style="width=50%, height=70%"):
gr.Pil(label="Draw")
gr.ImagePaint(label="Draw")
with gr.Tab("Text"):
with gr.Row():
with gr.Column(scale=50):
gr.Textbox(label="", lines=8, interactive=True)
with gr.Column(scale=50):
gr.Textbox(label="", lines=8, interactive=True)
with gr.Tab("Color Picker"):
with gr.Row():
with gr.Column(scale=50):
gr.ColorPicker(label="Color", interactive=True)
with gr.Column(scale=50):
gr.ImagePaint(label="Draw", interactive=True)
with gr.Tab("Style"):
style_switch=gr.Radio(["1", "2", "3"])
style_button=gr.Button("Load Style")
with gr.Row():
with gr.Column():
with gr.Row():
frame_num=gr.Textbox(label="Current",value=0,interactive=False)
time_box=gr.Textbox(label="Unique Bandaid", interactive=False)
frame_top=gr.Textbox(label="How many images? Max 20 Demo", value=10,interactive=True)
with gr.Row():
model_name1 = gr.Dropdown(show_label=False, choices=[m for m in models], type="index", value=current_model, interactive=True)
#magic_text=gr.Textbox(label="Magic Prompt",lines=3)
with gr.Column():
#use_short=gr.Button("Use Short Prompt")
#see_prompt=gr.Button("Generate Magic Prompt")
magic_text=gr.Textbox(label="Short Prompt",lines=1)
run=gr.Button("Send it!")
with gr.Tab("Bucket"):
with gr.Column():
with gr.Row():
with gr.Column():
frames=gr.Gallery(label="Bucket o' Frames", type="filepath").style(grid=10)
frame_files=gr.Files()
frame_tar=gr.Files()
with gr.Row():
batch_bot1=gr.Textbox(label="BB1")
start_frame1=gr.Textbox(label="Start Frame")
rand_box=gr.Textbox(value="",visible=False)
go_box=gr.Textbox(value=0,visible=False)
def short_prompt(inputs):
return(inputs)
run.click(prime_the_thing, inputs=[], outputs=[time_box,frame_num, frame_box, frame_file_box, frame_tar_box])
go_box.change(go_fn,inputs=[],outputs=[frame_num])
frame_num.change(the_thing, inputs=[magic_text,rand_box, model_name1, frame_num, frame_top,time_box, frame_box, frame_file_box, frame_tar_box], outputs=[frames,frame_files,frame_tar,frame_num,rand_box, frame_box, frame_file_box, frame_tar_box])
#use_short.click(short_prompt,inputs=[input_text],outputs=magic_text)
#see_prompt.click(text_it,inputs=[input_text],outputs=[magic_text])
#model_name1.change(set_model,inputs=model_name1,outputs=[output1,output2,output3,output4,output5,output6,output7,output8])
myface.queue(concurrency_count=10)
myface.launch(enable_queue=True, inline=True, max_threads=10, show_api=False)