Update core/app.py
Browse files- core/app.py +56 -25
core/app.py
CHANGED
@@ -19,28 +19,36 @@ app.mount("/static", StaticFiles(directory="static"), name="static")
|
|
19 |
# Initialize templates
|
20 |
templates = Jinja2Templates(directory="templates")
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
"
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
}
|
41 |
|
42 |
class SpeechRequest(BaseModel):
|
43 |
-
model: Optional[str] = Field(default="
|
44 |
input: str = Field(..., max_length=500)
|
45 |
voice: str
|
46 |
|
@@ -48,9 +56,17 @@ class SpeechRequest(BaseModel):
|
|
48 |
@app.get("/v1/audio/speech")
|
49 |
async def create_speech(request: SpeechRequest):
|
50 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
result = generate_speech(
|
52 |
-
model=
|
53 |
-
voice=
|
54 |
input_text=request.input
|
55 |
)
|
56 |
|
@@ -62,10 +78,25 @@ async def create_speech(request: SpeechRequest):
|
|
62 |
except Exception as e:
|
63 |
raise HTTPException(status_code=500, detail=str(e))
|
64 |
|
65 |
-
@app.
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
@app.get("/", response_class=HTMLResponse)
|
71 |
async def root(request: Request):
|
|
|
19 |
# Initialize templates
|
20 |
templates = Jinja2Templates(directory="templates")
|
21 |
|
22 |
+
# Model and voice information structure
|
23 |
+
MODEL_INFO = {
|
24 |
+
"Pyx r1-voice": {
|
25 |
+
"name": "Pyx r1-voice",
|
26 |
+
"created": "2024-12-12",
|
27 |
+
"owner": "Pyxilabs AI Studio",
|
28 |
+
"voices": {
|
29 |
+
"charlottee": "XB0fDUnXU5powFXDhCwa",
|
30 |
+
"daniel": "onwK4e9ZLuTAKqWW03F9",
|
31 |
+
"callum": "N2lVS1w4EtoT3dr4eOWO",
|
32 |
+
"charlie": "IKne3meq5aSn9XLyUdCD",
|
33 |
+
"clyde": "2EiwWnXFnvU5JabPnv8n",
|
34 |
+
"dave": "CYw3kZ02Hs0563khs1Fj",
|
35 |
+
"emily": "LcfcDJNUP1GQjkzn1xUU",
|
36 |
+
"ethan": "g5CIjZEefAph4nQFvHAz",
|
37 |
+
"fin": "D38z5RcWu1voky8WS1ja",
|
38 |
+
"freya": "jsCqWAovK2LkecY7zXl4",
|
39 |
+
"gigi": "jBpfuIE2acCO8z3wKNLl",
|
40 |
+
"giovanni": "zcAOhNBS3c14rBihAFp1",
|
41 |
+
"glinda": "z9fAnlkpzviPz146aGWa",
|
42 |
+
"grace": "oWAxZDx7w5VEj9dCyTzz",
|
43 |
+
"harry": "SOYHLrjzK2X1ezoPC6cr",
|
44 |
+
"james": "ZQe5CZNOzWyzPSCn5a3c",
|
45 |
+
"jeremy": "bVMeCyTHy58xNoL34h3p"
|
46 |
+
}
|
47 |
+
}
|
48 |
}
|
49 |
|
50 |
class SpeechRequest(BaseModel):
|
51 |
+
model: Optional[str] = Field(default="Pyx r1-voice")
|
52 |
input: str = Field(..., max_length=500)
|
53 |
voice: str
|
54 |
|
|
|
56 |
@app.get("/v1/audio/speech")
|
57 |
async def create_speech(request: SpeechRequest):
|
58 |
try:
|
59 |
+
if request.model != "Pyx r1-voice":
|
60 |
+
raise HTTPException(status_code=400, detail="Invalid model. Only 'Pyx r1-voice' is supported.")
|
61 |
+
|
62 |
+
if request.voice not in MODEL_INFO["Pyx r1-voice"]["voices"]:
|
63 |
+
raise HTTPException(status_code=400, detail="Invalid voice ID")
|
64 |
+
|
65 |
+
voice_id = MODEL_INFO["Pyx r1-voice"]["voices"][request.voice]
|
66 |
+
|
67 |
result = generate_speech(
|
68 |
+
model="eleven_multilingual_v2",
|
69 |
+
voice=voice_id,
|
70 |
input_text=request.input
|
71 |
)
|
72 |
|
|
|
78 |
except Exception as e:
|
79 |
raise HTTPException(status_code=500, detail=str(e))
|
80 |
|
81 |
+
@app.get("/v1/models")
|
82 |
+
async def get_models():
|
83 |
+
models_response = []
|
84 |
+
for model_id, model_data in MODEL_INFO.items():
|
85 |
+
model_info = {
|
86 |
+
"id": model_id,
|
87 |
+
"name": model_data["name"],
|
88 |
+
"created": model_data["created"],
|
89 |
+
"owner": model_data["owner"],
|
90 |
+
"vocals": [
|
91 |
+
{
|
92 |
+
"id": voice_name,
|
93 |
+
}
|
94 |
+
for voice_name, voice_id in model_data["voices"].items()
|
95 |
+
]
|
96 |
+
}
|
97 |
+
models_response.append(model_info)
|
98 |
+
|
99 |
+
return {"models": models_response}
|
100 |
|
101 |
@app.get("/", response_class=HTMLResponse)
|
102 |
async def root(request: Request):
|