Spaces:
Runtime error
Runtime error
Brian Watson
commited on
Commit
·
acfd51b
1
Parent(s):
ba3d642
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,10 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
models = [
|
| 4 |
-
{"name": "Claudfuen 1", "url": "
|
| 5 |
{"name": "Deliberate", "url": "Masagin/Deliberate"},
|
| 6 |
{"name": "Seek Art Mega", "url": "coreco/seek.art_MEGA"},
|
| 7 |
{"name": "Realistic Vision 1.4", "url": "SG161222/Realistic_Vision_V1.4"},
|
|
@@ -34,198 +37,85 @@ def send_it(inputs, model_choice):
|
|
| 34 |
return proc(inputs)
|
| 35 |
|
| 36 |
|
| 37 |
-
css = """
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
left: 0;
|
| 58 |
-
opacity: 0;
|
| 59 |
-
pointer-events: none;
|
| 60 |
-
}
|
| 61 |
-
</style>
|
| 62 |
"""
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
current_model = models[0]
|
| 126 |
-
|
| 127 |
-
text_gen = gr.Interface.load("spaces/Omnibus/MagicPrompt-Stable-Diffusion_link")
|
| 128 |
-
|
| 129 |
-
models2 = []
|
| 130 |
-
for model in models:
|
| 131 |
-
model_url = f"models/{model['url']}"
|
| 132 |
-
loaded_model = gr.Interface.load(model_url, live=True, preprocess=True)
|
| 133 |
-
models2.append(loaded_model)
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
def text_it(inputs, text_gen=text_gen):
|
| 137 |
-
return text_gen(inputs)
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
def set_model(current_model_index):
|
| 141 |
-
global current_model
|
| 142 |
-
current_model = models[current_model_index]
|
| 143 |
-
return gr.outputs.Label(f"Current Model: {current_model['name']}")
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
def send_it(inputs, model_choice):
|
| 147 |
-
proc = models2[model_choice]
|
| 148 |
-
return proc(inputs)
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
css = """
|
| 152 |
-
<style>
|
| 153 |
-
.searchable-dropdown {
|
| 154 |
-
position: relative;
|
| 155 |
-
}
|
| 156 |
-
|
| 157 |
-
.searchable-dropdown input {
|
| 158 |
-
width: 100%;
|
| 159 |
-
padding: 0.5rem;
|
| 160 |
-
border-radius: 5px;
|
| 161 |
-
border: 1px solid #ccc;
|
| 162 |
-
}
|
| 163 |
-
|
| 164 |
-
.searchable-dropdown select {
|
| 165 |
-
width: 100%;
|
| 166 |
-
padding: 0.5rem;
|
| 167 |
-
border-radius: 5px;
|
| 168 |
-
border: 1px solid #ccc;
|
| 169 |
-
position: absolute;
|
| 170 |
-
top: 0;
|
| 171 |
-
left: 0;
|
| 172 |
-
opacity: 0;
|
| 173 |
-
pointer-events: none;
|
| 174 |
-
}
|
| 175 |
-
</style>
|
| 176 |
-
"""
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
def make_dropdown_searchable(dropdown_id):
|
| 180 |
-
script = f"""
|
| 181 |
-
<script>
|
| 182 |
-
function makeDropdownSearchable(dropdownId) {{
|
| 183 |
-
const input = document.getElementById(dropdownId);
|
| 184 |
-
input.addEventListener("input", function() {{
|
| 185 |
-
const value = this.value.toLowerCase();
|
| 186 |
-
const options = Array.from(document.querySelectorAll(`#${dropdownId} option`));
|
| 187 |
-
let found = false;
|
| 188 |
-
for (let i = 0; i < options.length; i++) {{
|
| 189 |
-
const option = options[i];
|
| 190 |
-
const text = option.text.toLowerCase();
|
| 191 |
-
const match = text.includes(value);
|
| 192 |
-
option.style.display = match ? "block" : "none";
|
| 193 |
-
if (match) {{
|
| 194 |
-
found = true;
|
| 195 |
-
}}
|
| 196 |
-
}}
|
| 197 |
-
if (value && !found) {{
|
| 198 |
-
const firstOption = options[0];
|
| 199 |
-
if (firstOption) {{
|
| 200 |
-
firstOption.selected = true;
|
| 201 |
-
}}
|
| 202 |
-
}}
|
| 203 |
-
}});
|
| 204 |
-
}}
|
| 205 |
-
|
| 206 |
-
makeDropdownSearchable("{dropdown_id}");
|
| 207 |
-
</script>
|
| 208 |
-
"""
|
| 209 |
-
return gr.outputs.HTML(script)
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
iface = gr.Interface(
|
| 213 |
-
fn=text_it,
|
| 214 |
-
inputs="text",
|
| 215 |
-
outputs="text",
|
| 216 |
-
css=css,
|
| 217 |
-
capture_session=True
|
| 218 |
-
)
|
| 219 |
-
|
| 220 |
-
model_dropdown = gr.inputs.Dropdown(
|
| 221 |
-
label="Choose Model",
|
| 222 |
-
choices=[m["name"] for m in models],
|
| 223 |
-
type="index",
|
| 224 |
-
value=current_model["name"],
|
| 225 |
-
interactive=True,
|
| 226 |
-
description="Select the model to use for text generation"
|
| 227 |
-
)
|
| 228 |
-
|
| 229 |
-
iface.add_input(model_dropdown, set_model)
|
| 230 |
-
iface.add_input("text", send_it, "output")
|
| 231 |
-
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
|
| 6 |
models = [
|
| 7 |
+
{"name": "Claudfuen 1", "url": "sd-concepts-library/ahx-model-6"},
|
| 8 |
{"name": "Deliberate", "url": "Masagin/Deliberate"},
|
| 9 |
{"name": "Seek Art Mega", "url": "coreco/seek.art_MEGA"},
|
| 10 |
{"name": "Realistic Vision 1.4", "url": "SG161222/Realistic_Vision_V1.4"},
|
|
|
|
| 37 |
return proc(inputs)
|
| 38 |
|
| 39 |
|
| 40 |
+
css = """"""
|
| 41 |
+
|
| 42 |
+
with gr.Blocks(css=css) as myface:
|
| 43 |
+
gr.HTML(
|
| 44 |
+
"""<!DOCTYPE html>
|
| 45 |
+
<html lang="en">
|
| 46 |
+
<head>
|
| 47 |
+
<meta charset="utf-8" />
|
| 48 |
+
<meta name="twitter:card" content="player"/>
|
| 49 |
+
<meta name="twitter:site" content=""/>
|
| 50 |
+
<meta name="twitter:player" content="https://omnibus-maximum-multiplier-places.hf.space"/>
|
| 51 |
+
<meta name="twitter:player:stream" content="https://omnibus-maximum-multiplier-places.hf.space"/>
|
| 52 |
+
<meta name="twitter:player:width" content="100%"/>
|
| 53 |
+
<meta name="twitter:player:height" content="600"/>
|
| 54 |
+
<meta property="og:title" content="Embedded Live Viewer"/>
|
| 55 |
+
<meta property="og:description" content="Tweet Genie - A Huggingface Space"/>
|
| 56 |
+
<meta property="og:image" content="https://cdn.glitch.global/80dbe92e-ce75-44af-84d5-74a2e21e9e55/omnicard.png?v=1676772531627"/>
|
| 57 |
+
<!--<meta http-equiv="refresh" content="0; url=https://huggingface.co/spaces/corbt/tweet-genie">-->
|
| 58 |
+
</head>
|
| 59 |
+
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
"""
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
with gr.Row():
|
| 64 |
+
with gr.Row():
|
| 65 |
+
input_text = gr.Textbox(label="Prompt idea", lines=1)
|
| 66 |
+
# Model selection dropdown
|
| 67 |
+
model_name1 = gr.Dropdown(
|
| 68 |
+
label="Choose Model",
|
| 69 |
+
choices=[m["name"] for m in models],
|
| 70 |
+
type="index",
|
| 71 |
+
value=current_model["name"],
|
| 72 |
+
interactive=True,
|
| 73 |
+
)
|
| 74 |
+
with gr.Row():
|
| 75 |
+
see_prompts = gr.Button("Generate Prompts")
|
| 76 |
+
run = gr.Button("Generate Images", variant="primary")
|
| 77 |
+
with gr.Tab("Main"):
|
| 78 |
+
with gr.Row():
|
| 79 |
+
output1 = gr.Image(label=f"{current_model['name']}")
|
| 80 |
+
output2 = gr.Image(label=f"{current_model['name']}")
|
| 81 |
+
output3 = gr.Image(label=f"{current_model['name']}")
|
| 82 |
+
output4 = gr.Image(label=f"{current_model['name']}")
|
| 83 |
+
with gr.Row():
|
| 84 |
+
magic1 = gr.Textbox(lines=4)
|
| 85 |
+
magic2 = gr.Textbox(lines=4)
|
| 86 |
+
magic3 = gr.Textbox(lines=4)
|
| 87 |
+
magic4 = gr.Textbox(lines=4)
|
| 88 |
+
|
| 89 |
+
with gr.Row():
|
| 90 |
+
output5 = gr.Image(label=f"{current_model['name']}")
|
| 91 |
+
output6 = gr.Image(label=f"{current_model['name']}")
|
| 92 |
+
output7 = gr.Image(label=f"{current_model['name']}")
|
| 93 |
+
output8 = gr.Image(label=f"{current_model['name']}")
|
| 94 |
+
with gr.Row():
|
| 95 |
+
magic5 = gr.Textbox(lines=4)
|
| 96 |
+
magic6 = gr.Textbox(lines=4)
|
| 97 |
+
magic7 = gr.Textbox(lines=4)
|
| 98 |
+
magic8 = gr.Textbox(lines=4)
|
| 99 |
+
|
| 100 |
+
model_name1.change(set_model, inputs=model_name1, outputs=[output1, output2, output3, output4, output5, output6, output7, output8])
|
| 101 |
+
|
| 102 |
+
run.click(send_it, inputs=[magic1, model_name1], outputs=[output1])
|
| 103 |
+
run.click(send_it, inputs=[magic2, model_name1], outputs=[output2])
|
| 104 |
+
run.click(send_it, inputs=[magic3, model_name1], outputs=[output3])
|
| 105 |
+
run.click(send_it, inputs=[magic4, model_name1], outputs=[output4])
|
| 106 |
+
run.click(send_it, inputs=[magic5, model_name1], outputs=[output5])
|
| 107 |
+
run.click(send_it, inputs=[magic6, model_name1], outputs=[output6])
|
| 108 |
+
run.click(send_it, inputs=[magic7, model_name1], outputs=[output7])
|
| 109 |
+
run.click(send_it, inputs=[magic8, model_name1], outputs=[output8])
|
| 110 |
+
|
| 111 |
+
see_prompts.click(text_it, inputs=[input_text], outputs=[magic1])
|
| 112 |
+
see_prompts.click(text_it, inputs=[input_text], outputs=[magic2])
|
| 113 |
+
see_prompts.click(text_it, inputs=[input_text], outputs=[magic3])
|
| 114 |
+
see_prompts.click(text_it, inputs=[input_text], outputs=[magic4])
|
| 115 |
+
see_prompts.click(text_it, inputs=[input_text], outputs=[magic5])
|
| 116 |
+
see_prompts.click(text_it, inputs=[input_text], outputs=[magic6])
|
| 117 |
+
see_prompts.click(text_it, inputs=[input_text], outputs=[magic7])
|
| 118 |
+
see_prompts.click(text_it, inputs=[input_text], outputs=[magic8])
|
| 119 |
+
|
| 120 |
+
myface.queue(concurrency_count=200)
|
| 121 |
+
myface.launch(inline=True, show_api=False, max_threads=400)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|