File size: 3,327 Bytes
40ce629
 
 
 
 
 
f57ed6a
40ce629
f57ed6a
119d5c2
f57ed6a
40ce629
f57ed6a
98a2239
40ce629
 
51f1e70
38a5e47
cc52c45
 
c405107
51f1e70
0025f06
 
 
18f9c41
 
0025f06
40ce629
 
092a462
fe030b4
b703853
 
40ce629
27f8154
40ce629
 
 
972a2bf
 
 
abe9d47
 
 
 
 
 
 
 
 
 
 
 
39868fe
5266bb1
ae8b571
 
 
 
 
 
 
 
 
b0dd76b
a997257
5266bb1
 
 
d603fa9
c80e976
40e259d
1f683a7
 
 
 
 
7f59eee
ae8b571
b0dd76b
 
a997257
5266bb1
b0dd76b
2ed7e26
 
 
 
 
 
 
 
 
 
 
 
 
40e259d
ae8b571
 
 
 
 
 
40e259d
78f6e98
 
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
#!/usr/bin/env python

from __future__ import annotations

import argparse
import functools
import os
import pickle
import sys
import subprocess

import gradio as gr
import numpy as np
import torch
import torch.nn as nn
from huggingface_hub import hf_hub_download
from transformers import pipeline

sys.path.append('.')
sys.path.append('./Time_TravelRephotography')
from utils import torch_helpers as th
from argparse import Namespace
from projector import (
    ProjectorArguments,
    main,
    create_generator,
    make_image,
)
sys.path.insert(0, 'StyleGAN-Human')

input_path = ''
spectral_sensitivity =  'b'
TITLE = 'Time-TravelRephotography'
DESCRIPTION = '''This is an unofficial demo for https://github.com/Time-Travel-Rephotography.
'''
ARTICLE = '<center><img src="https://visitor-badge.glitch.me/badge?page_id=Time-TravelRephotography" alt="visitor badge"/></center>'

TOKEN = "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"


pipe = pipeline("translation", model="Helsinki-NLP/opus-mt-en-es")

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('--live', action='store_true')
    parser.add_argument('--share', action='store_true')
    parser.add_argument('--port', type=int)
    parser.add_argument('--disable-queue',
                        dest='enable_queue',
                        action='store_false')
    parser.add_argument('--allow-flagging', type=str, default='never')
    return parser.parse_args()
   
def image_create(input_img):
    args = ProjectorArguments().parse(
        args=[str(input_path)],
        namespace=Namespace(
            spectral_sensitivity=spectral_sensitivity,
            encoder_ckpt=f"checkpoint/encoder/checkpoint_{spectral_sensitivity}.pt",
            encoder_name=spectral_sensitivity,
            #gaussian=gaussian_radius,
            log_visual_freq=1000,
            input='text',
        )
    generator = create_generator("stylegan2-ffhq-config-f.pt","feng2022/Time-TravelRephotography_stylegan2-ffhq-config-f",args,device)
    latent = torch.randn((1, 512), device=device) 
    img_out, _, _ = generator([latent])
    imgs_arr = make_image(img_out)
    return imgs_arr[0].cpu().numpy()
    
def main():
    #torch.cuda.init()
    #if torch.cuda.is_initialized():
    #    ini = "True1"
    #else:
    #    ini = "False1"
    #result = subprocess.check_output(['nvidia-smi'])
    args = parse_args()
    device = th.device()
    func = functools.partial(image_create, device=device)
    func = functools.update_wrapper(func, image_create)
    iface = gr.Interface(
          func, 
          [
                gr.inputs.Number(default=0, label='Seed'),
                gr.inputs.Slider(
                    0, 2, step=0.05, default=0.7, label='Truncation psi'),
          ],
          gr.outputs.Image(type='numpy', label='Output'),
          title=TITLE,
          description=DESCRIPTION,
          article=ARTICLE,
          theme=args.theme,
          allow_flagging=args.allow_flagging,
          live=args.live,
          )
    
    iface.launch(
        enable_queue=args.enable_queue,
        server_port=args.port,
        share=args.share,
        )
        
if __name__ == '__main__':
    main()