iamvishalksingh commited on
Commit
b285b6c
·
verified ·
1 Parent(s): 9b79be3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py CHANGED
@@ -5,6 +5,44 @@ from PIL import Image
5
  import torch
6
  import uvicorn
7
  import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  # Import the CodeFormer model processing function
10
  from codeformer_model import enhance_image # Make sure this function is defined
 
5
  import torch
6
  import uvicorn
7
  import os
8
+ import sys
9
+ sys.path.append('CodeFormer')
10
+ import os
11
+ import cv2
12
+ import torch
13
+ import torch.nn.functional as F
14
+ import gradio as gr
15
+
16
+ from torchvision.transforms.functional import normalize
17
+
18
+ from basicsr.utils import imwrite, img2tensor, tensor2img
19
+ from basicsr.utils.download_util import load_file_from_url
20
+ from facelib.utils.face_restoration_helper import FaceRestoreHelper
21
+ from basicsr.archs.rrdbnet_arch import RRDBNet
22
+ from basicsr.utils.realesrgan_utils import RealESRGANer
23
+ from facelib.utils.misc import is_gray
24
+
25
+ from basicsr.utils.registry import ARCH_REGISTRY
26
+
27
+
28
+ os.system("pip freeze")
29
+
30
+ pretrain_model_url = {
31
+ 'codeformer': 'https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/codeformer.pth',
32
+ 'detection': 'https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/detection_Resnet50_Final.pth',
33
+ 'parsing': 'https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/parsing_parsenet.pth',
34
+ 'realesrgan': 'https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/RealESRGAN_x2plus.pth'
35
+ }
36
+ # download weights
37
+ if not os.path.exists('CodeFormer/weights/CodeFormer/codeformer.pth'):
38
+ load_file_from_url(url=pretrain_model_url['codeformer'], model_dir='CodeFormer/weights/CodeFormer', progress=True, file_name=None)
39
+ if not os.path.exists('CodeFormer/weights/facelib/detection_Resnet50_Final.pth'):
40
+ load_file_from_url(url=pretrain_model_url['detection'], model_dir='CodeFormer/weights/facelib', progress=True, file_name=None)
41
+ if not os.path.exists('CodeFormer/weights/facelib/parsing_parsenet.pth'):
42
+ load_file_from_url(url=pretrain_model_url['parsing'], model_dir='CodeFormer/weights/facelib', progress=True, file_name=None)
43
+ if not os.path.exists('CodeFormer/weights/realesrgan/RealESRGAN_x2plus.pth'):
44
+ load_file_from_url(url=pretrain_model_url['realesrgan'], model_dir='CodeFormer/weights/realesrgan', progress=True, file_name=None)
45
+
46
 
47
  # Import the CodeFormer model processing function
48
  from codeformer_model import enhance_image # Make sure this function is defined