aamsko commited on
Commit
5e30dca
·
verified ·
1 Parent(s): c9552b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -50
app.py CHANGED
@@ -1,50 +1,50 @@
1
- import gradio as gr
2
- import os
3
- import cv2
4
- import torch
5
- import numpy as np
6
- from PIL import Image
7
- from gfpgan import GFPGANer
8
-
9
- # Download GFPGAN model if not already present
10
- model_url = "https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.4.pth"
11
- model_path = "GFPGANv1.4.pth"
12
-
13
- if not os.path.exists(model_path):
14
- import requests
15
- r = requests.get(model_url, allow_redirects=True)
16
- open(model_path, 'wb').write(r.content)
17
-
18
- # Initialize GFPGAN
19
- restorer = GFPGANer(
20
- model_path=model_path,
21
- upscale=2,
22
- arch='clean',
23
- channel_multiplier=2,
24
- bg_upsampler=None
25
- )
26
-
27
- def enhance(image):
28
- # Convert PIL to numpy
29
- img = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
30
-
31
- _, _, restored_img = restorer.enhance(
32
- img,
33
- has_aligned=False,
34
- only_center_face=False,
35
- paste_back=True
36
- )
37
-
38
- restored_pil = Image.fromarray(cv2.cvtColor(restored_img, cv2.COLOR_BGR2RGB))
39
- return restored_pil
40
-
41
- iface = gr.Interface(
42
- fn=enhance,
43
- inputs=gr.Image(type="pil"),
44
- outputs="image",
45
- title="IMGEN - AI Photo Enhancer",
46
- description="Upload your photo (ID, CV, profile) and enhance it with AI using GFPGAN."
47
- )
48
-
49
- if __name__ == "__main__":
50
- iface.launch()
 
1
+ import gradio as gr
2
+ import os
3
+ import cv2
4
+ import torch
5
+ import numpy as np
6
+ from PIL import Image
7
+ from gfpgan import GFPGANer
8
+
9
+ # Download GFPGAN model if not already present
10
+ model_url = "https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.4.pth"
11
+ model_path = "GFPGANv1.4.pth"
12
+
13
+ if not os.path.exists(model_path):
14
+ import requests
15
+ r = requests.get(model_url, allow_redirects=True)
16
+ open(model_path, 'wb').write(r.content)
17
+
18
+ # Initialize GFPGAN
19
+ restorer = GFPGANer(
20
+ model_path=model_path,
21
+ upscale=2,
22
+ arch='clean',
23
+ channel_multiplier=2,
24
+ bg_upsampler=None
25
+ )
26
+
27
+ def enhance(image):
28
+ # Convert PIL to numpy
29
+ img = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
30
+
31
+ _, _, restored_img = restorer.enhance(
32
+ img,
33
+ has_aligned=False,
34
+ only_center_face=False,
35
+ paste_back=True
36
+ )
37
+
38
+ restored_pil = Image.fromarray(cv2.cvtColor(restored_img, cv2.COLOR_BGR2RGB))
39
+ return restored_pil
40
+
41
+ iface = gr.Interface(
42
+ fn=enhance,
43
+ inputs=gr.Image(type="pil"),
44
+ outputs="image",
45
+ title="IMGEN - AI Photo Enhancer",
46
+ description="Upload your photo (ID, CV, profile) and enhance it with AI using GFPGAN."
47
+ )
48
+
49
+ if __name__ == "__main__":
50
+ iface.launch()