-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
225 lines (191 loc) · 5.26 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
from fastapi import FastAPI, UploadFile
from fastapi.responses import JSONResponse
from fastapi.middleware.cors import CORSMiddleware
from utils.handling_models import get_models, generating_jit_model, set_model, delete_model
from utils.handling_data import update_jd_data, get_v_jd_data, get_v_jds_data, create_v_jd_data, update_udemy_data, update_keywords_jds, update_keywords_udemy, update_keywords_tech_stack
from utils.handling_requests import server_initialize, get_recommended_jds, get_recommended_lectures
tags_metadata = [
{
"name": "Embedding Model",
"description": "모델 관련 API",
},
{
"name": "JD Database",
"description": "JD 데이터베이스 관련 API",
},
{
"name": "Virture JD Database",
"description": "가상 JD 데이터베이스 관련 API",
},
{
"name": "Udemy Database",
"description": "Udemy 데이터베이스 관련 API",
},
{
"name": "Keywords Database",
"description": "Keywords 데이터베이스 관련 API",
},
{
"name": "Recommendation",
"description": "추천 기능 관련 API",
},
]
origins = [
"*",
]
app = FastAPI(
title="북극성",
summary="길을 잃지 않도록 환히 빛나고 있습니다.",
version="1.0.0",
openapi_tags=tags_metadata
)
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get('/')
async def helloworld():
return JSONResponse(
content={"message": "Hello World"},
status_code=200,
)
@app.get('/init')
def initialize():
checkFile = server_initialize()
return JSONResponse(
content={
"message": "success",
"data": checkFile
},
status_code=200,
)
@app.get('/models', tags=["Embedding Model"])
def getmodels():
model_list = get_models()
return JSONResponse(
content={
"message": "success",
"data": model_list,
},
status_code=200,
)
@app.post('/models', tags=["Embedding Model"])
def createmodel(data: dict):
model_ref = data.get('model_ref')
model_name = data.get('model_name')
generating_jit_model(model_ref, model_name)
return JSONResponse(
content={"message": "success"},
status_code=201,
)
@app.put('/models', tags=["Embedding Model"])
def setmodel(data: dict):
model_name = data.get('model_name')
set_model(model_name)
return JSONResponse(
content={"message": "success"},
status_code=200,
)
@app.delete('/models', tags=["Embedding Model"])
def deletemodel(data: dict):
model_name = data.get('model_name')
delete_model(model_name)
return JSONResponse(
content={"message": "success"},
status_code=200,
)
@app.put('/jds', tags=["JD Database"])
async def updatedata(file: UploadFile):
await update_jd_data(file)
return JSONResponse(
content={"message": "success"},
status_code=200,
)
@app.get('/v_jds', tags=["Virture JD Database"])
def getvjds():
data = get_v_jds_data()
return JSONResponse(
content={
"message": "success",
"data": data,
},
status_code=200,
)
@app.get('/v_jds/{id}', tags=["Virture JD Database"])
def getvjd(id: str):
data = get_v_jd_data(id)
return JSONResponse(
content={
"message": "success",
"data": data,
},
status_code=200,
)
@app.post('/v_jds', tags=["Virture JD Database"])
def embedding(data: dict):
name = data.get('name')
date = data.get('date')
answers = data.get('answers')
new_id = create_v_jd_data(name, date, answers)
return JSONResponse(
content={
"message": "success",
"id": new_id,
},
status_code=201,
)
@app.put('/udemy', tags=["Udemy Database"])
async def updateudemydata(file: UploadFile):
await update_udemy_data(file)
return JSONResponse(
content={"message": "success"},
status_code=200,
)
@app.put('/key_jds', tags=["Keywords Database"])
async def updatekeywordsjds(file: UploadFile):
await update_keywords_jds(file)
return JSONResponse(
content={"message": "success"},
status_code=200,
)
@app.put('/key_udemy', tags=["Keywords Database"])
async def updatekeywordsudemy(file: UploadFile):
await update_keywords_udemy(file)
return JSONResponse(
content={"message": "success"},
status_code=200,
)
@app.put('/key_tech_stack', tags=["Keywords Database"])
async def updatekeywordstechstack(file: UploadFile):
await update_keywords_tech_stack(file)
return JSONResponse(
content={"message": "success"},
status_code=200,
)
@app.get('/find_jds/{v_jd_id}', tags=["Recommendation"])
def get_rec_jds(v_jd_id: str, columns: str, start: int, end: int):
recommends_data, most_frequent_job, keyword_counts = get_recommended_jds(v_jd_id, columns, start, end)
return JSONResponse(
content={
"message": "success",
"data": {
"jds": recommends_data,
"most_frequent_job": most_frequent_job,
"keyword_counts": keyword_counts,
},
},
status_code=200,
)
@app.get('/find_lectures/{jd_id}', tags=["Recommendation"])
def get_rec_lectures(jd_id: int, start: int, end: int):
recommends_data = get_recommended_lectures(jd_id, start, end)
return JSONResponse(
content={
"message": "success",
"data": recommends_data,
},
status_code=200,
)