-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfast_api.py
122 lines (69 loc) · 2.42 KB
/
fast_api.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
from fastapi import FastAPI, File, Form, UploadFile
from fastapi.responses import JSONResponse
from pydantic import BaseModel
import os
import json
import uuid
from datetime import datetime
import sys
sys.path.append('..')
import inference
import translate_chatgpt
import summary_chatgpt
import keyword_chatgpt
language_list = {'ENGLISH': 'English', 'JAPANESE': 'Japanese', 'CHINESE': 'Chinese', 'VIETNAMESE': 'Vietnamese'}
class ASR_Item(BaseModel):
category: str
lectureId : int
class Translate_Item(BaseModel):
contents: str
language: str
class Summary_Item(BaseModel):
contents: str
class Keyword_Item(BaseModel):
contents: str
app = FastAPI()
@app.get('/glee')
#async def root():
def root():
return {'message': 'Fast API'}
@app.get('/glee/home')
def glee():
return {'message': 'glee home'}
@app.post("/glee/asr")
# async def glee_asr(file : UploadFile):
async def glee_asr(category : str = Form(...), lectureId : int = Form(...), file : UploadFile = File(...)):
save_audio_dir = ''
# category = category
audio_file = await file.read()
current_time = datetime.now()
current_time = current_time.strftime('%Y%m%d_%H%M%S')
file_name = current_time + '_' + str(uuid.uuid4()) + '.' + str(file.filename).split('.')[-1]
with open(os.path.join(save_audio_dir, file_name), "wb") as f:
f.write(audio_file)
result = inference.run_asr(category, lectureId, file_name)
# return JSONResponse({"filename" : file.filename})
return result
@app.post('/glee/translate')
async def glee_translate(item : Translate_Item):
contents = item.contents
# language = item.language
if item.language not in language_list:
# return {}
return # null 리턴
language = language_list[item.language]
result = translate_chatgpt.run_translate(contents, language)
# print(json.loads(result))
return result
@app.post('/glee/summary')
async def glee_summary(item : Summary_Item):
contents = item.contents
result = summary_chatgpt.run_summary(contents)
# print(json.loads(result))
return result
@app.post('/glee/keyword')
async def glee_keyword(item : Keyword_Item):
contents = item.contents
result = keyword_chatgpt.run_keyword(contents)
# print(json.loads(result))
return result