Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -14,18 +14,26 @@ def get_data(revision='main'):
|
|
14 |
continue
|
15 |
if path.suffix in ['.png', '.jpg', '.jpeg']:
|
16 |
data[path.parent.name].append(file)
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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=
|
26 |
]
|
27 |
|
28 |
-
def on_submit(
|
|
|
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,15 +43,16 @@ def on_submit(run, data):
|
|
35 |
prompt_config_json = requests.get(prompt_config_url).json()
|
36 |
return prompt_config_json, images
|
37 |
|
38 |
-
|
|
|
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 |
-
|
47 |
btn = gr.Button("View images").style(full_width=False)
|
48 |
|
49 |
with gr.Row(variant="compact"):
|
@@ -52,7 +61,8 @@ with gr.Blocks() as demo:
|
|
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,
|
56 |
-
btn.click(on_submit, [
|
57 |
|
58 |
-
|
|
|
|
14 |
continue
|
15 |
if path.suffix in ['.png', '.jpg', '.jpeg']:
|
16 |
data[path.parent.name].append(file)
|
17 |
+
|
18 |
+
prompts = []
|
19 |
+
for key in sorted(data.keys()):
|
20 |
+
prompt_cfg_url = hf_hub_url(repo_id=repo_id, filename=f"{key}/prompt_config.json", repo_type='dataset')
|
21 |
+
prompt_cfg = requests.get(prompt_cfg_url).json()
|
22 |
+
text = prompt_cfg.get('prompt')
|
23 |
+
prompts.append(text)
|
24 |
+
|
25 |
+
return data, prompts
|
26 |
|
27 |
def on_refresh(data_state):
|
28 |
+
data, prompts = get_data()
|
29 |
data_state.update(dict(data))
|
30 |
return [
|
31 |
data_state,
|
32 |
+
gr.update(choices=prompts),
|
33 |
]
|
34 |
|
35 |
+
def on_submit(run_idx, data):
|
36 |
+
run = sorted(data.keys())[run_idx]
|
37 |
images = [(hf_hub_url(repo_id=repo_id, filename=img, repo_type='dataset'), f"Seed:\n{Path(img).stem}") for img in data[run]]
|
38 |
prompt_config_url = hf_hub_url(
|
39 |
repo_id=repo_id,
|
|
|
43 |
prompt_config_json = requests.get(prompt_config_url).json()
|
44 |
return prompt_config_json, images
|
45 |
|
46 |
+
data, prompts = get_data()
|
47 |
+
runs = sorted(data.keys())
|
48 |
with gr.Blocks() as demo:
|
49 |
+
data_state = gr.State(data)
|
50 |
with gr.Column(variant="panel"):
|
51 |
with gr.Row(variant="compact"):
|
52 |
refresh_btn = gr.Button("Refresh").style(full_width=True)
|
53 |
|
54 |
with gr.Row(variant="compact"):
|
55 |
+
run_idx = gr.Dropdown(prompts, type='index') #interactive=True) # .style(container=False)
|
56 |
btn = gr.Button("View images").style(full_width=False)
|
57 |
|
58 |
with gr.Row(variant="compact"):
|
|
|
61 |
label="Generated images", show_label=False, elem_id="gallery"
|
62 |
).style(grid=[5], height="auto")
|
63 |
|
64 |
+
refresh_btn.click(on_refresh, data_state, [data_state, run_idx])
|
65 |
+
btn.click(on_submit, [run_idx, data_state], [data_json, gallery])
|
66 |
|
67 |
+
if __name__ == '__main__':
|
68 |
+
demo.launch(debug=True)
|