learnmlf commited on
Commit
9c07de8
·
1 Parent(s): 048983c

Add automatic model weights download from HuggingFace

Browse files

- Automatically download model.pth from FF2416/AC-Foley repo
- Create weights directory if not exists
- Better error handling for missing weights
- Improved status messages

Files changed (1) hide show
  1. app.py +25 -1
app.py CHANGED
@@ -117,6 +117,30 @@ class AudioFoleyModel:
117
  except Exception as e:
118
  log.warning(f"Could not download model components: {e}")
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  # Set custom model path if provided
121
  if model_path and os.path.exists(model_path):
122
  self.model.model_path = Path(model_path)
@@ -136,7 +160,7 @@ class AudioFoleyModel:
136
  return f"❌ Failed to load model weights: {e}"
137
  else:
138
  log.warning('⚠️ No model weights found, using default initialization')
139
- return "⚠️ Model loaded but no weights found. Download model.pth from HuggingFace."
140
 
141
  # Initialize flow matching
142
  self.fm = FlowMatching(min_sigma=0, inference_mode='euler', num_steps=25)
 
117
  except Exception as e:
118
  log.warning(f"Could not download model components: {e}")
119
 
120
+ # Try to download main model weights from HuggingFace
121
+ if not hasattr(self.model, 'model_path') or not self.model.model_path or not Path(self.model.model_path).exists():
122
+ try:
123
+ from huggingface_hub import hf_hub_download
124
+ log.info("Downloading main model weights from HuggingFace...")
125
+
126
+ # Create weights directory
127
+ weights_dir = Path("weights")
128
+ weights_dir.mkdir(exist_ok=True)
129
+
130
+ # Download model.pth from HuggingFace
131
+ model_file = hf_hub_download(
132
+ repo_id="FF2416/AC-Foley",
133
+ filename="model.pth",
134
+ local_dir=str(weights_dir),
135
+ local_dir_use_symlinks=False
136
+ )
137
+ self.model.model_path = Path(model_file)
138
+ log.info(f"✅ Downloaded model weights to {model_file}")
139
+
140
+ except Exception as e:
141
+ log.warning(f"Could not download main model weights: {e}")
142
+ log.info("Will proceed with available components only")
143
+
144
  # Set custom model path if provided
145
  if model_path and os.path.exists(model_path):
146
  self.model.model_path = Path(model_path)
 
160
  return f"❌ Failed to load model weights: {e}"
161
  else:
162
  log.warning('⚠️ No model weights found, using default initialization')
163
+ return "⚠️ Model components loaded, but main weights not available. Some features may be limited."
164
 
165
  # Initialize flow matching
166
  self.fm = FlowMatching(min_sigma=0, inference_mode='euler', num_steps=25)