1 Star 1 Fork 0

jobily/Suno-API

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
main.py 2.66 KB
Copy Edit Raw Blame History
# -*- 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
)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hubo/Suno-API.git
git@gitee.com:hubo/Suno-API.git
hubo
Suno-API
Suno-API
main

Search