-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
57 lines (47 loc) · 1.56 KB
/
main.py
File metadata and controls
57 lines (47 loc) · 1.56 KB
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
from fastapi import FastAPI
from pydantic import BaseModel
from typing import List
from extractor import extract_keywords, extract_target_entity, classify_categories
import asyncio
app = FastAPI()
# 요청 바디
class TextInput(BaseModel):
text: str
# 응답 바디
class KeywordResponse(BaseModel):
keywords: List[str]
class CombinedResponse(BaseModel):
keywords: List[str]
target: str
category: str
# @app.post("/keyword", response_model=KeywordResponse)
# async def extract(text_input: TextInput):
# keywords = extract_keywords(text_input.text)
# return {"keywords": keywords}
#
# @app.post("/target", response_model=KeywordResponse)
# async def extract(text_input: TextInput):
# keywords = extract_target_entity(text_input.text)
# return {"keywords": [keywords]}
#
# @app.post("/category", response_model=KeywordResponse)
# async def extract(text_input: TextInput):
# keywords = classify_categories(text_input.text)
# return {"keywords": [keywords]}
@app.post("/keyword", response_model=CombinedResponse)
async def extract_all(text_input: TextInput):
text = text_input.text
# 세 작업을 병렬 실행
keywords_task = asyncio.to_thread(extract_keywords, text)
target_task = asyncio.to_thread(extract_target_entity, text)
category_task = asyncio.to_thread(classify_categories, text)
keywords, target, category = await asyncio.gather(
keywords_task,
target_task,
category_task
)
return {
"keywords": keywords,
"target": target,
"category": category
}