JJS341 commited on
Commit
0de769a
·
verified ·
1 Parent(s): 22c8f2a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -3
app.py CHANGED
@@ -1,17 +1,32 @@
1
  import os
2
  import sys
3
 
4
- # 補強環境強制下載模型
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  os.system(f"{sys.executable} -m spacy download en_core_web_sm")
6
 
7
  import gradio as gr
8
  from fastcoref import FCoref
9
  from deep_translator import GoogleTranslator
10
 
11
- # 初始化模型 (FCoref 是 fastcoref 的標準入口)
12
- # 它會自動處理 Lingmess 或其他預訓練權重
13
  model = FCoref(device='cpu')
14
 
 
 
15
  def coref_chat(user_input):
16
  if not user_input.strip():
17
  return "請輸入內容", "等待輸入..."
 
1
  import os
2
  import sys
3
 
4
+ # 補丁 1解決 Transformers 4.40 與最新 Hub 的相容性問題
5
+ try:
6
+ import huggingface_hub
7
+ if not hasattr(huggingface_hub, 'HfFolder'):
8
+ class MockHfFolder:
9
+ @staticmethod
10
+ def get_token(): return os.getenv("HF_TOKEN")
11
+ @staticmethod
12
+ def save_token(token): pass
13
+ huggingface_hub.HfFolder = MockHfFolder
14
+ except:
15
+ pass
16
+
17
+ # 補丁 2:強制下載 Spacy
18
  os.system(f"{sys.executable} -m spacy download en_core_web_sm")
19
 
20
  import gradio as gr
21
  from fastcoref import FCoref
22
  from deep_translator import GoogleTranslator
23
 
24
+ # 初始化模型
25
+ # 指定 device='cpu' 避免雲端嘗試調用不存在的 GPU
26
  model = FCoref(device='cpu')
27
 
28
+
29
+
30
  def coref_chat(user_input):
31
  if not user_input.strip():
32
  return "請輸入內容", "等待輸入..."