Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,24 +4,28 @@ 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 |
|
10 |
-
def get_data():
|
11 |
-
all_files = list_repo_files(repo_id, repo_type='dataset')
|
12 |
-
global data
|
13 |
data = defaultdict(list)
|
14 |
-
for file in
|
15 |
path = Path(file)
|
16 |
if path.name == '.gitattributes':
|
17 |
continue
|
18 |
if path.suffix in ['.png', '.jpg', '.jpeg']:
|
19 |
data[path.parent.name].append(file)
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
images = [(hf_hub_url(repo_id=repo_id, filename=img, repo_type='dataset'), f"Seed:\n{Path(img).stem}") for img in data[run]]
|
26 |
prompt_config_url = hf_hub_url(
|
27 |
repo_id=repo_id,
|
@@ -31,13 +35,15 @@ def fn(run):
|
|
31 |
prompt_config_json = requests.get(prompt_config_url).json()
|
32 |
return prompt_config_json, images
|
33 |
|
|
|
34 |
with gr.Blocks() as demo:
|
|
|
35 |
with gr.Column(variant="panel"):
|
36 |
with gr.Row(variant="compact"):
|
37 |
refresh_btn = gr.Button("Refresh").style(full_width=True)
|
38 |
|
39 |
with gr.Row(variant="compact"):
|
40 |
-
run = gr.Dropdown(
|
41 |
btn = gr.Button("View images").style(full_width=False)
|
42 |
|
43 |
with gr.Row(variant="compact"):
|
@@ -46,7 +52,7 @@ with gr.Blocks() as demo:
|
|
46 |
label="Generated images", show_label=False, elem_id="gallery"
|
47 |
).style(grid=[5], height="auto")
|
48 |
|
49 |
-
refresh_btn.click(
|
50 |
-
btn.click(
|
51 |
|
52 |
demo.launch(debug=True)
|
|
|
4 |
from collections import defaultdict
|
5 |
import requests
|
6 |
|
|
|
7 |
repo_id = 'nateraw/stable-diffusion-gallery'
|
8 |
|
9 |
+
def get_data(revision='main'):
|
|
|
|
|
10 |
data = defaultdict(list)
|
11 |
+
for file in list_repo_files(repo_id, repo_type='dataset', revision=revision):
|
12 |
path = Path(file)
|
13 |
if path.name == '.gitattributes':
|
14 |
continue
|
15 |
if path.suffix in ['.png', '.jpg', '.jpeg']:
|
16 |
data[path.parent.name].append(file)
|
17 |
+
print(data.keys())
|
18 |
+
return data
|
19 |
+
|
20 |
+
def on_refresh(data_state):
|
21 |
+
data = get_data()
|
22 |
+
data_state.update(dict(data))
|
23 |
+
return [
|
24 |
+
data_state,
|
25 |
+
gr.update(choices=list(data_state.keys())),
|
26 |
+
]
|
27 |
+
|
28 |
+
def on_submit(run, data):
|
29 |
images = [(hf_hub_url(repo_id=repo_id, filename=img, repo_type='dataset'), f"Seed:\n{Path(img).stem}") for img in data[run]]
|
30 |
prompt_config_url = hf_hub_url(
|
31 |
repo_id=repo_id,
|
|
|
35 |
prompt_config_json = requests.get(prompt_config_url).json()
|
36 |
return prompt_config_json, images
|
37 |
|
38 |
+
runs = list(get_data().keys())
|
39 |
with gr.Blocks() as demo:
|
40 |
+
data_state = gr.State({})
|
41 |
with gr.Column(variant="panel"):
|
42 |
with gr.Row(variant="compact"):
|
43 |
refresh_btn = gr.Button("Refresh").style(full_width=True)
|
44 |
|
45 |
with gr.Row(variant="compact"):
|
46 |
+
run = gr.Dropdown(runs) #interactive=True) # .style(container=False)
|
47 |
btn = gr.Button("View images").style(full_width=False)
|
48 |
|
49 |
with gr.Row(variant="compact"):
|
|
|
52 |
label="Generated images", show_label=False, elem_id="gallery"
|
53 |
).style(grid=[5], height="auto")
|
54 |
|
55 |
+
refresh_btn.click(on_refresh, data_state, [data_state, run])
|
56 |
+
btn.click(on_submit, [run, data_state], [data_json, gallery])
|
57 |
|
58 |
demo.launch(debug=True)
|