Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,28 @@
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 "請輸入內容", "等待輸入..."
|