-
Notifications
You must be signed in to change notification settings - Fork 22
/
main.py
102 lines (83 loc) · 2.6 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
from fastapi import Depends, FastAPI, HTTPException, Request, status
from fastapi.middleware.cors import CORSMiddleware
import schemas
from deps import get_token
from utils import (
generate_lyrics,
generate_music_with_prompt,
generate_music_with_lyrics,
get_feed_by_clip_id,
get_lyrics,
concat_music,
)
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/")
async def get_root():
return schemas.Response()
@app.post("/generate")
async def generate(
data: schemas.CustomModeGenerateParam, token: str = Depends(get_token)
):
try:
resp = await generate_music_with_lyrics(data.dict(), token)
return resp
except Exception as e:
raise HTTPException(
detail=str(e), status_code=status.HTTP_500_INTERNAL_SERVER_ERROR
)
@app.post("/generate/description-mode")
async def generate_with_song_description(
data: schemas.DescriptionModeGenerateParam, token: str = Depends(get_token)
):
try:
resp = await generate_music_with_prompt(data.dict(), token)
return resp
except Exception as e:
raise HTTPException(
detail=str(e), status_code=status.HTTP_500_INTERNAL_SERVER_ERROR
)
@app.get("/feed/{aid}")
async def fetch_feed(aid: str, token: str = Depends(get_token)):
try:
resp = await get_feed_by_clip_id(aid, token)
return resp
except Exception as e:
raise HTTPException(
detail=str(e), status_code=status.HTTP_500_INTERNAL_SERVER_ERROR
)
@app.post("/generate/lyrics/")
async def generate_lyrics_post(
data: schemas.GenerateLyricsParam, token: str = Depends(get_token)
):
try:
resp = await generate_lyrics(data.prompt, token)
return resp
except Exception as e:
raise HTTPException(
detail=str(e), status_code=status.HTTP_500_INTERNAL_SERVER_ERROR
)
@app.get("/lyrics/{lid}")
async def fetch_lyrics(lid: str, token: str = Depends(get_token)):
try:
resp = await get_lyrics(lid, token)
return resp
except Exception as e:
raise HTTPException(
detail=str(e), status_code=status.HTTP_500_INTERNAL_SERVER_ERROR
)
@app.post("/generate/concat")
async def concat(data: schemas.ConcatParam, token: str = Depends(get_token)):
try:
resp = await concat_music(data.dict(), token)
return resp
except Exception as e:
raise HTTPException(
detail=str(e), status_code=status.HTTP_500_INTERNAL_SERVER_ERROR
)