Spaces:
Runtime error
Runtime error
Create new file
Browse files
app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from pathlib import Path
|
3 |
+
from huggingface_hub import list_repo_files, hf_hub_url
|
4 |
+
from collections import defaultdict
|
5 |
+
import requests
|
6 |
+
|
7 |
+
|
8 |
+
repo_id = 'nateraw/stable-diffusion-gallery'
|
9 |
+
all_files = list_repo_files(repo_id, repo_type='dataset')
|
10 |
+
data = defaultdict(list)
|
11 |
+
for file in all_files:
|
12 |
+
path = Path(file)
|
13 |
+
parent, name = path.parent, path.name
|
14 |
+
if path.name == '.gitattributes':
|
15 |
+
continue
|
16 |
+
if path.suffix in ['.png', '.jpg', '.jpeg']:
|
17 |
+
data[parent.name].append(file)
|
18 |
+
|
19 |
+
def fn(run):
|
20 |
+
images = [(hf_hub_url(repo_id=repo_id, filename=img, repo_type='dataset'), f"Seed: {Path(img).stem}") for img in data[run]]
|
21 |
+
prompt_config_url = hf_hub_url(
|
22 |
+
repo_id=repo_id,
|
23 |
+
filename='9fb143fa450011ed95da3947aa01fb28/prompt_config.json',
|
24 |
+
repo_type='dataset'
|
25 |
+
)
|
26 |
+
prompt_config_json = requests.get(prompt_config_url).json()
|
27 |
+
print("IMAGES", images)
|
28 |
+
print("PROMPT CONFIG", prompt_config_json)
|
29 |
+
return prompt_config_json, images
|
30 |
+
|
31 |
+
with gr.Blocks() as demo:
|
32 |
+
with gr.Column(variant="panel"):
|
33 |
+
with gr.Row(variant="compact"):
|
34 |
+
run = gr.Dropdown(list(data.keys()), interactive=True).style(container=False,)
|
35 |
+
btn = gr.Button("View images").style(full_width=False)
|
36 |
+
|
37 |
+
with gr.Row(variant="compact"):
|
38 |
+
data_json = gr.Json()
|
39 |
+
|
40 |
+
gallery = gr.Gallery(
|
41 |
+
label="Generated images", show_label=False, elem_id="gallery"
|
42 |
+
).style(grid=[5], height="auto")
|
43 |
+
|
44 |
+
btn.click(fn, run, [data_json, gallery])
|
45 |
+
|
46 |
+
demo.launch(debug=True)
|