Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
# 初始化模型
|
| 12 |
-
#
|
| 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 "請輸入內容", "等待輸入..."
|