from __future__ import annotations import argparse import pathlib import torch import gradio as gr from webUI.app_task import * from webUI.styleganex_model import Model 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() DESCRIPTION = '''

Face Manipulation with StyleGANEX

For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings. Duplicate Space

example

''' ARTICLE = r""" If StyleGANEX is helpful, please help to ⭐ the Github Repo. Thanks! [![GitHub Stars](https://img.shields.io/github/stars/williamyang1991/StyleGANEX?style=social)](https://github.com/williamyang1991/StyleGANEX) --- 📝 **Citation** If our work is useful for your research, please consider citing: ```bibtex @article{yang2023styleganex, title = {StyleGANEX: StyleGAN-Based Manipulation Beyond Cropped Aligned Faces}, author = {Yang, Shuai and Jiang, Liming and Liu, Ziwei and and Loy, Chen Change}, journal = {arXiv preprint arXiv:2303.06146}, year={2023}, } ``` 📋 **License** This project is licensed under S-Lab License 1.0. Redistribution and use for non-commercial purposes should follow this license. 📧 **Contact** If you have any questions, please feel free to reach me out at williamyang@pku.edu.cn. """ FOOTER = '
visitor badge
' torch.hub.download_url_to_file('https://raw.githubusercontent.com/williamyang1991/StyleGANEX/main/data/234_sketch.jpg', '234_sketch.jpg') torch.hub.download_url_to_file('https://github.com/williamyang1991/StyleGANEX/raw/main/output/ILip77SbmOE_inversion.pt', 'ILip77SbmOE_inversion.pt') torch.hub.download_url_to_file('https://raw.githubusercontent.com/williamyang1991/StyleGANEX/main/data/ILip77SbmOE.png', 'ILip77SbmOE.png') torch.hub.download_url_to_file('https://raw.githubusercontent.com/williamyang1991/StyleGANEX/main/data/ILip77SbmOE_mask.png', 'ILip77SbmOE_mask.png') torch.hub.download_url_to_file('https://raw.githubusercontent.com/williamyang1991/StyleGANEX/main/data/pexels-daniel-xavier-1239291.jpg', 'pexels-daniel-xavier-1239291.jpg') torch.hub.download_url_to_file('https://github.com/williamyang1991/StyleGANEX/raw/main/data/529_2.mp4', '529_2.mp4') torch.hub.download_url_to_file('https://github.com/williamyang1991/StyleGANEX/raw/main/data/684.mp4', '684.mp4') torch.hub.download_url_to_file('https://github.com/williamyang1991/StyleGANEX/raw/main/data/pexels-anthony-shkraba-production-8136210.mp4', 'pexels-anthony-shkraba-production-8136210.mp4') def main(): args = parse_args() args.device = 'cuda' if torch.cuda.is_available() else 'cpu' print('*** Now using %s.'%(args.device)) model = Model(device=args.device) with gr.Blocks(css='style.css') as demo: gr.Markdown(DESCRIPTION) with gr.Tabs(): with gr.TabItem('Inversion for Editing'): create_demo_inversion(model.process_inversion, allow_optimization=False) with gr.TabItem('Image Face Toonify'): create_demo_toonify(model.process_toonify) with gr.TabItem('Video Face Toonify'): create_demo_vtoonify(model.process_vtoonify, max_frame_num=4) with gr.TabItem('Image Face Editing'): create_demo_editing(model.process_editing) with gr.TabItem('Video Face Editing'): create_demo_vediting(model.process_vediting, max_frame_num=4) with gr.TabItem('Sketch2Face'): create_demo_s2f(model.process_s2f) with gr.TabItem('Mask2Face'): create_demo_m2f(model.process_m2f) with gr.TabItem('SR'): create_demo_sr(model.process_sr) gr.Markdown(ARTICLE) gr.Markdown(FOOTER) demo.launch( enable_queue=args.enable_queue, server_port=args.port, share=args.share, ) if __name__ == '__main__': main()