Fetch the repository succeeded.
# -*- coding:utf-8 -*-
import json
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, get_feed, get_lyrics, get_credits
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(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(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(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(request: Request, token: str = Depends(get_token)):
req = await request.json()
prompt = req.get("prompt")
if prompt is None:
raise HTTPException(
detail="prompt is required", status_code=status.HTTP_400_BAD_REQUEST
)
try:
resp = await generate_lyrics(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.get("/get_credits")
async def fetch_credits(token: str = Depends(get_token)):
try:
resp = await get_credits(token)
return resp
except Exception as e:
raise HTTPException(
detail=str(e), status_code=status.HTTP_500_INTERNAL_SERVER_ERROR
)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。