tjxj commited on
Commit
356c9a0
1 Parent(s): 88644d0
.history/app_20220327222543.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ os.system("pip install gfpgan")
3
+
4
+ #os.system("pip freeze")
5
+ #os.system("wget https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth -P .")
6
+ import random
7
+ import gradio as gr
8
+ from PIL import Image
9
+ import torch
10
+ # torch.hub.download_url_to_file('https://upload.wikimedia.org/wikipedia/commons/thumb/a/ab/Abraham_Lincoln_O-77_matte_collodion_print.jpg/1024px-Abraham_Lincoln_O-77_matte_collodion_print.jpg', 'lincoln.jpg')
11
+ # torch.hub.download_url_to_file('https://upload.wikimedia.org/wikipedia/commons/5/50/Albert_Einstein_%28Nobel%29.png', 'einstein.png')
12
+ # torch.hub.download_url_to_file('https://upload.wikimedia.org/wikipedia/commons/thumb/9/9d/Thomas_Edison2.jpg/1024px-Thomas_Edison2.jpg', 'edison.jpg')
13
+ # torch.hub.download_url_to_file('https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/Henry_Ford_1888.jpg/1024px-Henry_Ford_1888.jpg', 'Henry.jpg')
14
+ # torch.hub.download_url_to_file('https://upload.wikimedia.org/wikipedia/commons/thumb/0/06/Frida_Kahlo%2C_by_Guillermo_Kahlo.jpg/800px-Frida_Kahlo%2C_by_Guillermo_Kahlo.jpg', 'Frida.jpg')
15
+
16
+
17
+ import cv2
18
+ import glob
19
+ import numpy as np
20
+ from basicsr.utils import imwrite
21
+ from gfpgan import GFPGANer
22
+
23
+ bg_upsampler = None
24
+
25
+
26
+
27
+ # set up GFPGAN restorer
28
+ restorer = GFPGANer(
29
+ model_path='experiments/pretrained_models/GFPGANv1.3.pth',
30
+ upscale=2,
31
+ arch='clean',
32
+ channel_multiplier=2,
33
+ bg_upsampler=bg_upsampler)
34
+
35
+
36
+ def inference(img):
37
+ input_img = cv2.imread(img, cv2.IMREAD_COLOR)
38
+ cropped_faces, restored_faces, restored_img = restorer.enhance(
39
+ input_img, has_aligned=False, only_center_face=False, paste_back=True)
40
+
41
+ #return Image.fromarray(restored_faces[0][:,:,::-1])
42
+ return Image.fromarray(restored_img[:, :, ::-1])
43
+
44
+ title = "让美好回忆更清晰"
45
+
46
+
47
+ description = "上传老照片,点击Submit,稍等片刻,右侧Output将照片另存为即可。"
48
+
49
+ article = "<p style='text-align: center'><a href='https://huggingface.co/spaces/akhaliq/GFPGAN/' target='_blank'>本项目克隆自akhaliq@huggingface,稍作修改</a> | <a href='https://github.com/TencentARC/GFPGAN' target='_blank'>GFPGAN Github Repo</a></p><center><img src='https://visitor-badge.glitch.me/badge?page_id=akhaliq_GFPGAN' alt='visitor badge'></center>"
50
+
51
+ gr.Interface(
52
+ inference,
53
+ [gr.inputs.Image(type="filepath", label="Input")],
54
+ gr.outputs.Image(type="pil", label="Output"),
55
+ title=title,
56
+ description=description,
57
+ article=article,
58
+ examples=[
59
+ ['lincoln.jpg'],
60
+ ['einstein.png'],
61
+ ['edison.jpg'],
62
+ ['Henry.jpg'],
63
+ ['Frida.jpg']
64
+ ]
65
+ ).launch(enable_queue=True,cache_examples=True,share=True)
66
+
67
+
.history/app_20220327222818.py ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ os.system("pip install gfpgan")
3
+
4
+ #os.system("pip freeze")
5
+ #os.system("wget https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth -P .")
6
+ import random
7
+ import gradio as gr
8
+ from PIL import Image
9
+ import torch
10
+ # torch.hub.download_url_to_file('https://upload.wikimedia.org/wikipedia/commons/thumb/a/ab/Abraham_Lincoln_O-77_matte_collodion_print.jpg/1024px-Abraham_Lincoln_O-77_matte_collodion_print.jpg', 'lincoln.jpg')
11
+ # torch.hub.download_url_to_file('https://upload.wikimedia.org/wikipedia/commons/5/50/Albert_Einstein_%28Nobel%29.png', 'einstein.png')
12
+ # torch.hub.download_url_to_file('https://upload.wikimedia.org/wikipedia/commons/thumb/9/9d/Thomas_Edison2.jpg/1024px-Thomas_Edison2.jpg', 'edison.jpg')
13
+ # torch.hub.download_url_to_file('https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/Henry_Ford_1888.jpg/1024px-Henry_Ford_1888.jpg', 'Henry.jpg')
14
+ # torch.hub.download_url_to_file('https://upload.wikimedia.org/wikipedia/commons/thumb/0/06/Frida_Kahlo%2C_by_Guillermo_Kahlo.jpg/800px-Frida_Kahlo%2C_by_Guillermo_Kahlo.jpg', 'Frida.jpg')
15
+
16
+
17
+ import cv2
18
+ import glob
19
+ import numpy as np
20
+ from basicsr.utils import imwrite
21
+ from gfpgan import GFPGANer
22
+
23
+ bg_upsampler = None
24
+
25
+
26
+
27
+ # set up GFPGAN restorer
28
+ restorer = GFPGANer(
29
+ model_path='experiments/pretrained_models/GFPGANv1.3.pth',
30
+ upscale=2,
31
+ arch='clean',
32
+ channel_multiplier=2,
33
+ bg_upsampler=bg_upsampler)
34
+
35
+
36
+ def inference(img):
37
+ input_img = cv2.imread(img, cv2.IMREAD_COLOR)
38
+ cropped_faces, restored_faces, restored_img = restorer.enhance(
39
+ input_img, has_aligned=False, only_center_face=False, paste_back=True)
40
+
41
+ #return Image.fromarray(restored_faces[0][:,:,::-1])
42
+ return Image.fromarray(restored_img[:, :, ::-1])
43
+
44
+ title = "让美好回忆更清晰"
45
+
46
+
47
+ description = "上传老照片,点击Submit,稍等片刻,右侧Output将照片另存为即可。"
48
+
49
+ article = "<p style='text-align: center'><a href='https://huggingface.co/spaces/akhaliq/GFPGAN/' target='_blank'>clone from akhaliq@huggingface with little change
50
+ </a> | <a href='https://github.com/TencentARC/GFPGAN' target='_blank'>GFPGAN Github Repo</a></p><center><img src='https://visitor-badge.glitch.me/badge?page_id=akhaliq_GFPGAN' alt='visitor badge'></center>"
51
+
52
+ gr.Interface(
53
+ inference,
54
+ [gr.inputs.Image(type="filepath", label="Input")],
55
+ gr.outputs.Image(type="pil", label="Output"),
56
+ title=title,
57
+ description=description,
58
+ article=article,
59
+ examples=[
60
+ ['lincoln.jpg'],
61
+ ['einstein.png'],
62
+ ['edison.jpg'],
63
+ ['Henry.jpg'],
64
+ ['Frida.jpg']
65
+ ]
66
+ ).launch(enable_queue=True,cache_examples=True,share=True)
67
+
68
+
.history/app_20220327222821.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ os.system("pip install gfpgan")
3
+
4
+ #os.system("pip freeze")
5
+ #os.system("wget https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth -P .")
6
+ import random
7
+ import gradio as gr
8
+ from PIL import Image
9
+ import torch
10
+ # torch.hub.download_url_to_file('https://upload.wikimedia.org/wikipedia/commons/thumb/a/ab/Abraham_Lincoln_O-77_matte_collodion_print.jpg/1024px-Abraham_Lincoln_O-77_matte_collodion_print.jpg', 'lincoln.jpg')
11
+ # torch.hub.download_url_to_file('https://upload.wikimedia.org/wikipedia/commons/5/50/Albert_Einstein_%28Nobel%29.png', 'einstein.png')
12
+ # torch.hub.download_url_to_file('https://upload.wikimedia.org/wikipedia/commons/thumb/9/9d/Thomas_Edison2.jpg/1024px-Thomas_Edison2.jpg', 'edison.jpg')
13
+ # torch.hub.download_url_to_file('https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/Henry_Ford_1888.jpg/1024px-Henry_Ford_1888.jpg', 'Henry.jpg')
14
+ # torch.hub.download_url_to_file('https://upload.wikimedia.org/wikipedia/commons/thumb/0/06/Frida_Kahlo%2C_by_Guillermo_Kahlo.jpg/800px-Frida_Kahlo%2C_by_Guillermo_Kahlo.jpg', 'Frida.jpg')
15
+
16
+
17
+ import cv2
18
+ import glob
19
+ import numpy as np
20
+ from basicsr.utils import imwrite
21
+ from gfpgan import GFPGANer
22
+
23
+ bg_upsampler = None
24
+
25
+
26
+
27
+ # set up GFPGAN restorer
28
+ restorer = GFPGANer(
29
+ model_path='experiments/pretrained_models/GFPGANv1.3.pth',
30
+ upscale=2,
31
+ arch='clean',
32
+ channel_multiplier=2,
33
+ bg_upsampler=bg_upsampler)
34
+
35
+
36
+ def inference(img):
37
+ input_img = cv2.imread(img, cv2.IMREAD_COLOR)
38
+ cropped_faces, restored_faces, restored_img = restorer.enhance(
39
+ input_img, has_aligned=False, only_center_face=False, paste_back=True)
40
+
41
+ #return Image.fromarray(restored_faces[0][:,:,::-1])
42
+ return Image.fromarray(restored_img[:, :, ::-1])
43
+
44
+ title = "让美好回忆更清晰"
45
+
46
+
47
+ description = "上传老照片,点击Submit,稍等片刻,右侧Output将照片另存为即可。"
48
+
49
+ article = "<p style='text-align: center'><a href='https://huggingface.co/spaces/akhaliq/GFPGAN/' target='_blank'>clone from akhaliq@huggingface with little change</a> | <a href='https://github.com/TencentARC/GFPGAN' target='_blank'>GFPGAN Github Repo</a></p><center><img src='https://visitor-badge.glitch.me/badge?page_id=akhaliq_GFPGAN' alt='visitor badge'></center>"
50
+
51
+ gr.Interface(
52
+ inference,
53
+ [gr.inputs.Image(type="filepath", label="Input")],
54
+ gr.outputs.Image(type="pil", label="Output"),
55
+ title=title,
56
+ description=description,
57
+ article=article,
58
+ examples=[
59
+ ['lincoln.jpg'],
60
+ ['einstein.png'],
61
+ ['edison.jpg'],
62
+ ['Henry.jpg'],
63
+ ['Frida.jpg']
64
+ ]
65
+ ).launch(enable_queue=True,cache_examples=True,share=True)
66
+
67
+
app.py CHANGED
@@ -46,7 +46,7 @@ title = "让美好回忆更清晰"
46
 
47
  description = "上传老照片,点击Submit,稍等片刻,右侧Output将照片另存为即可。"
48
 
49
- article = "<p style='text-align: center'><a href='https://huggingface.co/spaces/akhaliq/GFPGAN/' target='_blank'>本项目克隆自akhaliq@huggingface,稍作修改</a> | <a href='https://github.com/TencentARC/GFPGAN' target='_blank'>GFPGAN Github Repo</a></p><center><img src='https://visitor-badge.glitch.me/badge?page_id=akhaliq_GFPGAN' alt='visitor badge'></center>"
50
 
51
  gr.Interface(
52
  inference,
 
46
 
47
  description = "上传老照片,点击Submit,稍等片刻,右侧Output将照片另存为即可。"
48
 
49
+ article = "<p style='text-align: center'><a href='https://huggingface.co/spaces/akhaliq/GFPGAN/' target='_blank'>clone from akhaliq@huggingface with little change</a> | <a href='https://github.com/TencentARC/GFPGAN' target='_blank'>GFPGAN Github Repo</a></p><center><img src='https://visitor-badge.glitch.me/badge?page_id=akhaliq_GFPGAN' alt='visitor badge'></center>"
50
 
51
  gr.Interface(
52
  inference,