Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import os
|
|
| 2 |
import sys
|
| 3 |
import subprocess
|
| 4 |
|
| 5 |
-
# --- PHẦN 1: SETUP MÔI TRƯỜNG THỦ CÔNG ---
|
| 6 |
print("⏳ Đang thiết lập môi trường...")
|
| 7 |
|
| 8 |
# 1. Clone CodeFormer
|
|
@@ -10,22 +10,37 @@ if not os.path.exists("CodeFormer"):
|
|
| 10 |
print(" + Cloning CodeFormer...")
|
| 11 |
subprocess.run(["git", "clone", "https://github.com/sczhou/CodeFormer.git"], check=True)
|
| 12 |
|
| 13 |
-
# 2.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
print(" + Compiling BasicSR...")
|
| 15 |
# Kiểm tra xem đã cài chưa
|
| 16 |
if not os.path.exists("CodeFormer/basicsr.egg-info"):
|
| 17 |
-
# Chạy setup.py develop
|
| 18 |
subprocess.run([sys.executable, "basicsr/setup.py", "develop"], cwd="CodeFormer", check=True)
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
# Dùng cờ --no-deps để nó không tự tải basicsr bản lỗi trên mạng về
|
| 22 |
print(" + Installing GFPGAN...")
|
| 23 |
try:
|
| 24 |
import gfpgan
|
| 25 |
except ImportError:
|
| 26 |
subprocess.run([sys.executable, "-m", "pip", "install", "gfpgan", "--no-deps"], check=True)
|
| 27 |
|
| 28 |
-
# Thêm CodeFormer vào path
|
| 29 |
sys.path.append(os.path.join(os.getcwd(), "CodeFormer"))
|
| 30 |
|
| 31 |
# -----------------------------------------------------------
|
|
|
|
| 2 |
import sys
|
| 3 |
import subprocess
|
| 4 |
|
| 5 |
+
# --- PHẦN 1: SETUP MÔI TRƯỜNG THỦ CÔNG (FIX LỖI VERSION & TORCH) ---
|
| 6 |
print("⏳ Đang thiết lập môi trường...")
|
| 7 |
|
| 8 |
# 1. Clone CodeFormer
|
|
|
|
| 10 |
print(" + Cloning CodeFormer...")
|
| 11 |
subprocess.run(["git", "clone", "https://github.com/sczhou/CodeFormer.git"], check=True)
|
| 12 |
|
| 13 |
+
# 2. VÁ LỖI SETUP.PY (QUAN TRỌNG)
|
| 14 |
+
# Lỗi KeyError: '__version__' xảy ra do Python mới không đọc được biến locals() trong exec().
|
| 15 |
+
# Ta sẽ thay thế đoạn code đọc version bằng một chuỗi cứng '1.4.2'.
|
| 16 |
+
setup_file_path = "CodeFormer/basicsr/setup.py"
|
| 17 |
+
if os.path.exists(setup_file_path):
|
| 18 |
+
print(" + Patching setup.py to fix version error...")
|
| 19 |
+
with open(setup_file_path, "r", encoding="utf-8") as f:
|
| 20 |
+
content = f.read()
|
| 21 |
+
|
| 22 |
+
# Thay thế lệnh gọi hàm gây lỗi bằng chuỗi cứng
|
| 23 |
+
# Tìm: version=get_version(), -> Thay bằng: version='1.4.2',
|
| 24 |
+
content = content.replace("version=get_version(),", "version='1.4.2',")
|
| 25 |
+
|
| 26 |
+
with open(setup_file_path, "w", encoding="utf-8") as f:
|
| 27 |
+
f.write(content)
|
| 28 |
+
|
| 29 |
+
# 3. Cài đặt BasicSR từ Source
|
| 30 |
print(" + Compiling BasicSR...")
|
| 31 |
# Kiểm tra xem đã cài chưa
|
| 32 |
if not os.path.exists("CodeFormer/basicsr.egg-info"):
|
| 33 |
+
# Chạy setup.py develop
|
| 34 |
subprocess.run([sys.executable, "basicsr/setup.py", "develop"], cwd="CodeFormer", check=True)
|
| 35 |
|
| 36 |
+
# 4. Cài đặt GFPGAN thủ công (--no-deps)
|
|
|
|
| 37 |
print(" + Installing GFPGAN...")
|
| 38 |
try:
|
| 39 |
import gfpgan
|
| 40 |
except ImportError:
|
| 41 |
subprocess.run([sys.executable, "-m", "pip", "install", "gfpgan", "--no-deps"], check=True)
|
| 42 |
|
| 43 |
+
# Thêm CodeFormer vào path
|
| 44 |
sys.path.append(os.path.join(os.getcwd(), "CodeFormer"))
|
| 45 |
|
| 46 |
# -----------------------------------------------------------
|