Siam2315 commited on
Commit
e43e12b
·
verified ·
1 Parent(s): 0fee83a

Create app.py

Browse files
Files changed (1) hide show
  1. CodeFormer/app.py +38 -0
CodeFormer/app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import torch
4
+ import cv2
5
+ from CodeFormer.inference_codeformer import main as codeformer_infer
6
+
7
+ def restore_face(image):
8
+ input_path = "input.jpg"
9
+ output_path = "output.png"
10
+
11
+ cv2.imwrite(input_path, cv2.cvtColor(image, cv2.COLOR_RGB2BGR))
12
+
13
+ args = type('', (), {})()
14
+ args.input_path = input_path
15
+ args.output_path = output_path
16
+ args.background_enhance = True
17
+ args.face_upsample = True
18
+ args.upscale = 2
19
+ args.weight = 0.5
20
+ args.has_aligned = False
21
+ args.only_center_face = False
22
+ args.device = "cpu"
23
+
24
+ codeformer_infer(args)
25
+
26
+ output = cv2.imread(output_path)
27
+ output = cv2.cvtColor(output, cv2.COLOR_BGR2RGB)
28
+
29
+ return output
30
+
31
+ demo = gr.Interface(
32
+ fn=restore_face,
33
+ inputs=gr.Image(type="numpy"),
34
+ outputs=gr.Image(type="numpy"),
35
+ title="CodeFormer Face Restore",
36
+ )
37
+
38
+ demo.launch()