Gemini899 commited on
Commit
faa2fe3
·
verified ·
1 Parent(s): 2137a53

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -4
app.py CHANGED
@@ -1,7 +1,33 @@
1
  import os
 
 
 
2
  import cv2
3
- import gradio as gr
4
  import torch
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  from basicsr.archs.srvgg_arch import SRVGGNetCompact
6
  from gfpgan.utils import GFPGANer
7
  from realesrgan.utils import RealESRGANer
@@ -93,7 +119,7 @@ def inference_internal(img, version, scale):
93
  if h > 3500 or w > 3500:
94
  print('too large size')
95
  return None, None
96
-
97
  if h < 300:
98
  img = cv2.resize(img, (w * 2, h * 2), interpolation=cv2.INTER_LANCZOS4)
99
 
@@ -150,13 +176,13 @@ title = "GFPGAN: Practical Face Restoration Algorithm"
150
  description = r"""Gradio demo Fix for <a href='https://github.com/TencentARC/GFPGAN' target='_blank'><b>GFPGAN: Towards Real-World Blind Face Restoration with Generative Facial Prior</b></a>.<br>
151
  It can be used to restore your **old photos** or improve **AI-generated faces**.<br>
152
  To use it, simply upload your image.<br>
153
- If GFPGAN is helpful, please help to the <a href='https://github.com/Nick088Official/GFPGAN-Fix' target='_blank'>Github Repo</a> and recommend it to your friends 😊
154
  """
155
  article = r"""
156
  [![download](https://img.shields.io/github/downloads/TencentARC/GFPGAN/total.svg)](https://github.com/TencentARC/GFPGAN/releases)
157
  [![GitHub Stars](https://img.shields.io/github/stars/TencentARC/GFPGAN?style=social)](https://github.com/TencentARC/GFPGAN)
158
  [![arXiv](https://img.shields.io/badge/arXiv-Paper-<COLOR>.svg)](https://arxiv.org/abs/2101.04061)
159
- If you have any question, please email 📧 `xintao.wang@outlook.com` or `xintaowang@tencent.com` (original creators).
160
  """
161
 
162
  # Only offer examples for images that actually downloaded.
 
1
  import os
2
+ import sys
3
+ import types
4
+
5
  import cv2
 
6
  import torch
7
+ import torchvision.transforms as _tv_transforms
8
+
9
+ # ---------------------------------------------------------------------------
10
+ # torchvision compatibility shim
11
+ #
12
+ # basicsr (pulled in by gfpgan / realesrgan) does:
13
+ # from torchvision.transforms.functional_tensor import rgb_to_grayscale
14
+ # torchvision removed the `functional_tensor` module in 0.17 (Jan 2024). Since
15
+ # ZeroGPU now requires torch >= 2.8 (=> torchvision >= 0.23), that import would
16
+ # raise ModuleNotFoundError and crash the Space at startup. We register a tiny
17
+ # stand-in module that forwards rgb_to_grayscale, BEFORE basicsr is imported.
18
+ # ---------------------------------------------------------------------------
19
+ try:
20
+ from torchvision.transforms.functional import rgb_to_grayscale as _rgb_to_grayscale
21
+ except Exception: # very new torchvision may only expose it under v2
22
+ from torchvision.transforms.v2.functional import rgb_to_grayscale as _rgb_to_grayscale
23
+
24
+ if 'torchvision.transforms.functional_tensor' not in sys.modules:
25
+ _shim = types.ModuleType('torchvision.transforms.functional_tensor')
26
+ _shim.rgb_to_grayscale = _rgb_to_grayscale
27
+ sys.modules['torchvision.transforms.functional_tensor'] = _shim
28
+ setattr(_tv_transforms, 'functional_tensor', _shim)
29
+
30
+ import gradio as gr
31
  from basicsr.archs.srvgg_arch import SRVGGNetCompact
32
  from gfpgan.utils import GFPGANer
33
  from realesrgan.utils import RealESRGANer
 
119
  if h > 3500 or w > 3500:
120
  print('too large size')
121
  return None, None
122
+
123
  if h < 300:
124
  img = cv2.resize(img, (w * 2, h * 2), interpolation=cv2.INTER_LANCZOS4)
125
 
 
176
  description = r"""Gradio demo Fix for <a href='https://github.com/TencentARC/GFPGAN' target='_blank'><b>GFPGAN: Towards Real-World Blind Face Restoration with Generative Facial Prior</b></a>.<br>
177
  It can be used to restore your **old photos** or improve **AI-generated faces**.<br>
178
  To use it, simply upload your image.<br>
179
+ If GFPGAN is helpful, please help to star the <a href='https://github.com/Nick088Official/GFPGAN-Fix' target='_blank'>Github Repo</a> and recommend it to your friends.
180
  """
181
  article = r"""
182
  [![download](https://img.shields.io/github/downloads/TencentARC/GFPGAN/total.svg)](https://github.com/TencentARC/GFPGAN/releases)
183
  [![GitHub Stars](https://img.shields.io/github/stars/TencentARC/GFPGAN?style=social)](https://github.com/TencentARC/GFPGAN)
184
  [![arXiv](https://img.shields.io/badge/arXiv-Paper-<COLOR>.svg)](https://arxiv.org/abs/2101.04061)
185
+ If you have any question, please email `xintao.wang@outlook.com` or `xintaowang@tencent.com` (original creators).
186
  """
187
 
188
  # Only offer examples for images that actually downloaded.