Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,41 +6,47 @@ import requests
|
|
6 |
|
7 |
|
8 |
repo_id = 'nateraw/stable-diffusion-gallery'
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
def fn(run):
|
20 |
-
images = [(hf_hub_url(repo_id=repo_id, filename=img, repo_type='dataset'), f"Seed
|
21 |
prompt_config_url = hf_hub_url(
|
22 |
repo_id=repo_id,
|
23 |
filename=f'{run}/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 |
-
|
|
|
|
|
|
|
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)
|
|
|
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 all_files:
|
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 |
+
return gr.update(value=list(data.keys()))
|
21 |
+
|
22 |
+
get_data()
|
23 |
|
24 |
def fn(run):
|
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,
|
28 |
filename=f'{run}/prompt_config.json',
|
29 |
repo_type='dataset'
|
30 |
)
|
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=False)
|
38 |
+
|
39 |
+
with gr.Row(variant="compact"):
|
40 |
+
run = gr.Dropdown(list(data.keys()), interactive=True).style(container=False)
|
41 |
btn = gr.Button("View images").style(full_width=False)
|
42 |
|
43 |
with gr.Row(variant="compact"):
|
44 |
data_json = gr.Json()
|
|
|
45 |
gallery = gr.Gallery(
|
46 |
label="Generated images", show_label=False, elem_id="gallery"
|
47 |
).style(grid=[5], height="auto")
|
48 |
|
49 |
+
refresh_btn.click(get_data, None, run)
|
50 |
btn.click(fn, run, [data_json, gallery])
|
51 |
|
52 |
demo.launch(debug=True)
|