Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
models = [
|
| 7 |
+
{"name": "Stable Diffusion 2", "url": "stabilityai/stable-diffusion-2-1"},
|
| 8 |
+
{"name": "stability AI", "url": "stabilityai/stable-diffusion-2-1-base"},
|
| 9 |
+
{"name": "XL-Refiner-1.0", "url": "stabilityai/stable-diffusion-xl-refiner-1.0"},
|
| 10 |
+
{"name": "Future Diffusion", "url": "nitrosocke/Future-Diffusion"},
|
| 11 |
+
{"name": "JWST Deep Space Diffusion", "url": "dallinmackay/JWST-Deep-Space-diffusion"},
|
| 12 |
+
{"name": "Robo Diffusion 3 Base", "url": "nousr/robo-diffusion-2-base"},
|
| 13 |
+
{"name": "Robo Diffusion", "url": "nousr/robo-diffusion"},
|
| 14 |
+
{"name": "Tron Legacy Diffusion", "url": "dallinmackay/Tron-Legacy-diffusion"},
|
| 15 |
+
]
|
| 16 |
+
|
| 17 |
+
current_model = models[0]
|
| 18 |
+
|
| 19 |
+
text_gen = gr.Interface.load("spaces/daspartho/prompt-extend")
|
| 20 |
+
|
| 21 |
+
models2 = []
|
| 22 |
+
for model in models:
|
| 23 |
+
model_url = f"models/{model['url']}"
|
| 24 |
+
loaded_model = gr.Interface.load(model_url, live=True, preprocess=True)
|
| 25 |
+
models2.append(loaded_model)
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def text_it(inputs, text_gen=text_gen):
|
| 29 |
+
return text_gen(inputs)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def set_model(current_model_index):
|
| 33 |
+
global current_model
|
| 34 |
+
current_model = models[current_model_index]
|
| 35 |
+
return gr.update(value=f"{current_model['name']}")
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def send_it(inputs, model_choice):
|
| 39 |
+
proc = models2[model_choice]
|
| 40 |
+
return proc(inputs)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
with gr.Blocks() as myface:
|
| 44 |
+
gr.HTML(
|
| 45 |
+
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
with gr.Row():
|
| 49 |
+
with gr.Row():
|
| 50 |
+
input_text = gr.Textbox(label="Prompt idea", placeholder="", lines=1)
|
| 51 |
+
# Model selection dropdown
|
| 52 |
+
model_name1 = gr.Dropdown(
|
| 53 |
+
label="Choose Model",
|
| 54 |
+
choices=[m["name"] for m in models],
|
| 55 |
+
type="index",
|
| 56 |
+
value=current_model["name"],
|
| 57 |
+
interactive=True,
|
| 58 |
+
)
|
| 59 |
+
with gr.Row():
|
| 60 |
+
see_prompts = gr.Button("Generate Prompts")
|
| 61 |
+
run = gr.Button("Generate Images", variant="primary")
|
| 62 |
+
|
| 63 |
+
with gr.Row():
|
| 64 |
+
output1 = gr.Image(label="")
|
| 65 |
+
output2 = gr.Image(label="")
|
| 66 |
+
output3 = gr.Image(label="")
|
| 67 |
+
with gr.Row():
|
| 68 |
+
magic1 = gr.Textbox(label="Generated Prompt", lines=2)
|
| 69 |
+
magic2 = gr.Textbox(label="Generated Prompt", lines=2)
|
| 70 |
+
magic3 = gr.Textbox(label="Generated Prompt", lines=2)
|
| 71 |
+
with gr.Row():
|
| 72 |
+
output4 = gr.Image(label="")
|
| 73 |
+
output5 = gr.Image(label="")
|
| 74 |
+
output6 = gr.Image(label="")
|
| 75 |
+
with gr.Row():
|
| 76 |
+
magic4 = gr.Textbox(label="Generated Prompt", lines=2)
|
| 77 |
+
magic5 = gr.Textbox(label="Generated Prompt", lines=2)
|
| 78 |
+
magic6 = gr.Textbox(label="Generated Prompt", lines=2)
|
| 79 |
+
|
| 80 |
+
model_name1.change(set_model, inputs=model_name1, outputs=[output1, output2, output3, output4, output5, output6])
|
| 81 |
+
|
| 82 |
+
run.click(send_it, inputs=[magic1, model_name1], outputs=[output1])
|
| 83 |
+
run.click(send_it, inputs=[magic2, model_name1], outputs=[output2])
|
| 84 |
+
run.click(send_it, inputs=[magic3, model_name1], outputs=[output3])
|
| 85 |
+
run.click(send_it, inputs=[magic4, model_name1], outputs=[output4])
|
| 86 |
+
run.click(send_it, inputs=[magic5, model_name1], outputs=[output5])
|
| 87 |
+
run.click(send_it, inputs=[magic6, model_name1], outputs=[output6])
|
| 88 |
+
|
| 89 |
+
see_prompts.click(text_it, inputs=[input_text], outputs=[magic1])
|
| 90 |
+
see_prompts.click(text_it, inputs=[input_text], outputs=[magic2])
|
| 91 |
+
see_prompts.click(text_it, inputs=[input_text], outputs=[magic3])
|
| 92 |
+
see_prompts.click(text_it, inputs=[input_text], outputs=[magic4])
|
| 93 |
+
see_prompts.click(text_it, inputs=[input_text], outputs=[magic5])
|
| 94 |
+
see_prompts.click(text_it, inputs=[input_text], outputs=[magic6])
|
| 95 |
+
|
| 96 |
+
myface.queue(concurrency_count=200)
|
| 97 |
+
myface.launch(inline=True, show_api=True, max_threads=400)
|
| 98 |
+
|
| 99 |
+
demo.launch()
|