Spaces:
Running
Running
up
Browse files- Dockerfile +36 -0
- main.py +46 -0
- requirements.txt +19 -0
Dockerfile
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9-slim
|
2 |
+
|
3 |
+
WORKDIR /app
|
4 |
+
|
5 |
+
# Cài đặt các dependencies cần thiết
|
6 |
+
RUN apt-get update && apt-get install -y \
|
7 |
+
build-essential \
|
8 |
+
git \
|
9 |
+
&& rm -rf /var/lib/apt/lists/*
|
10 |
+
|
11 |
+
# Copy requirements từ project hiện tại
|
12 |
+
COPY requirements.txt .
|
13 |
+
|
14 |
+
# Clone repository meisai-check-ai từ Bitbucket sử dụng biến môi trường
|
15 |
+
ARG BITBUCKET_APP_PW
|
16 |
+
RUN git clone https://vumichien:${BITBUCKET_APP_PW}@bitbucket.org/dtm-partners/meisai-check-ai.git
|
17 |
+
|
18 |
+
# Cài đặt dependencies
|
19 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
20 |
+
RUN pip install --no-cache-dir -r meisai-check-ai/requirements.txt
|
21 |
+
|
22 |
+
# Cài đặt FastAPI và Uvicorn
|
23 |
+
RUN pip install --no-cache-dir fastapi uvicorn
|
24 |
+
|
25 |
+
# Copy code của API vào container
|
26 |
+
COPY . .
|
27 |
+
|
28 |
+
# Thêm đường dẫn meisai-check-ai vào PYTHONPATH
|
29 |
+
ENV PYTHONPATH="${PYTHONPATH}:/app/meisai-check-ai"
|
30 |
+
|
31 |
+
# Expose port
|
32 |
+
EXPOSE 7860
|
33 |
+
|
34 |
+
# Chạy ứng dụng với Uvicorn
|
35 |
+
# Lưu ý: Hugging Face Spaces sử dụng port 7860
|
36 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
main.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
import os
|
3 |
+
import time
|
4 |
+
from fastapi import FastAPI
|
5 |
+
import uvicorn
|
6 |
+
import traceback
|
7 |
+
|
8 |
+
# Điều chỉnh đường dẫn để import từ thư mục meisai-check-ai
|
9 |
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
10 |
+
sys.path.append(os.path.join(current_dir, "meisai-check-ai"))
|
11 |
+
|
12 |
+
from sentence_transformer_lib.sentence_transformer_helper import (
|
13 |
+
SentenceTransformerHelper,
|
14 |
+
)
|
15 |
+
from data_lib.base_data import BaseData
|
16 |
+
from data_lib.input_name_data import InputNameData
|
17 |
+
|
18 |
+
app = FastAPI()
|
19 |
+
|
20 |
+
|
21 |
+
@app.get("/")
|
22 |
+
async def root():
|
23 |
+
return {"message": "Hello World"}
|
24 |
+
|
25 |
+
|
26 |
+
@app.get("/health")
|
27 |
+
async def health_check():
|
28 |
+
return {"status": "ok", "timestamp": time.time()}
|
29 |
+
|
30 |
+
|
31 |
+
@app.get("/test-dependencies")
|
32 |
+
async def test_dependencies():
|
33 |
+
try:
|
34 |
+
# Kiểm tra các dependencies đã được import thành công
|
35 |
+
transformer_helper = SentenceTransformerHelper()
|
36 |
+
return {"status": "success", "message": "All dependencies loaded successfully"}
|
37 |
+
except Exception as e:
|
38 |
+
return {
|
39 |
+
"status": "error",
|
40 |
+
"message": str(e),
|
41 |
+
"traceback": traceback.format_exc(),
|
42 |
+
}
|
43 |
+
|
44 |
+
|
45 |
+
if __name__ == "__main__":
|
46 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
requirements.txt
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
sentence-transformers
|
2 |
+
fugashi
|
3 |
+
unidic_lite
|
4 |
+
fastapi
|
5 |
+
uvicorn
|
6 |
+
sortedcontainers
|
7 |
+
jaconv
|
8 |
+
oauth2client
|
9 |
+
gspread
|
10 |
+
scikit-learn
|
11 |
+
datasets
|
12 |
+
unidic-lit
|
13 |
+
sortedcontainers
|
14 |
+
gspread-dataframe
|
15 |
+
oauth2client
|
16 |
+
wandb
|
17 |
+
scikit-learn
|
18 |
+
fastapi
|
19 |
+
uvicorn
|