Spaces:
Running
on
T4
Running
on
T4
Update app.py
Browse files
app.py
CHANGED
|
@@ -159,20 +159,24 @@ except Exception as e:
|
|
| 159 |
CODEFORMER_PATH = "CodeFormer/inference_codeformer.py"
|
| 160 |
|
| 161 |
def ensure_codeformer():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
try:
|
| 163 |
if not os.path.exists("CodeFormer"):
|
| 164 |
logger.info("CodeFormer not found, cloning repository...")
|
| 165 |
subprocess.run("git clone https://github.com/sczhou/CodeFormer.git", shell=True, check=True)
|
| 166 |
subprocess.run("pip install -r CodeFormer/requirements.txt", shell=True, check=False)
|
| 167 |
|
| 168 |
-
#
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
)
|
| 175 |
-
logger.info("BasicSR installed successfully")
|
| 176 |
|
| 177 |
try:
|
| 178 |
import realesrgan
|
|
@@ -180,8 +184,11 @@ def ensure_codeformer():
|
|
| 180 |
except ImportError:
|
| 181 |
logger.info("Installing RealESRGAN...")
|
| 182 |
subprocess.run("pip install --no-cache-dir realesrgan", shell=True, check=True, timeout=120)
|
|
|
|
|
|
|
| 183 |
logger.info("RealESRGAN installed successfully")
|
| 184 |
|
|
|
|
| 185 |
if os.path.exists("CodeFormer"):
|
| 186 |
try:
|
| 187 |
subprocess.run("python CodeFormer/scripts/download_pretrained_models.py facelib", shell=True, check=False, timeout=300)
|
|
@@ -1992,6 +1999,7 @@ if __name__ == "__main__":
|
|
| 1992 |
|
| 1993 |
|
| 1994 |
|
|
|
|
| 1995 |
# #####################FASTAPI___________________##############
|
| 1996 |
# import os
|
| 1997 |
# os.environ["OMP_NUM_THREADS"] = "1"
|
|
|
|
| 159 |
CODEFORMER_PATH = "CodeFormer/inference_codeformer.py"
|
| 160 |
|
| 161 |
def ensure_codeformer():
|
| 162 |
+
"""
|
| 163 |
+
Ensure CodeFormer's local basicsr + facelib are importable and
|
| 164 |
+
pretrained weights are downloaded. No setup.py needed — we use
|
| 165 |
+
sys.path / PYTHONPATH instead.
|
| 166 |
+
"""
|
| 167 |
try:
|
| 168 |
if not os.path.exists("CodeFormer"):
|
| 169 |
logger.info("CodeFormer not found, cloning repository...")
|
| 170 |
subprocess.run("git clone https://github.com/sczhou/CodeFormer.git", shell=True, check=True)
|
| 171 |
subprocess.run("pip install -r CodeFormer/requirements.txt", shell=True, check=False)
|
| 172 |
|
| 173 |
+
# Add CodeFormer root to sys.path so `import basicsr` and
|
| 174 |
+
# `import facelib` resolve to the local (compatible) versions
|
| 175 |
+
# instead of the broken PyPI basicsr==1.4.2.
|
| 176 |
+
codeformer_root = os.path.join(os.getcwd(), "CodeFormer")
|
| 177 |
+
if codeformer_root not in sys.path:
|
| 178 |
+
sys.path.insert(0, codeformer_root)
|
| 179 |
+
logger.info(f"Added {codeformer_root} to sys.path for local basicsr/facelib")
|
|
|
|
| 180 |
|
| 181 |
try:
|
| 182 |
import realesrgan
|
|
|
|
| 184 |
except ImportError:
|
| 185 |
logger.info("Installing RealESRGAN...")
|
| 186 |
subprocess.run("pip install --no-cache-dir realesrgan", shell=True, check=True, timeout=120)
|
| 187 |
+
# Uninstall the broken PyPI basicsr that realesrgan pulls in
|
| 188 |
+
subprocess.run("pip uninstall -y basicsr", shell=True, check=False, timeout=30)
|
| 189 |
logger.info("RealESRGAN installed successfully")
|
| 190 |
|
| 191 |
+
# Download pretrained weights if not already present
|
| 192 |
if os.path.exists("CodeFormer"):
|
| 193 |
try:
|
| 194 |
subprocess.run("python CodeFormer/scripts/download_pretrained_models.py facelib", shell=True, check=False, timeout=300)
|
|
|
|
| 1999 |
|
| 2000 |
|
| 2001 |
|
| 2002 |
+
|
| 2003 |
# #####################FASTAPI___________________##############
|
| 2004 |
# import os
|
| 2005 |
# os.environ["OMP_NUM_THREADS"] = "1"
|