Spaces:
Runtime error
Runtime error
Commit
Β·
97cc1f0
1
Parent(s):
2a904da
Add advanced tab to working basic tab
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
#@title Prepare the Concepts Library to be used
|
2 |
|
|
|
3 |
import requests
|
4 |
import os
|
5 |
import gradio as gr
|
@@ -21,7 +22,6 @@ models_list = api.list_models(author="sd-concepts-library", sort="likes", direct
|
|
21 |
models = []
|
22 |
|
23 |
my_token = os.environ['api_key']
|
24 |
-
# my_token = "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" # π€«
|
25 |
|
26 |
pipe = StableDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2", revision="fp16", torch_dtype=torch.float16, use_auth_token=my_token).to("cuda")
|
27 |
|
@@ -98,9 +98,97 @@ for model in ahx_model_list:
|
|
98 |
models.append(model_content)
|
99 |
|
100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
|
103 |
-
#@title Prepare the Concepts Library to be used
|
104 |
|
105 |
SELECT_LABEL = "Select concept"
|
106 |
def assembleHTML(model):
|
@@ -153,31 +241,31 @@ with gr.Blocks(css=css) as demo:
|
|
153 |
gr.Markdown('''
|
154 |
# π§βπ Astronaut Horse Concept Loader
|
155 |
|
156 |
-
|
157 |
-
|
158 |
-
http://www.astronaut.horse
|
159 |
''')
|
160 |
with gr.Row():
|
161 |
with gr.Column():
|
162 |
-
with gr.Box():
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
|
|
181 |
with gr.Group(elem_id="share-btn-container"):
|
182 |
community_icon = gr.HTML(community_icon_html, visible=False)
|
183 |
loading_icon = gr.HTML(loading_icon_html, visible=False)
|
@@ -188,24 +276,10 @@ with gr.Blocks(css=css) as demo:
|
|
188 |
inputs=inputs,
|
189 |
outputs=[infer_outputs, community_icon, loading_icon]
|
190 |
)
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
## Valid Artist Tokens:
|
197 |
-
* \<afx-model-3>
|
198 |
-
* \<afx-model-4>
|
199 |
-
* \<afx-model-6>
|
200 |
-
* \<afx-model-7>
|
201 |
-
* \<afx-model-9>
|
202 |
-
* \<afx-model-10>
|
203 |
-
* \<afx-model-11>
|
204 |
-
* \<afx-model-12>
|
205 |
-
* \<afx-model-13>
|
206 |
-
* \<afx-model-14>
|
207 |
-
''')
|
208 |
-
# demo.queue(max_size=20).launch()
|
209 |
|
210 |
-
tabbed_interface = gr.TabbedInterface([demo.queue(max_size=20)], ["
|
211 |
-
tabbed_interface.launch()
|
|
|
1 |
#@title Prepare the Concepts Library to be used
|
2 |
|
3 |
+
|
4 |
import requests
|
5 |
import os
|
6 |
import gradio as gr
|
|
|
22 |
models = []
|
23 |
|
24 |
my_token = os.environ['api_key']
|
|
|
25 |
|
26 |
pipe = StableDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2", revision="fp16", torch_dtype=torch.float16, use_auth_token=my_token).to("cuda")
|
27 |
|
|
|
98 |
models.append(model_content)
|
99 |
|
100 |
|
101 |
+
# -----------------------------------------------------------------------------------------------
|
102 |
+
|
103 |
+
|
104 |
+
|
105 |
+
#@title Dropdown Prompt Tab
|
106 |
+
|
107 |
+
model_tags = [model.modelId.split("/")[1] for model in ahx_model_list]
|
108 |
+
model_tags.sort()
|
109 |
+
|
110 |
+
|
111 |
+
import random
|
112 |
+
|
113 |
+
|
114 |
+
#@title Gradio Concept Loader
|
115 |
+
DROPDOWNS = {}
|
116 |
+
|
117 |
+
for model in model_tags:
|
118 |
+
if model != "ahx-model-1" and model != "ahx-model-2":
|
119 |
+
DROPDOWNS[model] = f" in the style of <{model}>"
|
120 |
+
|
121 |
+
# def image_prompt(prompt, dropdown, guidance, steps, seed, height, width):
|
122 |
+
def image_prompt(prompt, guidance, steps, seed, height, width):
|
123 |
+
# prompt = prompt + DROPDOWNS[dropdown]
|
124 |
+
generator = torch.Generator(device="cuda").manual_seed(int(seed))
|
125 |
+
return (
|
126 |
+
pipe(prompt=prompt, guidance_scale=guidance, num_inference_steps=steps, generator=generator, height=int((height // 8) * 8), width=int((width // 8) * 8)).images[0],
|
127 |
+
f"prompt = '{prompt}'\nseed = {int(seed)}\nguidance_scale = {guidance}\ninference steps = {steps}\nheight = {int((height // 8) * 8)}\nwidth = {int((width // 8) * 8)}"
|
128 |
+
)
|
129 |
+
|
130 |
+
|
131 |
+
def default_guidance():
|
132 |
+
return 7.5
|
133 |
+
|
134 |
+
def default_steps():
|
135 |
+
return 30
|
136 |
+
|
137 |
+
def default_pixel():
|
138 |
+
return 768
|
139 |
+
|
140 |
+
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 |
+
# gr.Markdown("<u>styles</u>: check out examples of these at https://www.astronaut.horse/collaborations")
|
145 |
+
|
146 |
+
# dropdown = gr.Dropdown(list(DROPDOWNS), label="choose style...")
|
147 |
+
# gr.Markdown("<u>styles</u>: check out examples of these at https://www.astronaut.horse/collaborations")
|
148 |
+
|
149 |
+
with gr.Row():
|
150 |
+
prompt = gr.Textbox(label="image prompt...", elem_id="input-text")
|
151 |
+
with gr.Row():
|
152 |
+
seed = gr.Slider(0, 99999999999999, label="seed", dtype=int, value=random_seed, interactive=True, step=1)
|
153 |
+
with gr.Row():
|
154 |
+
with gr.Column():
|
155 |
+
guidance = gr.Slider(0, 10, label="guidance", dtype=float, value=default_guidance, step=0.1, interactive=True)
|
156 |
+
with gr.Column():
|
157 |
+
steps = gr.Slider(1, 100, label="inference steps", dtype=int, value=default_steps, step=1, interactive=True)
|
158 |
+
with gr.Row():
|
159 |
+
with gr.Column():
|
160 |
+
height = gr.Slider(50, 3500, label="height", dtype=int, value=default_pixel, step=1, interactive=True)
|
161 |
+
with gr.Column():
|
162 |
+
width = gr.Slider(50, 3500, label="width", dtype=int, value=default_pixel, step=1, interactive=True)
|
163 |
+
gr.Markdown("<u>heads-up</u>: height multiplied by width should not exceed about 195,000 or an error will occur so don't go too nuts")
|
164 |
+
|
165 |
+
go_button = gr.Button("generate image", elem_id="go-button")
|
166 |
+
output = gr.Image(elem_id="output-image")
|
167 |
+
output_text = gr.Text(elem_id="output-text")
|
168 |
+
# go_button.click(fn=image_prompt, inputs=[prompt, dropdown, guidance, steps, seed, height, width], outputs=[output, output_text])
|
169 |
+
go_button.click(fn=image_prompt, inputs=[prompt, guidance, steps, seed, height, width], outputs=[output, output_text])
|
170 |
+
gr.Markdown('''
|
171 |
+
## Prompt Examples Using Artist Tokens:
|
172 |
+
* "an alien in the style of \<ahx-model-12>"
|
173 |
+
* "a painting in the style of \<ahx-model-11>"
|
174 |
+
* "a landscape in the style of \<ahx-model-10> and \<ahx-model-14> "
|
175 |
+
|
176 |
+
## Valid Artist Tokens:
|
177 |
+
* \<ahx-model-3>
|
178 |
+
* \<ahx-model-4>
|
179 |
+
* \<ahx-model-6>
|
180 |
+
* \<ahx-model-7>
|
181 |
+
* \<ahx-model-9>
|
182 |
+
* \<ahx-model-10>
|
183 |
+
* \<ahx-model-11>
|
184 |
+
* \<ahx-model-12>
|
185 |
+
* \<ahx-model-13>
|
186 |
+
* \<ahx-model-14>
|
187 |
+
''')
|
188 |
+
|
189 |
+
# -----------------------------------------------------------------------------------------------
|
190 |
|
191 |
|
|
|
192 |
|
193 |
SELECT_LABEL = "Select concept"
|
194 |
def assembleHTML(model):
|
|
|
241 |
gr.Markdown('''
|
242 |
# π§βπ Astronaut Horse Concept Loader
|
243 |
|
244 |
+
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!
|
245 |
+
<a href="http://www.astronaut.horse">http://www.astronaut.horse</a>
|
|
|
246 |
''')
|
247 |
with gr.Row():
|
248 |
with gr.Column():
|
249 |
+
# with gr.Box():
|
250 |
+
dropdown = gr.Dropdown(list(DROPDOWNS), label="choose style...")
|
251 |
+
with gr.Row(elem_id="prompt_area").style(mobile_collapse=False, equal_height=True):
|
252 |
+
text = gr.Textbox(
|
253 |
+
label="Enter your prompt", placeholder="Enter your prompt", show_label=False, max_lines=1, elem_id="prompt_input"
|
254 |
+
).style(
|
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)
|
|
|
276 |
inputs=inputs,
|
277 |
outputs=[infer_outputs, community_icon, loading_icon]
|
278 |
)
|
279 |
+
|
280 |
+
# -----------------------------------------------------------------------------------------------
|
281 |
+
|
282 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
|
284 |
+
tabbed_interface = gr.TabbedInterface([demo.queue(max_size=20), dropdown_tab], ["Welcome!", "Advanced Prompting"])
|
285 |
+
tabbed_interface.launch(share=True)
|