Spaces:
Runtime error
Runtime error
import gradio as gr | |
from pathlib import Path | |
from huggingface_hub import list_repo_files, hf_hub_url | |
from collections import defaultdict | |
import requests | |
repo_id = 'nateraw/stable-diffusion-gallery' | |
all_files = list_repo_files(repo_id, repo_type='dataset') | |
data = defaultdict(list) | |
for file in all_files: | |
path = Path(file) | |
parent, name = path.parent, path.name | |
if path.name == '.gitattributes': | |
continue | |
if path.suffix in ['.png', '.jpg', '.jpeg']: | |
data[parent.name].append(file) | |
def fn(run): | |
images = [(hf_hub_url(repo_id=repo_id, filename=img, repo_type='dataset'), f"Seed: {Path(img).stem}") for img in data[run]] | |
prompt_config_url = hf_hub_url( | |
repo_id=repo_id, | |
filename='9fb143fa450011ed95da3947aa01fb28/prompt_config.json', | |
repo_type='dataset' | |
) | |
prompt_config_json = requests.get(prompt_config_url).json() | |
print("IMAGES", images) | |
print("PROMPT CONFIG", prompt_config_json) | |
return prompt_config_json, images | |
with gr.Blocks() as demo: | |
with gr.Column(variant="panel"): | |
with gr.Row(variant="compact"): | |
run = gr.Dropdown(list(data.keys()), interactive=True).style(container=False,) | |
btn = gr.Button("View images").style(full_width=False) | |
with gr.Row(variant="compact"): | |
data_json = gr.Json() | |
gallery = gr.Gallery( | |
label="Generated images", show_label=False, elem_id="gallery" | |
).style(grid=[5], height="auto") | |
btn.click(fn, run, [data_json, gallery]) | |
demo.launch(debug=True) |