TienVu2204 commited on
Commit
c321f55
·
verified ·
1 Parent(s): 3ba2c8f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -14
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 (FIX LỖI VERSION & TORCH) ---
6
  print("⏳ Đang thiết lập môi trường...")
7
 
8
  # 1. Clone CodeFormer
@@ -10,37 +10,33 @@ 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. 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
  # -----------------------------------------------------------
 
2
  import sys
3
  import subprocess
4
 
5
+ # --- PHẦN 1: SETUP MÔI TRƯỜNG THỦ CÔNG (FIX TRIỆT ĐỂ) ---
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 VERSION TRONG SETUP.PY
14
+ # File setup.py nằm CodeFormer/basicsr/setup.py
 
15
  setup_file_path = "CodeFormer/basicsr/setup.py"
16
  if os.path.exists(setup_file_path):
17
  print(" + Patching setup.py to fix version error...")
18
  with open(setup_file_path, "r", encoding="utf-8") as f:
19
  content = f.read()
 
 
 
20
  content = content.replace("version=get_version(),", "version='1.4.2',")
 
21
  with open(setup_file_path, "w", encoding="utf-8") as f:
22
  f.write(content)
23
 
24
+ # 3. CÀI ĐẶT BASICSR (FIX LỖI PATH)
25
  print(" + Compiling BasicSR...")
26
+ # Thay đổi thư mục làm việc vào trong nơi chứa setup.py để chạy lệnh
27
  if not os.path.exists("CodeFormer/basicsr.egg-info"):
28
+ # Chuyển vào thư mục CodeFormer/basicsr nơi chứa setup.py
29
+ # Lưu ý: Lệnh này sẽ cài package basicsr vào môi trường hiện tại
30
+ subprocess.run([sys.executable, "setup.py", "develop"], cwd="CodeFormer/basicsr", check=True)
31
 
32
+ # 4. CÀI ĐẶT GFPGAN
33
  print(" + Installing GFPGAN...")
34
  try:
35
  import gfpgan
36
  except ImportError:
37
  subprocess.run([sys.executable, "-m", "pip", "install", "gfpgan", "--no-deps"], check=True)
38
 
39
+ # Thêm CodeFormer vào path để code Python tìm thấy các module khác
40
  sys.path.append(os.path.join(os.getcwd(), "CodeFormer"))
41
 
42
  # -----------------------------------------------------------