soiz commited on
Commit
68b971d
·
verified ·
1 Parent(s): ba5ef6b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -25
app.py CHANGED
@@ -1,33 +1,27 @@
1
- import cv2
2
  import gradio as gr
 
3
  import numpy as np
 
4
 
5
- # 顔の補正関数
6
- def correct_face(image):
7
- # BGR(OpenCVのデフォルト)からLab色空間に変換
8
- lab = cv2.cvtColor(image, cv2.COLOR_BGR2Lab)
9
-
10
- # LabのLチャンネル(輝度)を取得
11
- l, a, b = cv2.split(lab)
12
-
13
- # CLAHE(局所的ヒストグラム均等化)を適用
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
- return corrected_image
 
22
 
23
  # Gradioインターフェースの作成
24
- iface = gr.Interface(
25
- fn=correct_face,
26
- inputs=gr.Image(type="numpy"),
27
- outputs=gr.Image(type="numpy"),
28
- title="顔補正アプリ",
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()