Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,27 @@
|
|
1 |
-
import cv2
|
2 |
import gradio as gr
|
|
|
3 |
import numpy as np
|
|
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))
|
15 |
-
l_clahe = clahe.apply(l)
|
16 |
-
|
17 |
-
# 再度チャンネルを統合し、LabからBGRに戻す
|
18 |
-
lab_clahe = cv2.merge((l_clahe, a, b))
|
19 |
-
corrected_image = cv2.cvtColor(lab_clahe, cv2.COLOR_Lab2BGR)
|
20 |
|
21 |
-
|
|
|
22 |
|
23 |
# Gradioインターフェースの作成
|
24 |
-
iface = gr.Interface(
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
description="画像をアップロードして顔の色と明るさ補正を行います。CLAHEを使用してコントラストを最適化しています。"
|
30 |
-
)
|
31 |
|
32 |
-
#
|
33 |
iface.launch()
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import cv2
|
3 |
import numpy as np
|
4 |
+
from gfpgan import GFPGANer
|
5 |
|
6 |
+
# GFPGANerの初期化
|
7 |
+
restorer = GFPGANer(model_path='https://github.com/TencentARC/GFPGAN/releases/download/v1.3.4/GFPGANv1.4.pth',
|
8 |
+
upscale=2, arch='clean', channel_multiplier=2)
|
9 |
+
|
10 |
+
# 画像補正関数
|
11 |
+
def restore_faces(input_img):
|
12 |
+
# 入力画像を処理
|
13 |
+
img = np.array(input_img)
|
14 |
+
_, restored_img, _ = restorer.enhance(img, has_aligned=False, only_center_face=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
# 補正後の画像を返す
|
17 |
+
return restored_img
|
18 |
|
19 |
# Gradioインターフェースの作成
|
20 |
+
iface = gr.Interface(fn=restore_faces,
|
21 |
+
inputs=gr.Image(type="numpy"),
|
22 |
+
outputs="image",
|
23 |
+
title="AI生成顔をGFPGANで補正",
|
24 |
+
description="AIで生成された顔画像をGFPGANを使って補正します。")
|
|
|
|
|
25 |
|
26 |
+
# アプリケーションを起動
|
27 |
iface.launch()
|