JJS341 commited on
Commit
3aebd6c
·
verified ·
1 Parent(s): 8f4cbf6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -1,16 +1,21 @@
1
  import os
2
  import sys
3
- import gradio as gr
4
- from deep_translator import GoogleTranslator
5
 
6
- # 補強環境套件
7
- os.system(f"{sys.executable} -m pip install torch transformers")
 
 
 
 
 
8
 
 
9
  from fastcoref import LingmessCoref
 
 
 
 
10
 
11
- # 1. 預先下載並加載 Lingmess 模型 (這在雲端更穩定)
12
- print("正在初始化深度語意模型...")
13
- model = LingmessCoref(device='cpu')
14
 
15
  def coref_chat(user_input):
16
  if not user_input.strip():
 
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():