Skip to content

Commit a5bd280

Browse files
authored
배포 v1.5.6
배포 v1.5.6
2 parents 7b4f8af + b8afd3b commit a5bd280

File tree

7 files changed

+79
-13
lines changed

7 files changed

+79
-13
lines changed

.github/workflows/Deploy-ML-EC2.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,23 @@ jobs:
1919
uses: appleboy/[email protected]
2020
env:
2121
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
22+
CLICK_LOG: ${{ secrets.CLICK_LOG }}
23+
DEEPFM_TRAIN_MODEL_PATH: ${{ secrets.DEEPFM_TRAIN_MODEL_PATH }}
24+
DEEPFM_TRAIN_ENCODERS_PATH: ${{ secrets.DEEPFM_TRAIN_ENCODERS_PATH }}
25+
DEEPFM_TRAIN_KEY2INDEX_PATH: ${{ secrets.DEEPFM_TRAIN_KEY2INDEX_PATH }}
2226
with:
2327
host: ${{ secrets.EC2_HOST_ML }}
2428
username: ${{ secrets.EC2_USER }}
2529
key: ${{ secrets.EC2_SSH_KEY }}
2630
port: 22
27-
envs: OPENAI_API_KEY
31+
envs: OPENAI_API_KEY CLICK_LOG DEEPFM_TRAIN_MODEL_PATH DEEPFM_TRAIN_ENCODERS_PATH DEEPFM_TRAIN_KEY2INDEX_PATH
2832
script: |
2933
export OPENAI_API_KEY=$OPENAI_API_KEY
30-
echo "OPENAI_API_KEY is $OPENAI_API_KEY"
31-
34+
export CLICK_LOG=$CLICK_LOG
35+
export DEEPFM_TRAIN_MODEL_PATH=$DEEPFM_TRAIN_MODEL_PATH
36+
export DEEPFM_TRAIN_ENCODERS_PATH=$DEEPFM_TRAIN_ENCODERS_PATH
37+
export DEEPFM_TRAIN_KEY2INDEX_PATH=$DEEPFM_TRAIN_KEY2INDEX_PATH
38+
3239
# 프로젝트 디렉터리로 이동
3340
cd ~/MLOps
3441

MLOps/app/main.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from datetime import datetime
1111

1212
# 라우터 임포트
13-
from app.routers import recommendation, chatbot
13+
from app.routers import recommendation, chatbot, crowd
1414

1515
# 환경 변수 설정
1616
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY", "")
@@ -47,6 +47,7 @@ async def global_exception_handler(request: Request, exc: Exception):
4747
# 라우터 등록
4848
app.include_router(recommendation.router)
4949
app.include_router(chatbot.router)
50+
app.include_router(crowd.router)
5051

5152
@app.get("/")
5253
async def root():
@@ -68,7 +69,7 @@ async def root():
6869
"stats": "/api/chat/stats"
6970
},
7071
"description": "OpenAI GPT 기반 데이트 코스 추천 챗봇",
71-
"status": "active" if hasattr(chatbot, 'openai_service') else "inactive"
72+
"status": "active" if hasattr(chatbot, 'langchain_agent_service') else "inactive"
7273
}
7374
},
7475
"documentation": "/docs"
@@ -84,7 +85,7 @@ async def health_check():
8485

8586
# 챗봇 상태 확인
8687
chatbot_status = "inactive"
87-
if hasattr(chatbot, 'openai_service') and chatbot.openai_service:
88+
if hasattr(chatbot, 'langchain_agent_service') and chatbot.langchain_agent_service:
8889
chatbot_status = "active"
8990

9091
# 전체 상태 결정
@@ -112,7 +113,7 @@ async def get_overall_stats():
112113
"type": "ELK + DeepCTR"
113114
},
114115
"chatbot": {
115-
"status": "active" if hasattr(chatbot, 'openai_service') else "inactive",
116+
"status": "active" if hasattr(chatbot, 'langchain_agent_service') else "inactive",
116117
"type": "OpenAI GPT",
117118
"active_sessions": len(getattr(chatbot, 'active_sessions', {}))
118119
}

MLOps/app/model/deepfm_train.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ def __init__(self, data_path):
2222
self.feature_names = None
2323
self.model_input = None
2424
self.target = "yn"
25-
self.model_path = "/app/app/model/deepfm_model.pt"
26-
self.encoders_path = "/app/app/model/label_encoders.pkl"
27-
self.key2index_path = "/app/app/model/key2index.pkl"
25+
self.model_path = os.environ.get("DEEPFM_TRAIN_MODEL_PATH", "")
26+
self.encoders_path = os.environ.get("DEEPFM_TRAIN_ENCODERS_PATH", "")
27+
self.key2index_path = os.environ.get("DEEPFM_TRAIN_KEY2INDEX_PATH", "")
2828
self.model = None
2929
self.max_len = None
3030
self.label_encoders = {}
@@ -177,7 +177,7 @@ def encode_sequence(x):
177177
return model.predict(model_input)
178178

179179
if __name__ == "__main__":
180-
deepfm_train = DeepFMModdelTrain("../data/final_click_log.csv")
180+
deepfm_train = DeepFMModdelTrain(os.environ.get("CLICK_LOG", ""))
181181
deepfm_train.preprocess()
182182
model = deepfm_train.train()
183183
# 예시 데이터

MLOps/app/routers/crowd.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from fastapi import APIRouter
2+
from app.schema.crowd_schema import CrowdResponse, CrowdLevel, CrowdInfo
3+
4+
router = APIRouter()
5+
6+
@router.get("/api/crowd", response_model=CrowdResponse)
7+
async def get_crowd(hour: int):
8+
"""
9+
## 혼잡도 예측 API
10+
- **hour**: 시간 (정수)
11+
"""
12+
dummy_row_data = [
13+
CrowdInfo(
14+
area_nm="충정로역",
15+
x="37.55969632013057",
16+
y="126.96369132536704",
17+
area_congest_lvl="붐빔",
18+
area_congest_num=4
19+
),
20+
CrowdInfo(
21+
area_nm="서울역",
22+
x="37.55659428234287",
23+
y="126.97302795181167",
24+
area_congest_lvl="붐빔",
25+
area_congest_num=4
26+
)
27+
]
28+
29+
dummy_crowd_level = CrowdLevel(
30+
total=120,
31+
row=dummy_row_data
32+
)
33+
34+
return CrowdResponse(
35+
success=True,
36+
message="혼잡도 예측 성공!",
37+
crowdLevel=dummy_crowd_level
38+
)

MLOps/app/schema/crowd_schema.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from pydantic import BaseModel
2+
from typing import List
3+
4+
class CrowdInfo(BaseModel):
5+
area_nm: str
6+
x: str
7+
y: str
8+
area_congest_lvl: str
9+
area_congest_num: int
10+
11+
class CrowdLevel(BaseModel):
12+
total: int
13+
row: List[CrowdInfo]
14+
15+
class CrowdResponse(BaseModel):
16+
success: bool
17+
message: str
18+
crowdLevel: CrowdLevel

MLOps/app/services/deepctr_service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
from app.services.elk_client import ELKClient
55
from app.services.user_data_service import UserDataService
66
import pandas as pd
7+
import os
78

89
class DeepCTRService:
910
"""DeepCTR 모델 서비스"""
1011

1112
def __init__(self):
12-
self.model = DeepFMModdelTrain("/app/data/final_click_log.csv")
13+
self.model = DeepFMModdelTrain(os.environ.get("CLICK_LOG", ""))
1314
self.elk_client = ELKClient()
1415
self.user_data_service = UserDataService()
1516

MLOps/app/services/user_data_service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import pandas as pd
22
from typing import Dict
3+
import os
34

45
class UserDataService:
56
"""사용자 데이터 관리 서비스"""
67

78
def __init__(self):
8-
self.data_path = "/app/data/final_click_log.csv"
9+
self.data_path = os.environ.get("CLICK_LOG", "")
910
self.user_data = pd.read_csv(self.data_path)
1011

1112
def get_user_info(self, userid: str) -> Dict:

0 commit comments

Comments
 (0)