LogicGoInfotechSpaces commited on
Commit
51051dc
·
verified ·
1 Parent(s): 541ad32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -8
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
- # FIX: Must cd into CodeFormer directory so setup.py can find ./basicsr/VERSION
169
- if os.path.exists("CodeFormer/basicsr/setup.py"):
170
- logger.info("Installing BasicSR from local directory...")
171
- subprocess.run(
172
- "cd CodeFormer && python basicsr/setup.py develop",
173
- shell=True, check=True, timeout=120
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"