Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,29 @@
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
|
| 4 |
-
# 強制下載 Spacy
|
| 5 |
os.system(f"{sys.executable} -m spacy download en_core_web_sm")
|
| 6 |
|
| 7 |
-
# 防錯補丁:
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
| 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 "請輸入內容", "等待輸入..."
|
|
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
|
| 4 |
+
# 1. 強制下載 Spacy 模型
|
| 5 |
os.system(f"{sys.executable} -m spacy download en_core_web_sm")
|
| 6 |
|
| 7 |
+
# 2. 防錯補丁:解決 huggingface_hub 版本太新導致的 ImportError
|
| 8 |
+
try:
|
| 9 |
+
import huggingface_hub
|
| 10 |
+
if not hasattr(huggingface_hub, 'HfFolder'):
|
| 11 |
+
class MockHfFolder:
|
| 12 |
+
@staticmethod
|
| 13 |
+
def get_token(): return os.getenv("HF_TOKEN")
|
| 14 |
+
huggingface_hub.HfFolder = MockHfFolder
|
| 15 |
+
except:
|
| 16 |
+
pass
|
| 17 |
|
| 18 |
import gradio as gr
|
| 19 |
from fastcoref import LingmessCoref
|
| 20 |
from deep_translator import GoogleTranslator
|
| 21 |
|
| 22 |
+
# 3. 初始化 Lingmess 模型 (這行會跑比較久,因為要下載 Lingmess 權重)
|
| 23 |
model = LingmessCoref(device='cpu')
|
| 24 |
|
| 25 |
|
| 26 |
|
|
|
|
| 27 |
def coref_chat(user_input):
|
| 28 |
if not user_input.strip():
|
| 29 |
return "請輸入內容", "等待輸入..."
|