Top-20-Models / app.py
Dao3's picture
Update app.py
dc024bc
import gradio as gr
import os
import sys
from pathlib import Path
import time
models =[
"",
"CompVis/stable-diffusion-v1-4",
"runwayml/stable-diffusion-v1-5",
"prompthero/openjourney",
"stabilityai/stable-diffusion-2-1",
"stabilityai/stable-diffusion-2-1-base",
"andite/anything-v4.0",
"Linaqruf/anything-v3.0",
"eimiss/EimisAnimeDiffusion_1.0v",
"nitrosocke/Nitro-Diffusion",
"wavymulder/portraitplus",
"22h/vintedois-diffusion-v0-1",
"dreamlike-art/dreamlike-photoreal-2.0",
"dreamlike-art/dreamlike-diffusion-1.0",
"wavymulder/Analog-Diffusion",
"nitrosocke/redshift-diffusion",
"claudfuen/photorealistic-fuen-v1",
"prompthero/openjourney-v2",
"johnslegers/epic-diffusion",
"nitrosocke/Arcane-Diffusion",
"darkstorm2150/Protogen_x5.8_Official_Release",
]
model_1=models[1]
model_2=models[2]
model_3=models[3]
model_4=models[4]
model_5=models[5]
model_6=models[6]
model_7=models[7]
model_8=models[8]
model_9=models[9]
model_10=models[10]
model_11=models[11]
model_12=models[12]
model_13=models[13]
model_14=models[14]
model_15=models[15]
model_16=models[16]
model_17=models[17]
model_18=models[18]
model_19=models[19]
model_20=models[20]
text_gen=gr.Interface.load("spaces/Dao3/MagicPrompt-Stable-Diffusion_link",live=True, preprocess=True)
proc1=gr.Interface.load(f"models/{model_1}",live=False,preprocess=True, postprocess=False)
proc2=gr.Interface.load(f"models/{model_2}",live=False,preprocess=True, postprocess=False)
proc3=gr.Interface.load(f"models/{model_3}",live=False,preprocess=True, postprocess=False)
proc4=gr.Interface.load(f"models/{model_4}",live=False,preprocess=True, postprocess=False)
proc5=gr.Interface.load(f"models/{model_5}",live=False,preprocess=True, postprocess=False)
proc6=gr.Interface.load(f"models/{model_6}",live=False,preprocess=True, postprocess=False)
proc7=gr.Interface.load(f"models/{model_7}",live=False,preprocess=True, postprocess=False)
proc8=gr.Interface.load(f"models/{model_8}",live=False,preprocess=True, postprocess=False)
proc9=gr.Interface.load(f"models/{model_9}",live=False,preprocess=True, postprocess=False)
proc10=gr.Interface.load(f"models/{model_10}",live=False,preprocess=True, postprocess=False)
proc11=gr.Interface.load(f"models/{model_11}",live=False,preprocess=True, postprocess=False)
proc12=gr.Interface.load(f"models/{model_12}",live=False,preprocess=True, postprocess=False)
proc13=gr.Interface.load(f"models/{model_13}",live=False,preprocess=True, postprocess=False)
proc14=gr.Interface.load(f"models/{model_14}",live=False,preprocess=True, postprocess=False)
proc15=gr.Interface.load(f"models/{model_15}",live=False,preprocess=True, postprocess=False)
proc16=gr.Interface.load(f"models/{model_16}",live=False,preprocess=True, postprocess=False)
proc17=gr.Interface.load(f"models/{model_17}",live=False,preprocess=True, postprocess=False)
proc18=gr.Interface.load(f"models/{model_18}",live=False,preprocess=True, postprocess=False)
proc19=gr.Interface.load(f"models/{model_19}",live=False,preprocess=True, postprocess=False)
proc20=gr.Interface.load(f"models/{model_20}",live=False,preprocess=True, postprocess=False)
def get_prompts(prompt_text):
return text_gen(prompt_text)
def send_it1(inputs,proc1=proc1):
output1=proc1(inputs)
return(output1)
def send_it2(inputs,proc2=proc2):
output2=proc2(inputs)
return(output2)
def send_it3(inputs,proc3=proc3):
output3=proc3(inputs)
return(output3)
def send_it4(inputs,proc4=proc4):
output4=proc4(inputs)
return(output4)
def send_it5(inputs,proc5=proc5):
output5=proc5(inputs)
return(output5)
def send_it6(inputs,proc6=proc6):
output6=proc6(inputs)
return(output6)
def send_it7(inputs,proc7=proc7):
output7=proc7(inputs)
return(output7)
def send_it8(inputs,proc8=proc8):
output8=proc8(inputs)
return(output8)
def send_it9(inputs,proc9=proc9):
output9=proc9(inputs)
return(output9)
def send_it10(inputs,proc10=proc10):
output10=proc10(inputs)
return(output10)
def send_it11(inputs,proc11=proc11):
output11=proc11(inputs)
return(output11)
def send_it12(inputs,proc12=proc12):
output12=proc12(inputs)
return(output12)
def send_it13(inputs,proc13=proc13):
output13=proc13(inputs)
return(output13)
def send_it14(inputs,proc14=proc14):
output14=proc14(inputs)
return(output14)
def send_it15(inputs,proc15=proc15):
output15=proc15(inputs)
return(output15)
def send_it16(inputs,proc16=proc16):
output16=proc16(inputs)
return(output16)
def send_it17(inputs,proc17=proc17):
output17=proc17(inputs)
return(output17)
def send_it18(inputs,proc18=proc18):
output18=proc18(inputs)
return(output18)
def send_it19(inputs,proc19=proc19):
output19=proc19(inputs)
return(output19)
def send_it20(inputs,proc20=proc20):
output20=proc20(inputs)
return(output20)
with gr.Blocks(css="cake.css") as myface:
gr.HTML("""<head><meta http-equiv="refresh" content="600"></head>""")
with gr.Column():
gr.HTML("""<title>SD的二十个最流行模型</title>""")
gr.Markdown("""<center><h1>20个SD模型</h1><center>""")
gr.Markdown("""<center><h4>一次生成20张不同风格的图</h4><center>""")
with gr.Accordion("使用说明",open=False):
with gr.Tab("Description"):
gr.Markdown("""<center>
<h4>在第一个输入框内填写你想画的内容,然后点击"完善"按钮,第二个输入框会自动出现经过完善后的提示词。然后点击"开始",下面的20个模型就开始为你疯狂了~<br>
<br>
部分模型的图像不出现的话,重新点击"开始"按钮即可
<br>
间隔十分钟后模型会生成新的图像
<br>
我们不对最终生成的内容负责,权责自负哦~
</h4></center>""")
with gr.Tab("魔改一下"):
gr.HTML("""<div style="text-align:Left;">
<h4>克隆一个你自己的:<br><br>
新建app.py 文件,把下面代码复制黏贴进去<br><br>
import gradio as gr<br>
max_d=gr.Interface.load("spaces/Dao3/Top-20-Models")<br>
max_d.launch()<br>
</h4></div>""")
with gr.Tab("致谢"):
with gr.Row():
with gr.Column(style="text-align:left;"):
gr.HTML("""
<div style="vertical-align:center">
<br>
<p>提示词优化方法来自:
<p><a href="https://huggingface.co/spaces/Gustavosta/MagicPrompt-Stable-Diffusion">Magic Prompt Stable Diffusion</a></p>
<p><a href="https://huggingface.co/spaces/huggingface-projects/magic-diffusion">Magic Diffusion</a></p>
</div>
""")
with gr.Column(style="text-align:left;"):
gr.HTML(f"""
<div style="vertical-align:center">
<br>
<p>模型来自:<br>
<a href="https://huggingface.co/{models[1]}">{models[1]}</a><br>
<a href="https://huggingface.co/{models[2]}">{models[2]}</a><br>
<a href="https://huggingface.co/{models[3]}">{models[3]}</a><br>
<a href="https://huggingface.co/{models[4]}">{models[4]}</a><br>
<a href="https://huggingface.co/{models[5]}">{models[5]}</a><br>
<a href="https://huggingface.co/{models[6]}">{models[6]}</a><br>
<a href="https://huggingface.co/{models[7]}">{models[7]}</a><br>
<a href="https://huggingface.co/{models[8]}">{models[8]}</a><br>
<a href="https://huggingface.co/{models[9]}">{models[9]}</a><br>
<a href="https://huggingface.co/{models[10]}">{models[10]}</a><br>
<a href="https://huggingface.co/{models[11]}">{models[11]}</a><br>
<a href="https://huggingface.co/{models[12]}">{models[12]}</a><br>
<a href="https://huggingface.co/{models[13]}">{models[13]}</a><br>
<a href="https://huggingface.co/{models[14]}">{models[14]}</a><br>
<a href="https://huggingface.co/{models[15]}">{models[15]}</a><br>
<a href="https://huggingface.co/{models[16]}">{models[16]}</a><br>
<a href="https://huggingface.co/{models[17]}">{models[17]}</a><br>
<a href="https://huggingface.co/{models[18]}">{models[18]}</a><br>
<a href="https://huggingface.co/{models[19]}">{models[19]}</a><br>
<a href="https://huggingface.co/{models[20]}">{models[20]}</a><br>
</p>
</div>
""")
with gr.Tab("工具"):
with gr.Tab("Draw"):
with gr.Row():
with gr.Column(style="width=50%"):
gr.Pil(label="Crop")
with gr.Column(style="width=50%"):
gr.Pil(label="Draw")
with gr.Tab("View"):
with gr.Row():
with gr.Column():
gr.Pil(label="Crop").style(style="height=500")
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("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.Box(visible=True) as timo:
with gr.Row():
with gr.Column():
input_text=gr.Textbox(label="你想画的内容(英文单词,如a cat, 加英文逗号效果更好;点完善按钮)")
prompt=gr.Textbox(label="完善后的提示词,出现后再点右边的开始按钮",visible=True)
with gr.Column():
see_prompts=gr.Button("完善")
with gr.Row():
run=gr.Button("开始")
clear_btn=gr.Button("清除")
with gr.Row():
output1=gr.Image(label=(f"{model_1}"),visible=True)
output2=gr.Image(label=(f"{model_2}"),visible=True)
output3=gr.Image(label=(f"{model_3}"),visible=True)
output4=gr.Image(label=(f"{model_4}"),visible=True)
with gr.Row():
output5=gr.Image(label=(f"{model_5}"),visible=True)
output6=gr.Image(label=(f"{model_6}"),visible=True)
output7=gr.Image(label=(f"{model_7}"),visible=True)
output8=gr.Image(label=(f"{model_8}"),visible=True)
with gr.Row():
output9=gr.Image(label=(f"{model_9}"),visible=True)
output10=gr.Image(label=(f"{model_10}"),visible=True)
output11=gr.Image(label=(f"{model_11}"),visible=True)
output12=gr.Image(label=(f"{model_12}"),visible=True)
with gr.Row():
output13=gr.Image(label=(f"{model_13}"),visible=True)
output14=gr.Image(label=(f"{model_14}"),visible=True)
output15=gr.Image(label=(f"{model_15}"),visible=True)
output16=gr.Image(label=(f"{model_16}"),visible=True)
with gr.Row():
output17=gr.Image(label=(f"{model_17}"),visible=True)
output18=gr.Image(label=(f"{model_18}"),visible=True)
output19=gr.Image(label=(f"{model_19}"),visible=True)
output20=gr.Image(label=(f"{model_20}"),visible=True)
with gr.Row(visible=False):
start_box=gr.Number(interactive=False)
end_box=gr.Number(interactive=False)
tog_box=gr.Textbox(value=0,interactive=False)
def clear_it(val):
if int(val) != 0:
val = 0
else:
val = 0
pass
return val
def sesh_end(cnt,t_stamp):
to = t_stamp + 60
et = time.time()
if et > to and t_stamp != 0:
d=gr.update(value=0)
tog=gr.update(value=1)
#print(f'to: {to} et: {et}')
else:
if cnt != 0:
d=gr.update(value=et)
else:
d=gr.update(value=0)
tog=gr.update(value=0)
#print (f'passing: to: {to} et: {et}')
pass
return d,tog
def sesh_start():
t = time.gmtime()
t_stamp = time.time()
current_time = time.strftime("%H:%M:%S", t)
return gr.update(value=t_stamp),gr.update(value=t_stamp),gr.update(value=0)
def clear_fn():
return None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None,None
start_box.change(sesh_end,[start_box,end_box],[start_box,tog_box],every=1,show_progress=False)
run.click(sesh_start,None,[start_box,end_box,tog_box])
run1=run.click(send_it1, inputs=[prompt], outputs=[output1])
run2=run.click(send_it2, inputs=[prompt], outputs=[output2])
run3=run.click(send_it3, inputs=[prompt], outputs=[output3])
run4=run.click(send_it4, inputs=[prompt], outputs=[output4])
run5=run.click(send_it5, inputs=[prompt], outputs=[output5])
run6=run.click(send_it6, inputs=[prompt], outputs=[output6])
run7=run.click(send_it7, inputs=[prompt], outputs=[output7])
run8=run.click(send_it8, inputs=[prompt], outputs=[output8])
run9=run.click(send_it9, inputs=[prompt], outputs=[output9])
run10=run.click(send_it10, inputs=[prompt], outputs=[output10])
run11=run.click(send_it11, inputs=[prompt], outputs=[output11])
run12=run.click(send_it12, inputs=[prompt], outputs=[output12])
run13=run.click(send_it13, inputs=[prompt], outputs=[output13])
run14=run.click(send_it14, inputs=[prompt], outputs=[output14])
run15=run.click(send_it15, inputs=[prompt], outputs=[output15])
run16=run.click(send_it16, inputs=[prompt], outputs=[output16])
run17=run.click(send_it17, inputs=[prompt], outputs=[output17])
run18=run.click(send_it18, inputs=[prompt], outputs=[output18])
run19=run.click(send_it19, inputs=[prompt], outputs=[output19])
run20=run.click(send_it20, inputs=[prompt], outputs=[output20])
prompt1=see_prompts.click(get_prompts, inputs=[input_text], outputs=[prompt],cancels=[run1,run2,run3,run4,run5,run6,run7,run8,run9,run10,run11,run12,run13,run14,run15,run16,run17,run18,run19,run20])
clear_btn.click(clear_fn, None,
[input_text,prompt,output1,output2,output3,output4,output5,output6,output7,output8,output9,output10,output11,output12,output13,output14,output15,output16,output17,output18,output19,output20],
cancels=[prompt1,run1,run2,run3,run4,run5,run6,run7,run8,run9,run10,run11,run12,run13,run14,run15,run16,run17,run18,run19,run20])
tog_box.change(clear_it,tog_box,tog_box,cancels=[run1,run2,run3,run4,run5,run6,run7,run8,run9,run10,run11,run12,run13,run14,run15,run16,run17,run18,run19,run20,prompt1])
myface.queue(concurrency_count=600,status_update_rate=1)
myface.launch(inline=True,show_api=False)