JJS341 commited on
Commit
0d0999a
·
verified ·
1 Parent(s): 8354844

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -1,22 +1,28 @@
1
  import os
2
  import sys
3
 
4
- # 強 Spacy 模型,這在 Python 3.10 環境是必要的
5
- try:
6
- import spacy
7
- if not spacy.util.is_package("en_core_web_sm"):
8
- os.system("python -m spacy download en_core_web_sm")
9
- except:
10
- os.system("python -m spacy download en_core_web_sm")
 
 
 
 
11
 
12
  import gradio as gr
13
  from fastcoref import LingmessCoref
14
  from deep_translator import GoogleTranslator
15
 
16
- # 初始化模型
17
  model = LingmessCoref(device='cpu')
18
 
19
 
 
 
20
  def coref_chat(user_input):
21
  if not user_input.strip():
22
  return "請輸入內容", "等待輸入..."
 
1
  import os
2
  import sys
3
 
4
+ # 強制下載 Spacy 英文模型 (Lingmess 運作基礎)
5
+ os.system(f"{sys.executable} -m spacy download en_core_web_sm")
6
+
7
+ # 防錯補丁:萬一 huggingface_hub 版本太新,手動導向舊路徑
8
+ import huggingface_hub
9
+ if not hasattr(huggingface_hub, 'HfFolder'):
10
+ # 這是為了讓舊版 Gradio 能在新的 hub 環境下強行啟動
11
+ class MockHfFolder:
12
+ @staticmethod
13
+ def get_token(): return os.getenv("HF_TOKEN")
14
+ huggingface_hub.HfFolder = MockHfFolder
15
 
16
  import gradio as gr
17
  from fastcoref import LingmessCoref
18
  from deep_translator import GoogleTranslator
19
 
20
+ # 初始化 Lingmess 模型
21
  model = LingmessCoref(device='cpu')
22
 
23
 
24
+
25
+
26
  def coref_chat(user_input):
27
  if not user_input.strip():
28
  return "請輸入內容", "等待輸入..."