Madiy commited on
Commit
8f00a47
·
verified ·
1 Parent(s): 7b09ab9

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -40,11 +40,8 @@ try:
40
  except ImportError:
41
  brisque = None
42
 
43
- # ================================================================
44
- # 3. DDColor import — path FIRST, then import
45
- # ================================================================
46
- sys.path.insert(0, os.path.join(os.path.dirname(__file__), "DDColor"))
47
- from ddcolor import DDColor
48
  # ================================================================
49
  # 5. LOAD ALL MODELS AT STARTUP (no lazy loading)
50
  # ================================================================
@@ -94,6 +91,20 @@ esrgan_model.to("cuda").eval()
94
  ESRGAN_SCALE = int(esrgan_model.scale)
95
  print("Enhancement model loaded. Scale factor:", ESRGAN_SCALE)
96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  class DDColorHF(DDColor, PyTorchModelHubMixin):
98
  def __init__(self, config=None, **kwargs):
99
  if isinstance(config, dict):
@@ -106,7 +117,6 @@ ddcolor_model = (
106
  )
107
  print("✅ DDColor loaded on cuda.")
108
 
109
-
110
  print("🚀 Loading CLIP for metrics...")
111
  clip_model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32").to("cuda")
112
  clip_processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")
 
40
  except ImportError:
41
  brisque = None
42
 
43
+ import sys, os
44
+ from huggingface_hub import snapshot_download, PyTorchModelHubMixin
 
 
 
45
  # ================================================================
46
  # 5. LOAD ALL MODELS AT STARTUP (no lazy loading)
47
  # ================================================================
 
91
  ESRGAN_SCALE = int(esrgan_model.scale)
92
  print("Enhancement model loaded. Scale factor:", ESRGAN_SCALE)
93
 
94
+ # ================================================================
95
+ # 4. DDColor — download source, then load model
96
+ # ================================================================
97
+ import sys, os
98
+ from huggingface_hub import snapshot_download, PyTorchModelHubMixin
99
+
100
+ print("🚀 Downloading DDColor source code...")
101
+ ddcolor_repo_root = snapshot_download(
102
+ repo_id="kunhsiang/cv-final-colorize-demo",
103
+ repo_type="space",
104
+ allow_patterns="ddcolor_repo/ddcolor/*.py",
105
+ local_dir="/tmp/ddcolor_source",
106
+ )
107
+
108
  class DDColorHF(DDColor, PyTorchModelHubMixin):
109
  def __init__(self, config=None, **kwargs):
110
  if isinstance(config, dict):
 
117
  )
118
  print("✅ DDColor loaded on cuda.")
119
 
 
120
  print("🚀 Loading CLIP for metrics...")
121
  clip_model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32").to("cuda")
122
  clip_processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")