PyxiLabs commited on
Commit
16623fe
·
verified ·
1 Parent(s): 6b68b98

Update core/app.py

Browse files
Files changed (1) hide show
  1. 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
- VOICE_MAPPING = {
23
- "charlottee": "XB0fDUnXU5powFXDhCwa",
24
- "daniel": "onwK4e9ZLuTAKqWW03F9",
25
- "callum": "N2lVS1w4EtoT3dr4eOWO",
26
- "charlie": "IKne3meq5aSn9XLyUdCD",
27
- "clyde": "2EiwWnXFnvU5JabPnv8n",
28
- "dave": "CYw3kZ02Hs0563khs1Fj",
29
- "emily": "LcfcDJNUP1GQjkzn1xUU",
30
- "ethan": "g5CIjZEefAph4nQFvHAz",
31
- "fin": "D38z5RcWu1voky8WS1ja",
32
- "freya": "jsCqWAovK2LkecY7zXl4",
33
- "gigi": "jBpfuIE2acCO8z3wKNLl",
34
- "giovanni": "zcAOhNBS3c14rBihAFp1",
35
- "glinda": "z9fAnlkpzviPz146aGWa",
36
- "grace": "oWAxZDx7w5VEj9dCyTzz",
37
- "harry": "SOYHLrjzK2X1ezoPC6cr",
38
- "james": "ZQe5CZNOzWyzPSCn5a3c",
39
- "jeremy": "bVMeCyTHy58xNoL34h3p"
 
 
 
 
 
 
 
 
40
  }
41
 
42
  class SpeechRequest(BaseModel):
43
- model: Optional[str] = Field(default="eleven_multilingual_v2")
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=request.model,
53
- voice=request.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.post("/v1/voices")
66
- @app.get("/v1/voices")
67
- async def get_voices():
68
- return {"voices": list(VOICE_MAPPING.keys())}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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):