Spaces:
Runtime error
Runtime error
Commit
•
6ab078b
1
Parent(s):
0f5cc5e
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
#@title Prepare the Concepts Library to be used
|
2 |
-
|
3 |
import requests
|
4 |
import os
|
5 |
import gradio as gr
|
@@ -9,9 +8,10 @@ from torch import autocast
|
|
9 |
from diffusers import StableDiffusionPipeline
|
10 |
from huggingface_hub import HfApi
|
11 |
from transformers import CLIPTextModel, CLIPTokenizer
|
|
|
12 |
|
13 |
api = HfApi()
|
14 |
-
models_list = api.list_models(author="sd-concepts-library")
|
15 |
models = []
|
16 |
|
17 |
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=True, revision="fp16", torch_dtype=torch.float16).to("cuda")
|
@@ -86,7 +86,53 @@ for model in models_list:
|
|
86 |
#@markdown Click the `Running on public URL:` result to run the Gradio app
|
87 |
|
88 |
SELECT_LABEL = "Select concept"
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
def title_block(title, id):
|
91 |
return gr.Markdown(f"### [`{title}`](https://huggingface.co/{id})")
|
92 |
|
@@ -211,10 +257,11 @@ with gr.Blocks(css=css) as demo:
|
|
211 |
''')
|
212 |
with gr.Row(elem_id="main_row"):
|
213 |
image_blocks = []
|
214 |
-
for i, model in enumerate(models):
|
215 |
-
|
216 |
-
|
217 |
-
|
|
|
218 |
with gr.Box():
|
219 |
with gr.Row(elem_id="prompt_area").style(mobile_collapse=False, equal_height=True):
|
220 |
text = gr.Textbox(
|
@@ -241,4 +288,4 @@ with gr.Blocks(css=css) as demo:
|
|
241 |
inputs=inputs,
|
242 |
outputs=infer_outputs
|
243 |
)
|
244 |
-
demo.launch(
|
|
|
1 |
#@title Prepare the Concepts Library to be used
|
|
|
2 |
import requests
|
3 |
import os
|
4 |
import gradio as gr
|
|
|
8 |
from diffusers import StableDiffusionPipeline
|
9 |
from huggingface_hub import HfApi
|
10 |
from transformers import CLIPTextModel, CLIPTokenizer
|
11 |
+
import html
|
12 |
|
13 |
api = HfApi()
|
14 |
+
models_list = api.list_models(author="sd-concepts-library", sort="likes", direction=-1)
|
15 |
models = []
|
16 |
|
17 |
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=True, revision="fp16", torch_dtype=torch.float16).to("cuda")
|
|
|
86 |
#@markdown Click the `Running on public URL:` result to run the Gradio app
|
87 |
|
88 |
SELECT_LABEL = "Select concept"
|
89 |
+
def assembleHTML(model):
|
90 |
+
html_gallery = ''
|
91 |
+
html_gallery = html_gallery+'''
|
92 |
+
<div class="flex gr-gap gr-form-gap row gap-4 w-full flex-wrap" id="main_row">
|
93 |
+
'''
|
94 |
+
for model in models:
|
95 |
+
html_gallery = html_gallery+f'''
|
96 |
+
<div class="gr-block gr-box relative w-full overflow-hidden border-solid border border-gray-200 gr-panel">
|
97 |
+
<div class="output-markdown gr-prose" style="max-width: 100%;">
|
98 |
+
<h3>
|
99 |
+
<a href="https://huggingface.co/{model["id"]}" target="_blank">
|
100 |
+
<code>{html.escape(model["token"])}</code>
|
101 |
+
</a>
|
102 |
+
</h3>
|
103 |
+
</div>
|
104 |
+
<div id="gallery" class="gr-block gr-box relative w-full overflow-hidden border-solid border border-gray-200">
|
105 |
+
<div class="wrap svelte-17ttdjv opacity-0"></div>
|
106 |
+
<div class="absolute left-0 top-0 py-1 px-2 rounded-br-lg shadow-sm text-xs text-gray-500 flex items-center pointer-events-none bg-white z-20 border-b border-r border-gray-100 dark:bg-gray-900">
|
107 |
+
<span class="mr-2 h-[12px] w-[12px] opacity-80">
|
108 |
+
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather feather-image">
|
109 |
+
<rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect>
|
110 |
+
<circle cx="8.5" cy="8.5" r="1.5"></circle>
|
111 |
+
<polyline points="21 15 16 10 5 21"></polyline>
|
112 |
+
</svg>
|
113 |
+
</span> {model["concept_type"]}
|
114 |
+
</div>
|
115 |
+
<div class="overflow-y-auto h-full p-2" style="position: relative;">
|
116 |
+
<div class="grid gap-2 grid-cols-2 sm:grid-cols-2 md:grid-cols-2 lg:grid-cols-2 xl:grid-cols-2 2xl:grid-cols-2 svelte-1g9btlg pt-6">
|
117 |
+
'''
|
118 |
+
for image in model["images"]:
|
119 |
+
html_gallery = html_gallery + f'''
|
120 |
+
<button class="gallery-item svelte-1g9btlg">
|
121 |
+
<img alt="" loading="lazy" class="h-full w-full overflow-hidden object-contain" src="file/{image}">
|
122 |
+
</button>
|
123 |
+
'''
|
124 |
+
html_gallery = html_gallery+'''
|
125 |
+
</div>
|
126 |
+
<iframe style="display: block; position: absolute; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden; border: 0; opacity: 0; pointer-events: none; z-index: -1;" aria-hidden="true" tabindex="-1" src="about:blank"></iframe>
|
127 |
+
</div>
|
128 |
+
</div>
|
129 |
+
</div>
|
130 |
+
'''
|
131 |
+
html_gallery = html_gallery+'''
|
132 |
+
</div>
|
133 |
+
'''
|
134 |
+
return html_gallery
|
135 |
+
|
136 |
def title_block(title, id):
|
137 |
return gr.Markdown(f"### [`{title}`](https://huggingface.co/{id})")
|
138 |
|
|
|
257 |
''')
|
258 |
with gr.Row(elem_id="main_row"):
|
259 |
image_blocks = []
|
260 |
+
#for i, model in enumerate(models):
|
261 |
+
with gr.Box().style(border=None):
|
262 |
+
gr.HTML(assembleHTML(models))
|
263 |
+
#title_block(model["token"], model["id"])
|
264 |
+
#image_blocks.append(image_block(model["images"], model["concept_type"]))
|
265 |
with gr.Box():
|
266 |
with gr.Row(elem_id="prompt_area").style(mobile_collapse=False, equal_height=True):
|
267 |
text = gr.Textbox(
|
|
|
288 |
inputs=inputs,
|
289 |
outputs=infer_outputs
|
290 |
)
|
291 |
+
demo.launch(max_size=25)
|