renatotn7 commited on
Commit
160b451
·
1 Parent(s): 5fe0034

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -2
app.py CHANGED
@@ -2,5 +2,66 @@ import streamlit as st
2
  import os
3
  os.system("pip install git+https://github.com/TencentARC/GFPGAN.git")
4
 
5
- x = st.slider('Select a value')
6
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import os
3
  os.system("pip install git+https://github.com/TencentARC/GFPGAN.git")
4
 
5
+ #os.system("pip freeze")
6
+ #os.system("wget https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth -P .")
7
+ import random
8
+ import gradio as gr
9
+ from PIL import Image
10
+ import torch
11
+ # 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')
12
+ # torch.hub.download_url_to_file('https://upload.wikimedia.org/wikipedia/commons/5/50/Albert_Einstein_%28Nobel%29.png', 'einstein.png')
13
+ # torch.hub.download_url_to_file('https://upload.wikimedia.org/wikipedia/commons/thumb/9/9d/Thomas_Edison2.jpg/1024px-Thomas_Edison2.jpg', 'edison.jpg')
14
+ # 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')
15
+ # 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')
16
+
17
+
18
+ import cv2
19
+ import glob
20
+ import numpy as np
21
+ from basicsr.utils import imwrite
22
+ from gfpgan import GFPGANer
23
+
24
+ bg_upsampler = None
25
+
26
+
27
+
28
+ # set up GFPGAN restorer
29
+ restorer = GFPGANer(
30
+ model_path='experiments/pretrained_models/GFPGANv1.3.pth',
31
+ upscale=2,
32
+ arch='clean',
33
+ channel_multiplier=2,
34
+ bg_upsampler=bg_upsampler)
35
+
36
+
37
+ def inference(img):
38
+ input_img = cv2.imread(img, cv2.IMREAD_COLOR)
39
+ cropped_faces, restored_faces, restored_img = restorer.enhance(
40
+ input_img, has_aligned=False, only_center_face=False, paste_back=True)
41
+
42
+ #return Image.fromarray(restored_faces[0][:,:,::-1])
43
+ return Image.fromarray(restored_img[:, :, ::-1])
44
+
45
+ title = "让美好回忆更清晰"
46
+
47
+
48
+ description = "上传老照片,点击Submit,稍等片刻,右侧Output将照片另存为即可。"
49
+
50
+ 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>"
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
+