Spaces:
Sleeping
Sleeping
更新 Gunicorn 配置以优化连接管理;在处理条目时增加对空文本的处理,确保输入有效性
Browse files- blkeras.py +1 -1
- gunicorn.conf.py +4 -0
- preprocess.py +8 -4
blkeras.py
CHANGED
|
@@ -66,7 +66,7 @@ def get_model():
|
|
| 66 |
"ConcatenateTimesteps": ConcatenateTimesteps
|
| 67 |
})
|
| 68 |
|
| 69 |
-
model.summary()
|
| 70 |
model_initialized = True
|
| 71 |
return model
|
| 72 |
|
|
|
|
| 66 |
"ConcatenateTimesteps": ConcatenateTimesteps
|
| 67 |
})
|
| 68 |
|
| 69 |
+
# model.summary()
|
| 70 |
model_initialized = True
|
| 71 |
return model
|
| 72 |
|
gunicorn.conf.py
CHANGED
|
@@ -14,6 +14,10 @@ threads = 2
|
|
| 14 |
# 请求超时时间
|
| 15 |
timeout = 600
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
# 工作方式
|
| 18 |
worker_class = "uvicorn.workers.UvicornWorker"
|
| 19 |
|
|
|
|
| 14 |
# 请求超时时间
|
| 15 |
timeout = 600
|
| 16 |
|
| 17 |
+
keepalive = 5 # keep-alive 连接等待时间,建议设置较小值
|
| 18 |
+
graceful_timeout = 30 # 优雅关闭超时时间,给进程2分钟清理资源
|
| 19 |
+
|
| 20 |
+
|
| 21 |
# 工作方式
|
| 22 |
worker_class = "uvicorn.workers.UvicornWorker"
|
| 23 |
|
preprocess.py
CHANGED
|
@@ -74,7 +74,7 @@ class LazyWord2Vec:
|
|
| 74 |
def load_model(self):
|
| 75 |
if self._model is None:
|
| 76 |
print(f"Loading Word2Vec model from path: {self.model_path}...")
|
| 77 |
-
self._model = KeyedVectors.load(self.model_path
|
| 78 |
|
| 79 |
@property
|
| 80 |
def model(self):
|
|
@@ -677,11 +677,15 @@ def dependency_parsing(text):
|
|
| 677 |
def processing_entry(entry):
|
| 678 |
# print(f"processing_entry: {entry}")
|
| 679 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 680 |
|
| 681 |
-
lemmatized_entry = preprocessing_entry(
|
| 682 |
# print(f"lemmatized_entry: {lemmatized_entry}")
|
| 683 |
|
| 684 |
-
cleaned_text = disposal_noise(
|
| 685 |
# print(f"disposal_noise: {cleaned_text}")
|
| 686 |
|
| 687 |
pos_tag = pos_tagging(cleaned_text)
|
|
@@ -694,7 +698,7 @@ def processing_entry(entry):
|
|
| 694 |
# print(f"dependency_parsing: {db_dependency_parsing}")
|
| 695 |
dependency_parsed = None
|
| 696 |
|
| 697 |
-
sentiment_score = get_sentiment_score(
|
| 698 |
# print(f"sentiment_score: {sentiment_score}")
|
| 699 |
|
| 700 |
|
|
|
|
| 74 |
def load_model(self):
|
| 75 |
if self._model is None:
|
| 76 |
print(f"Loading Word2Vec model from path: {self.model_path}...")
|
| 77 |
+
self._model = KeyedVectors.load(self.model_path)
|
| 78 |
|
| 79 |
@property
|
| 80 |
def model(self):
|
|
|
|
| 677 |
def processing_entry(entry):
|
| 678 |
# print(f"processing_entry: {entry}")
|
| 679 |
|
| 680 |
+
text = entry
|
| 681 |
+
if text and text.strip() == "EMPTY_TEXT":
|
| 682 |
+
text = "It just a normal day."
|
| 683 |
+
|
| 684 |
|
| 685 |
+
lemmatized_entry = preprocessing_entry(text)
|
| 686 |
# print(f"lemmatized_entry: {lemmatized_entry}")
|
| 687 |
|
| 688 |
+
cleaned_text = disposal_noise(text)
|
| 689 |
# print(f"disposal_noise: {cleaned_text}")
|
| 690 |
|
| 691 |
pos_tag = pos_tagging(cleaned_text)
|
|
|
|
| 698 |
# print(f"dependency_parsing: {db_dependency_parsing}")
|
| 699 |
dependency_parsed = None
|
| 700 |
|
| 701 |
+
sentiment_score = get_sentiment_score(entry)
|
| 702 |
# print(f"sentiment_score: {sentiment_score}")
|
| 703 |
|
| 704 |
|