File size: 5,218 Bytes
1481a58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c3f9de8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1481a58
 
 
 
 
 
 
 
 
b716e0c
1481a58
 
 
b716e0c
1481a58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
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 = '''
<div align=center>
<h1 style="font-weight: 900; margin-bottom: 7px;">
   Face Manipulation with <a href="https://github.com/williamyang1991/StyleGANEX">StyleGANEX</a>
</h1>
<p>For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings. 
<a href="https://huggingface.co/spaces/PKUWilliamYang/StyleGANEX?duplicate=true"><img style="display: inline; margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space" /></a></p>
<p/>
<img style="margin-top: 0em" src="https://raw.githubusercontent.com/williamyang1991/tmpfile/master/imgs/example.jpg" alt="example">
</div>
'''
ARTICLE = r"""
If StyleGANEX is helpful, please help to ⭐ the <a href='https://github.com/williamyang1991/StyleGANEX' target='_blank'>Github Repo</a>. 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 <a rel="license" href="https://github.com/williamyang1991/VToonify/blob/main/LICENSE.md">S-Lab License 1.0</a>. 
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 <b>williamyang@pku.edu.cn</b>.
"""

FOOTER = '<div align=center><img id="visitor-badge" alt="visitor badge" src="https://visitor-badge.laobi.icu/badge?page_id=williamyang1991/styleganex" /></div>'

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)


    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')    

    
    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=12)                      
            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=12)               
            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()