Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_tool_test_recommend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_tool_test_recommend
Commits
1b9277bb
Commit
1b9277bb
authored
Jan 16, 2026
by
Vũ Hoàng Anh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: update port to 5004, clean requirements.txt, add redirect to index.html
parent
446d8f46
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
110 additions
and
1244 deletions
+110
-1244
Dockerfile
backend/Dockerfile
+6
-10
recommend_image.py
backend/api/recommend_image.py
+4
-3
config.py
backend/config.py
+1
-1
magento_product_dimension_with_text_embedding_202512221052.json
...o_product_dimension_with_text_embedding_202512221052.json
+0
-1203
text.txt
backend/datadb/text.txt
+0
-2
docker-compose.yml
backend/docker-compose.yml
+3
-3
entrypoint.sh
backend/entrypoint.sh
+0
-19
requirements.txt
backend/requirements.txt
+0
-0
requirements_docker.txt
backend/requirements_docker.txt
+91
-0
run.txt
backend/run.txt
+2
-2
server.py
backend/server.py
+3
-1
No files found.
backend/Dockerfile
View file @
1b9277bb
#
Lấy Python 3.11 slim (ít file, nhẹ
)
#
Python 3.11 slim (nhẹ, ít file
)
FROM
python:3.11-slim
FROM
python:3.11-slim
# Thư mục làm việc
# Thư mục làm việc
...
@@ -8,17 +8,13 @@ ENV PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1
...
@@ -8,17 +8,13 @@ ENV PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1
# Copy requirements rồi cài package
# Copy requirements rồi cài package
COPY
requirements.txt .
COPY
requirements.txt .
RUN
pip
install
-r
requirements.txt
RUN
pip
install
-
-no-cache-dir
-
r
requirements.txt
# Copy code
# Copy code
COPY
. .
COPY
. .
# Copy entrypoint script (nếu có)
# Mở port (sẽ được override bởi docker-compose)
COPY
entrypoint.sh /app/entrypoint.sh
EXPOSE
5004
RUN
chmod
+x /app/entrypoint.sh
# Mở port 5003
# Chạy uvicorn với auto workers (2 * CPU cores + 1)
EXPOSE
5003
CMD
["sh", "-c", "uvicorn server:app --host 0.0.0.0 --port ${PORT:-5004} --workers $(( $(nproc) * 2 + 1 ))"]
\ No newline at end of file
# Chạy server
CMD
["/app/entrypoint.sh"]
\ No newline at end of file
backend/api/recommend_image.py
View file @
1b9277bb
...
@@ -49,13 +49,15 @@ async def recommend_by_image(
...
@@ -49,13 +49,15 @@ async def recommend_by_image(
# Chuyển vector sang định dạng string [v1, v2, ...] để gắn vào SQL
# Chuyển vector sang định dạng string [v1, v2, ...] để gắn vào SQL
v_str
=
"["
+
","
.
join
(
map
(
str
,
vector
.
tolist
()))
+
"]"
v_str
=
"["
+
","
.
join
(
map
(
str
,
vector
.
tolist
()))
+
"]"
# 2.
Hardcoded SQL cho StarRocks (CTE + Grouping
)
# 2.
Optimized SQL cho StarRocks (sử dụng HNSW Vector Index
)
# Bảng đích: magento_product_dimension_with_image_embedding
# Bảng đích: magento_product_dimension_with_image_embedding
target_table
=
"shared_source.magento_product_dimension_with_image_embedding"
target_table
=
"shared_source.magento_product_dimension_with_image_embedding"
ef_search
=
128
# HNSW ef_search parameter (higher = more accurate, slower)
sql
=
f
"""
sql
=
f
"""
WITH top_sku_candidates AS (
WITH top_sku_candidates AS (
SELECT
SELECT
/*+ SET_VAR(ann_params='{{"ef_search":{ef_search}}}') */
internal_ref_code,
internal_ref_code,
product_name,
product_name,
sale_price,
sale_price,
...
@@ -76,9 +78,8 @@ async def recommend_by_image(
...
@@ -76,9 +78,8 @@ async def recommend_by_image(
form_sleeve,
form_sleeve,
product_line_vn,
product_line_vn,
product_color_name,
product_color_name,
cosine_similarity(vector, {v_str}) as similarity_score
approx_
cosine_similarity(vector, {v_str}) as similarity_score
FROM {target_table}
FROM {target_table}
WHERE vector IS NOT NULL
ORDER BY similarity_score DESC
ORDER BY similarity_score DESC
LIMIT 50
LIMIT 50
)
)
...
...
backend/config.py
View file @
1b9277bb
...
@@ -73,7 +73,7 @@ JWT_SECRET: str | None = os.getenv("JWT_SECRET")
...
@@ -73,7 +73,7 @@ JWT_SECRET: str | None = os.getenv("JWT_SECRET")
JWT_ALGORITHM
:
str
|
None
=
os
.
getenv
(
"JWT_ALGORITHM"
)
JWT_ALGORITHM
:
str
|
None
=
os
.
getenv
(
"JWT_ALGORITHM"
)
# ====================== SERVER CONFIG ======================
# ====================== SERVER CONFIG ======================
PORT
:
int
=
int
(
os
.
getenv
(
"PORT"
,
"500
0
"
))
PORT
:
int
=
int
(
os
.
getenv
(
"PORT"
,
"500
4
"
))
FIRECRAWL_API_KEY
:
str
|
None
=
os
.
getenv
(
"FIRECRAWL_API_KEY"
)
FIRECRAWL_API_KEY
:
str
|
None
=
os
.
getenv
(
"FIRECRAWL_API_KEY"
)
# ====================== LANGFUSE CONFIGURATION (DEPRECATED) ======================
# ====================== LANGFUSE CONFIGURATION (DEPRECATED) ======================
...
...
backend/datadb/magento_product_dimension_with_text_embedding_202512221052.json
deleted
100644 → 0
View file @
446d8f46
This source diff could not be displayed because it is too large. You can
view the blob
instead.
backend/datadb/text.txt
deleted
100644 → 0
View file @
446d8f46
product_name: Pack 3 đôi tất bé gái cổ thấp. master_color: Xanh da trời/ Blue. product_image_url: https://2885371169.e.cdneverest.net/pub/media/catalog/product/1/a/1ax24a002-pb449-7-9-ghep-u.jpg. product_image_url_thumbnail: https://2885371169.e.cdneverest.net/pub/media/catalog/product/1/a/1ax24a002-pb449-7-9-ghep-u.jpg. product_web_url: https://canifa.com/tat-be-gai-1ax24a002?color=PB449&utm_source=chatbot&utm_medium=rsa&utm_campaign=testver25.9. description_text: Pack 3 đôi tất cổ thấp, họa tiết basic.
Chất liệu cotton pha mềm mại, co giãn tốt, màu sắc đơn giản dễ phối mix đồ.. material: None. material_group: Yarn - Sợi. gender_by_product: female. age_by_product: others. season: Year. style: Feminine. fitting: Slim. size_scale: 4/6. form_neckline: None. form_sleeve: None. product_line_vn: Tất. product_color_name: Blue Strip 449
\ No newline at end of file
backend/docker-compose.yml
View file @
1b9277bb
...
@@ -2,14 +2,14 @@ services:
...
@@ -2,14 +2,14 @@ services:
# --- Backend Service ---
# --- Backend Service ---
backend
:
backend
:
build
:
.
build
:
.
container_name
:
canifa_
back
end
container_name
:
canifa_
tool_test_recomm
end
env_file
:
.env
env_file
:
.env
ports
:
ports
:
-
"
500
3:5003
"
-
"
500
4:5004
"
volumes
:
volumes
:
-
.:/app
-
.:/app
environment
:
environment
:
-
PORT=500
3
-
PORT=500
4
restart
:
unless-stopped
restart
:
unless-stopped
deploy
:
deploy
:
resources
:
resources
:
...
...
backend/entrypoint.sh
deleted
100644 → 0
View file @
446d8f46
#!/bin/bash
NUM_CORES
=
$(
nproc
)
WORKERS
=
$((
2
*
NUM_CORES
+
1
))
echo
"🔧 [STARTUP] CPU cores:
$NUM_CORES
"
echo
"🔧 [STARTUP] Gunicorn workers:
$WORKERS
"
exec
gunicorn
\
server:app
\
--workers
"
$WORKERS
"
\
--worker-class
uvicorn.workers.UvicornWorker
\
--worker-connections
1000
\
--max-requests
1000
\
--max-requests-jitter
100
\
--timeout
30
\
--access-logfile
-
\
--error-logfile
-
\
--bind
0.0.0.0:5000
\
--log-level
info
\ No newline at end of file
backend/requirements.txt
View file @
1b9277bb
B
# Core Web Framework
B
# Core Web Framework
...
...
backend/requirements_docker.txt
0 → 100644
View file @
1b9277bb
annotated-doc==0.0.4
annotated-types==0.7.0
anyio==4.12.0
attrs==25.4.0
bidict==0.23.1
blinker==1.9.0
brotli==1.2.0
certifi==2025.11.12
cffi==2.0.0
charset-normalizer==3.4.4
click==8.3.1
colorama==0.4.6
ConfigArgParse==1.7.1
cryptography==46.0.3
distro==1.9.0
et_xmlfile==2.0.0
fastapi==0.128.0
Flask==3.1.2
flask-cors==6.0.2
Flask-Login==0.6.3
gevent==25.9.1
geventhttpclient==2.3.7
googleapis-common-protos==1.72.0
greenlet==3.3.0
grpcio==1.76.0
h11==0.16.0
httpcore==1.0.9
httpx==0.28.1
httpx-sse==0.4.3
idna==3.11
importlib_metadata==8.7.1
iniconfig==2.3.0
itsdangerous==2.2.0
Jinja2==3.1.6
jiter==0.12.0
jsonschema==4.25.1
jsonschema-specifications==2025.9.1
locust==2.43.0
MarkupSafe==3.0.3
mcp==1.25.0
msgpack==1.1.2
numpy==2.4.0
openai==2.15.0
openpyxl==3.1.5
opentelemetry-api==1.39.1
opentelemetry-exporter-otlp==1.39.1
opentelemetry-exporter-otlp-proto-common==1.39.1
opentelemetry-exporter-otlp-proto-grpc==1.39.1
opentelemetry-exporter-otlp-proto-http==1.39.1
opentelemetry-proto==1.39.1
opentelemetry-sdk==1.39.1
opentelemetry-semantic-conventions==0.60b1
packaging==25.0
pandas==2.3.3
pluggy==1.6.0
protobuf==6.33.2
psutil==7.2.1
pycparser==2.23
pydantic==2.12.5
pydantic-settings==2.12.0
pydantic_core==2.41.5
Pygments==2.19.2
PyJWT==2.10.1
pytest==9.0.2
python-dateutil==2.9.0.post0
python-dotenv==1.2.1
python-engineio==4.13.0
python-multipart==0.0.21
python-socketio==5.16.0
pytz==2025.2
pyzmq==27.1.0
referencing==0.37.0
requests==2.32.5
rpds-py==0.30.0
simple-websocket==1.1.0
six==1.17.0
sniffio==1.3.1
sse-starlette==3.1.2
starlette==0.50.0
tqdm==4.67.1
typing-inspection==0.4.2
typing_extensions==4.15.0
tzdata==2025.3
urllib3==2.6.2
uvicorn==0.40.0
websocket-client==1.9.0
Werkzeug==3.1.4
wsproto==1.3.2
zipp==3.23.0
zope.event==6.1
zope.interface==8.1.1
backend/run.txt
View file @
1b9277bb
...
@@ -4,10 +4,10 @@
...
@@ -4,10 +4,10 @@
.\.venv\Scripts\activate
.\.venv\Scripts\activate
uvicorn server:app --host 0.0.0.0 --port 8000 --reload
uvicorn server:app --host 0.0.0.0 --port 5000
uvicorn server:app --host 0.0.0.0 --port 6000
docker restart chatbot-backend
docker restart chatbot-backend
...
...
backend/server.py
View file @
1b9277bb
...
@@ -71,9 +71,11 @@ try:
...
@@ -71,9 +71,11 @@ try:
except
Exception
as
e
:
except
Exception
as
e
:
print
(
f
"⚠️ Failed to mount static files: {e}"
)
print
(
f
"⚠️ Failed to mount static files: {e}"
)
from
fastapi.responses
import
RedirectResponse
@
app
.
get
(
"/"
)
@
app
.
get
(
"/"
)
async
def
root
():
async
def
root
():
return
{
"message"
:
"Contract AI Service is running!"
,
"status"
:
"healthy"
}
return
RedirectResponse
(
url
=
"/static/index.html"
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
print
(
"="
*
60
)
print
(
"="
*
60
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment