Spaces:
Runtime error
Runtime error
Commit
Β·
877dee8
1
Parent(s):
871d7f6
Minor overhaul to tabs from semi-working version
Browse files
app.py
CHANGED
@@ -101,7 +101,6 @@ for model in ahx_model_list:
|
|
101 |
# -----------------------------------------------------------------------------------------------
|
102 |
|
103 |
|
104 |
-
|
105 |
#@title Dropdown Prompt Tab
|
106 |
|
107 |
model_tags = [model.modelId.split("/")[1] for model in ahx_model_list]
|
@@ -141,10 +140,15 @@ def random_seed():
|
|
141 |
return random.randint(0, 99999999999999) # <-- this is a random gradio limit, the seed range seems to actually be 0-18446744073709551615
|
142 |
|
143 |
with gr.Blocks(css=".gradio-container {max-width: 650px}") as dropdown_tab:
|
144 |
-
|
|
|
145 |
|
146 |
-
|
147 |
-
|
|
|
|
|
|
|
|
|
148 |
|
149 |
with gr.Row():
|
150 |
prompt = gr.Textbox(label="image prompt...", elem_id="input-text")
|
@@ -189,39 +193,83 @@ with gr.Blocks(css=".gradio-container {max-width: 650px}") as dropdown_tab:
|
|
189 |
# -----------------------------------------------------------------------------------------------
|
190 |
|
191 |
|
|
|
192 |
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
|
200 |
-
def
|
201 |
-
return
|
202 |
-
label=concept_type, value=image_list, elem_id="gallery"
|
203 |
-
).style(grid=[2], height="auto")
|
204 |
|
205 |
-
def
|
206 |
-
|
207 |
-
return checkbox
|
208 |
|
209 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
images_list = pipe(
|
211 |
-
[text],
|
212 |
-
num_inference_steps=
|
213 |
guidance_scale=7.5
|
214 |
)
|
215 |
return images_list.images, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
216 |
|
217 |
-
|
218 |
-
images_list = pipe(
|
219 |
-
[text],
|
220 |
-
num_inference_steps=50,
|
221 |
-
guidance_scale=7.5
|
222 |
-
)
|
223 |
-
return images_list.images
|
224 |
-
|
225 |
css = ""
|
226 |
examples = []
|
227 |
|
@@ -246,31 +294,17 @@ with gr.Blocks(css=css) as demo:
|
|
246 |
''')
|
247 |
with gr.Row():
|
248 |
with gr.Column():
|
249 |
-
# with gr.Box():
|
250 |
dropdown = gr.Dropdown(list(DROPDOWNS), label="choose style...")
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
border=(True, False, True, True),
|
256 |
-
rounded=(True, False, False, True),
|
257 |
-
container=False,
|
258 |
-
)
|
259 |
-
btn = gr.Button("generate image",elem_id="run_btn").style(
|
260 |
-
margin=False,
|
261 |
-
rounded=(False, True, True, False),
|
262 |
-
)
|
263 |
-
# with gr.Row().style():
|
264 |
infer_outputs = gr.Gallery(show_label=False, elem_id="generated-gallery").style(grid=[1])
|
265 |
-
with gr.Row():
|
266 |
-
gr.HTML("<p></p>")
|
267 |
-
with gr.Row():
|
268 |
-
gr.Examples(examples=examples, fn=infer_examples, inputs=[text], outputs=infer_outputs, cache_examples=True)
|
269 |
with gr.Group(elem_id="share-btn-container"):
|
270 |
community_icon = gr.HTML(community_icon_html, visible=False)
|
271 |
loading_icon = gr.HTML(loading_icon_html, visible=False)
|
272 |
checkbox_states = {}
|
273 |
-
inputs = [text]
|
274 |
btn.click(
|
275 |
infer,
|
276 |
inputs=inputs,
|
@@ -280,6 +314,5 @@ with gr.Blocks(css=css) as demo:
|
|
280 |
# -----------------------------------------------------------------------------------------------
|
281 |
|
282 |
|
283 |
-
|
284 |
-
tabbed_interface = gr.TabbedInterface([demo.queue(max_size=20), dropdown_tab], ["Welcome!", "Advanced Prompting"])
|
285 |
tabbed_interface.launch()
|
|
|
101 |
# -----------------------------------------------------------------------------------------------
|
102 |
|
103 |
|
|
|
104 |
#@title Dropdown Prompt Tab
|
105 |
|
106 |
model_tags = [model.modelId.split("/")[1] for model in ahx_model_list]
|
|
|
140 |
return random.randint(0, 99999999999999) # <-- this is a random gradio limit, the seed range seems to actually be 0-18446744073709551615
|
141 |
|
142 |
with gr.Blocks(css=".gradio-container {max-width: 650px}") as dropdown_tab:
|
143 |
+
gr.Markdown('''
|
144 |
+
# π§βπ Advanced Concept Loader
|
145 |
|
146 |
+
This tool allows you to run your own text prompts into fine-tuned artist concepts with individual parameter controls.
|
147 |
+
Text prompts need to manually include artist concept / model tokens, see the examples below.
|
148 |
+
The seed controls the static starting.
|
149 |
+
Additionally if you can play around with more controls in the Advanced Prompting tab. Enjoy!
|
150 |
+
<a href="http://www.astronaut.horse">http://www.astronaut.horse</a>
|
151 |
+
''')
|
152 |
|
153 |
with gr.Row():
|
154 |
prompt = gr.Textbox(label="image prompt...", elem_id="input-text")
|
|
|
193 |
# -----------------------------------------------------------------------------------------------
|
194 |
|
195 |
|
196 |
+
#@title Dropdown Prompt Tab
|
197 |
|
198 |
+
model_tags = [model.modelId.split("/")[1] for model in ahx_model_list]
|
199 |
+
model_tags.sort()
|
200 |
+
|
201 |
+
|
202 |
+
import random
|
203 |
+
|
204 |
+
|
205 |
+
#@title Gradio Concept Loader
|
206 |
+
DROPDOWNS = {}
|
207 |
+
|
208 |
+
for model in model_tags:
|
209 |
+
if model != "ahx-model-1" and model != "ahx-model-2":
|
210 |
+
DROPDOWNS[model] = f" in the style of <{model}>"
|
211 |
+
|
212 |
+
# def image_prompt(prompt, dropdown, guidance, steps, seed, height, width):
|
213 |
+
|
214 |
+
|
215 |
+
|
216 |
+
def default_guidance():
|
217 |
+
return 7.5
|
218 |
|
219 |
+
def default_steps():
|
220 |
+
return 30
|
|
|
|
|
221 |
|
222 |
+
def default_pixel():
|
223 |
+
return 768
|
|
|
224 |
|
225 |
+
def random_seed():
|
226 |
+
return random.randint(0, 99999999999999) # <-- this is a random gradio limit, the seed range seems to actually be 0-18446744073709551615
|
227 |
+
|
228 |
+
|
229 |
+
def simple_image_prompt(prompt, dropdown):
|
230 |
+
seed = random_seed()
|
231 |
+
guidance = 7.5
|
232 |
+
height = 768
|
233 |
+
width = 768
|
234 |
+
steps = 30
|
235 |
+
|
236 |
+
prompt = prompt + DROPDOWNS[dropdown]
|
237 |
+
generator = torch.Generator(device="cuda").manual_seed(int(seed))
|
238 |
+
return (
|
239 |
+
pipe(prompt=prompt, guidance_scale=guidance, num_inference_steps=steps, generator=generator, height=int((height // 8) * 8), width=int((width // 8) * 8)).images[0],
|
240 |
+
f"prompt = '{prompt}'\nseed = {int(seed)}\nguidance_scale = {guidance}\ninference steps = {steps}\nheight = {int((height // 8) * 8)}\nwidth = {int((width // 8) * 8)}"
|
241 |
+
)
|
242 |
+
|
243 |
+
|
244 |
+
with gr.Blocks(css=".gradio-container {max-width: 650px}") as new_welcome:
|
245 |
+
gr.Markdown('''
|
246 |
+
# π§βπ Astronaut Horse Concept Loader
|
247 |
+
|
248 |
+
This tool allows you to run your own text prompts into fine-tuned artist concepts from an ongoing series of Stable Diffusion collaborations with visual artists linked below. Select an artist's fine-tuned concept / model from the dropdown and enter any desired text prompt. You can check out example output images and project details on the project's webpage. Additionally if you can play around with more controls in the Advanced Prompting tab. Enjoy!
|
249 |
+
<a href="http://www.astronaut.horse">http://www.astronaut.horse</a>
|
250 |
+
''')
|
251 |
+
dropdown = gr.Dropdown(list(DROPDOWNS), label="choose style...")
|
252 |
+
|
253 |
+
# with gr.Row():
|
254 |
+
prompt = gr.Textbox(label="image prompt...", elem_id="input-text")
|
255 |
+
|
256 |
+
go_button = gr.Button("generate image", elem_id="go-button")
|
257 |
+
output = gr.Image(elem_id="output-image")
|
258 |
+
output_text = gr.Text(elem_id="output-text")
|
259 |
+
go_button.click(fn=simple_image_prompt, inputs=[prompt, dropdown], outputs=[output, output_text])
|
260 |
+
|
261 |
+
# -----------------------------------------------------------------------------------------------
|
262 |
+
|
263 |
+
|
264 |
+
def infer(text, dropdown):
|
265 |
images_list = pipe(
|
266 |
+
[f"{text} in the style of <{dropdown}>"],
|
267 |
+
num_inference_steps=30,
|
268 |
guidance_scale=7.5
|
269 |
)
|
270 |
return images_list.images, gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
271 |
|
272 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
273 |
css = ""
|
274 |
examples = []
|
275 |
|
|
|
294 |
''')
|
295 |
with gr.Row():
|
296 |
with gr.Column():
|
|
|
297 |
dropdown = gr.Dropdown(list(DROPDOWNS), label="choose style...")
|
298 |
+
text = gr.Textbox(
|
299 |
+
label="Enter your prompt", placeholder="Enter your prompt", show_label=False, max_lines=1, elem_id="prompt_input"
|
300 |
+
)
|
301 |
+
btn = gr.Button("generate image",elem_id="run_btn")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
302 |
infer_outputs = gr.Gallery(show_label=False, elem_id="generated-gallery").style(grid=[1])
|
|
|
|
|
|
|
|
|
303 |
with gr.Group(elem_id="share-btn-container"):
|
304 |
community_icon = gr.HTML(community_icon_html, visible=False)
|
305 |
loading_icon = gr.HTML(loading_icon_html, visible=False)
|
306 |
checkbox_states = {}
|
307 |
+
inputs = [text, dropdown]
|
308 |
btn.click(
|
309 |
infer,
|
310 |
inputs=inputs,
|
|
|
314 |
# -----------------------------------------------------------------------------------------------
|
315 |
|
316 |
|
317 |
+
tabbed_interface = gr.TabbedInterface([new_welcome, dropdown_tab], ["Welcome!", "Advanced Prompting"])
|
|
|
318 |
tabbed_interface.launch()
|