Commit 路
9497a3d
1
Parent(s): 8a50149
chore: preload models in Dockerfile, bump VERSION, add pytest and unit tests
Browse files- Dockerfile +5 -0
- VERSION +1 -1
- requirements.txt +3 -0
- tests/test_analysis.py +27 -0
Dockerfile
CHANGED
|
@@ -16,6 +16,11 @@ RUN pip install --upgrade pip && \
|
|
| 16 |
|
| 17 |
COPY . .
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
EXPOSE 8000
|
| 20 |
|
| 21 |
CMD ["python", "run.py"]
|
|
|
|
| 16 |
|
| 17 |
COPY . .
|
| 18 |
|
| 19 |
+
# Pre-download commonly used models to avoid long first-request cold starts.
|
| 20 |
+
# These lines increase the image size but significantly reduce latency on first API call.
|
| 21 |
+
RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('paraphrase-multilingual-MiniLM-L12-v2')"
|
| 22 |
+
RUN python -c "from transformers import pipeline; pipeline('sentiment-analysis', model='nlptown/bert-base-multilingual-uncased-sentiment')"
|
| 23 |
+
|
| 24 |
EXPOSE 8000
|
| 25 |
|
| 26 |
CMD ["python", "run.py"]
|
VERSION
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
0.
|
|
|
|
| 1 |
+
0.2.0
|
requirements.txt
CHANGED
|
@@ -16,3 +16,6 @@ google-generativeai==0.6.0
|
|
| 16 |
pyarrow==14.0.2
|
| 17 |
tiktoken==0.7.0
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
pyarrow==14.0.2
|
| 17 |
tiktoken==0.7.0
|
| 18 |
|
| 19 |
+
# Dev / test dependencies
|
| 20 |
+
pytest==7.4.0
|
| 21 |
+
|
tests/test_analysis.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
from app.analysis import detect_query_type, count_keyword_rows, THANKS_KEYWORDS, COMPLAINT_KEYWORDS
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def test_detect_query_type_thanks():
|
| 6 |
+
t = "讻诪讛 诪砖转诪砖讬诐 讻转讘讜 转讜讚讛 注诇 讛砖讬专讜转"
|
| 7 |
+
qtype, target = detect_query_type(t)
|
| 8 |
+
assert qtype == "count_thanks"
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def test_detect_query_type_complaint():
|
| 12 |
+
t = "讻诪讛 讗谞砖讬诐 诪讚讜讜讞讬诐 注诇 转拽诇讛 讘诪注专讻转"
|
| 13 |
+
qtype, target = detect_query_type(t)
|
| 14 |
+
assert qtype == "count_complaint"
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def test_count_keyword_rows_counts_thanks():
|
| 18 |
+
df = pd.DataFrame({"Text": ["转讜讚讛 注诇 讛砖讬专讜转", "诇讗 讟讜讘", "转讜讚讛 专讘讛!", "砖讚专讜讙 谞讞诪讚"]})
|
| 19 |
+
cnt = count_keyword_rows(df, THANKS_KEYWORDS, text_column="Text")
|
| 20 |
+
assert cnt == 2
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def test_count_keyword_rows_counts_complaints():
|
| 24 |
+
df = pd.DataFrame({"Text": ["讗讬谉 砖讙讬讗讛", "转讬拽讜谉 谞讚专砖", "讬砖 转拽诇讛", "谞讻砖诇 讘注讘讜讚讛"]})
|
| 25 |
+
# Notice: keywords are Hebrew complaint variants; expect matches >=1
|
| 26 |
+
cnt = count_keyword_rows(df, COMPLAINT_KEYWORDS, text_column="Text")
|
| 27 |
+
assert cnt >= 1
|