StyleGAN-Human / app.py
hysts's picture
hysts HF staff
Refactor
d84b2d3
raw
history blame
3.63 kB
#!/usr/bin/env python
from __future__ import annotations
import argparse
import gradio as gr
from huggingface_hub import hf_hub_download
from model import Model
DESCRIPTION = '''# StyleGAN-Human
This is an unofficial demo for [https://github.com/stylegan-human/StyleGAN-Human](https://github.com/stylegan-human/StyleGAN-Human).
'''
FOOTER = '<img id="visitor-badge" alt="visitor badge" src="https://visitor-badge.glitch.me/badge?page_id=gradio-blocks.stylegan-human" />'
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument('--device', type=str, default='cpu')
parser.add_argument('--theme', type=str)
parser.add_argument('--share', action='store_true')
parser.add_argument('--port', type=int)
parser.add_argument('--disable-queue',
dest='enable_queue',
action='store_false')
return parser.parse_args()
def main():
args = parse_args()
app = Model(device=args.device)
with gr.Blocks(theme=args.theme, css='style.css') as demo:
gr.Markdown(DESCRIPTION)
with gr.Row():
with gr.Column():
with gr.Row():
seed1 = gr.Number(value=6876, label='Seed 1')
psi1 = gr.Slider(0,
2,
value=0.7,
step=0.05,
label='Truncation psi 1')
with gr.Row():
generate_button1 = gr.Button('Generate')
with gr.Row():
generated_image1 = gr.Image(type='numpy',
label='Generated Image 1')
with gr.Column():
with gr.Row():
seed2 = gr.Number(value=6886, label='Seed 2')
psi2 = gr.Slider(0,
2,
value=0.7,
step=0.05,
label='Truncation psi 2')
with gr.Row():
generate_button2 = gr.Button('Generate')
with gr.Row():
generated_image2 = gr.Image(type='numpy',
label='Generated Image 2')
with gr.Row():
with gr.Column():
with gr.Row():
num_frames = gr.Slider(
0,
41,
value=7,
step=1,
label='Number of Intermediate Frames')
with gr.Row():
interpolate_button = gr.Button('Interpolate')
with gr.Row():
interpolated_images = gr.Gallery(label='Output Images')
gr.Markdown(FOOTER)
generate_button1.click(app.generate_single_image,
inputs=[seed1, psi1],
outputs=generated_image1)
generate_button2.click(app.generate_single_image,
inputs=[seed2, psi2],
outputs=generated_image2)
interpolate_button.click(app.generate_interpolated_images,
inputs=[seed1, psi1, seed2, psi2, num_frames],
outputs=interpolated_images)
demo.launch(
enable_queue=args.enable_queue,
server_port=args.port,
share=args.share,
)
if __name__ == '__main__':
main()