#!/usr/bin/env python from __future__ import annotations import gradio as gr import numpy as np from model import Model DESCRIPTION = "# [AvantGAN](https://github.com/ellemcfarlane/AvantGAN)" def get_sample_image_url(name: str) -> str: sample_image_dir = "https://huggingface.co/spaces/ellemac/avantGAN/resolve/main/samples" return f"{sample_image_dir}/{name}.png" def get_sample_image_markdown(name: str) -> str: url = get_sample_image_url(name) size = 128 if ("stylegan3" in name or "original" in name) else 64 return f""" - size: {size}x{size} ![sample images]({url})""" model = Model() with gr.Blocks(css="style.css") as demo: gr.Markdown(DESCRIPTION) with gr.Tabs(): with gr.TabItem("App"): with gr.Row(): with gr.Column(): model_name = gr.Dropdown( label="Model", choices=list(model.MODEL_DICT.keys()), value="stylegan3-abstract" ) seed = gr.Slider(label="Seed", minimum=0, maximum=np.iinfo(np.uint32).max, step=1, value=0) run_button = gr.Button() with gr.Column(): result = gr.Image(label="Result", elem_id="result", width=300, height=300) with gr.TabItem("Sample Images"): with gr.Row(): model_name2 = gr.Dropdown( [ "stylegan3-abstract", "stylegan3-high-fidelity", "ada-dcgan", "original-training-data", ], value="stylegan3-abstract", label="Model", ) with gr.Row(): text = get_sample_image_markdown(model_name2.value) sample_images = gr.Markdown(text) run_button.click( fn=model.set_model_and_generate_image, inputs=[ model_name, seed, ], outputs=result, api_name="run", ) model_name2.change( fn=get_sample_image_markdown, inputs=model_name2, outputs=sample_images, queue=False, api_name=False, ) if __name__ == "__main__": demo.queue(max_size=20).launch()