hutiger commited on
Commit
7e18bc7
·
verified ·
1 Parent(s): 44f15fb

Fix model loading with weights_only=False

Browse files
Files changed (2) hide show
  1. app.py +6 -4
  2. predict.py +1 -1
app.py CHANGED
@@ -1,20 +1,20 @@
1
  """
2
- Hugging Face Spaces 入口文件
3
  """
4
  import sys
5
 
6
- # 补丁 1: audioop (Python 3.13)
7
  try:
8
  import audioop_lts as audioop
9
  sys.modules["pyaudioop"] = audioop
10
  except ImportError:
11
  pass
12
 
13
- # 补丁 2: HfFolder (huggingface-hub>=0.25)
14
  try:
15
  import huggingface_hub
16
  if not hasattr(huggingface_hub, "HfFolder"):
17
- from huggingface_hub import HfApi, get_token
18
  class _HfFolder:
19
  @staticmethod
20
  def get_token(): return get_token()
@@ -23,4 +23,6 @@ try:
23
  except Exception:
24
  pass
25
 
 
26
  from webui import demo
 
 
1
  """
2
+ Hugging Face Spaces 入口
3
  """
4
  import sys
5
 
6
+ # 补丁: audioop (Python 3.13)
7
  try:
8
  import audioop_lts as audioop
9
  sys.modules["pyaudioop"] = audioop
10
  except ImportError:
11
  pass
12
 
13
+ # 补丁: HfFolder
14
  try:
15
  import huggingface_hub
16
  if not hasattr(huggingface_hub, "HfFolder"):
17
+ from huggingface_hub import get_token
18
  class _HfFolder:
19
  @staticmethod
20
  def get_token(): return get_token()
 
23
  except Exception:
24
  pass
25
 
26
+ # 启动
27
  from webui import demo
28
+ demo.queue().launch(server_name="0.0.0.0", server_port=7860)
predict.py CHANGED
@@ -44,7 +44,7 @@ class GarbageClassifier:
44
  if not path.exists():
45
  raise FileNotFoundError(f"模型文件不存在: {model_path}\n请先运行 train.py 训练模型")
46
 
47
- checkpoint = torch.load(model_path, map_location=self.device, weights_only=True)
48
  model.load_state_dict(checkpoint["model_state_dict"])
49
  model = model.to(self.device)
50
  print(f"✓ 模型加载成功 ({model_path})")
 
44
  if not path.exists():
45
  raise FileNotFoundError(f"模型文件不存在: {model_path}\n请先运行 train.py 训练模型")
46
 
47
+ checkpoint = torch.load(model_path, map_location=self.device, weights_only=False)
48
  model.load_state_dict(checkpoint["model_state_dict"])
49
  model = model.to(self.device)
50
  print(f"✓ 模型加载成功 ({model_path})")