buchi-stdesign's picture
Upload 3 files
c253bc8 verified
raw
history blame
765 Bytes
from fastapi import FastAPI, Query
import requests
app = FastAPI()
GRADIO_API = "https://buchi-stdesign-sbv2-editor-demo.hf.space/run/predict"
GRADIO_FILE_BASE = "https://buchi-stdesign-sbv2-editor-demo.hf.space/file"
@app.get("/voice")
def get_voice(text: str = Query(...), style: str = "小春音アミ"):
payload = {
"data": [text, style, 1.0, 1.0, 0.5]
}
headers = {"Content-Type": "application/json"}
res = requests.post(GRADIO_API, json=payload, headers=headers)
if res.status_code != 200:
return {"error": "Gradio backend error", "detail": res.text}
result = res.json()
wav_path = result["data"][0] # tmp/audio.wav
wav_url = f"{GRADIO_FILE_BASE}/{wav_path}"
return {"audio_url": wav_url}