Update TextGen/router.py
Browse files- TextGen/router.py +27 -4
TextGen/router.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import time
|
| 3 |
from pydantic import BaseModel
|
| 4 |
-
from fastapi import FastAPI, HTTPException, Query
|
| 5 |
from fastapi.responses import FileResponse
|
| 6 |
from fastapi.middleware.cors import CORSMiddleware
|
| 7 |
|
|
@@ -67,15 +67,37 @@ def api_home():
|
|
| 67 |
def inference(input_prompt: str):
|
| 68 |
return generate_text(prompt=input_prompt)
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
@app.get("/generate_wav")
|
| 71 |
-
async def generate_wav(
|
| 72 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
# Use the Gradio client to generate the wav file
|
| 74 |
result = tts_client.predict(
|
| 75 |
text, # str in 'Text Prompt' Textbox component
|
| 76 |
language, # str in 'Language' Dropdown component
|
| 77 |
-
|
| 78 |
-
|
| 79 |
False, # bool in 'Use Microphone' Checkbox component
|
| 80 |
False, # bool in 'Cleanup Reference Voice' Checkbox component
|
| 81 |
False, # bool in 'Do not use language auto-detect' Checkbox component
|
|
@@ -92,6 +114,7 @@ async def generate_wav(text: str, language: str = "en"):
|
|
| 92 |
except Exception as e:
|
| 93 |
raise HTTPException(status_code=500, detail=str(e))
|
| 94 |
|
|
|
|
| 95 |
@app.get("/generate_song")
|
| 96 |
async def generate_song(text: str):
|
| 97 |
try:
|
|
|
|
| 1 |
import os
|
| 2 |
import time
|
| 3 |
from pydantic import BaseModel
|
| 4 |
+
from fastapi import FastAPI, HTTPException, Query, Request
|
| 5 |
from fastapi.responses import FileResponse
|
| 6 |
from fastapi.middleware.cors import CORSMiddleware
|
| 7 |
|
|
|
|
| 67 |
def inference(input_prompt: str):
|
| 68 |
return generate_text(prompt=input_prompt)
|
| 69 |
|
| 70 |
+
from fastapi import FastAPI, HTTPException, Request
|
| 71 |
+
from fastapi.responses import FileResponse
|
| 72 |
+
import json
|
| 73 |
+
|
| 74 |
+
app = FastAPI()
|
| 75 |
+
|
| 76 |
@app.get("/generate_wav")
|
| 77 |
+
async def generate_wav(request: Request):
|
| 78 |
try:
|
| 79 |
+
body = await request.json()
|
| 80 |
+
text = body.get("text")
|
| 81 |
+
language = body.get("language", "en")
|
| 82 |
+
voice_choice = body.get("voice_choice", "./blacksmith.mp3")
|
| 83 |
+
|
| 84 |
+
valid_voices = [
|
| 85 |
+
"./blacksmith.mp3",
|
| 86 |
+
"./female.wav",
|
| 87 |
+
"./female.mp3",
|
| 88 |
+
"./narator_out.wav",
|
| 89 |
+
"./blacksmith2.mp3"
|
| 90 |
+
]
|
| 91 |
+
|
| 92 |
+
if voice_choice not in valid_voices:
|
| 93 |
+
raise HTTPException(status_code=400, detail="Invalid voice choice")
|
| 94 |
+
|
| 95 |
# Use the Gradio client to generate the wav file
|
| 96 |
result = tts_client.predict(
|
| 97 |
text, # str in 'Text Prompt' Textbox component
|
| 98 |
language, # str in 'Language' Dropdown component
|
| 99 |
+
voice_choice, # str (filepath on your computer (or URL) of file) in 'Reference Audio' Audio component
|
| 100 |
+
voice_choice, # str (filepath on your computer (or URL) of file) in 'Use Microphone for Reference' Audio component
|
| 101 |
False, # bool in 'Use Microphone' Checkbox component
|
| 102 |
False, # bool in 'Cleanup Reference Voice' Checkbox component
|
| 103 |
False, # bool in 'Do not use language auto-detect' Checkbox component
|
|
|
|
| 114 |
except Exception as e:
|
| 115 |
raise HTTPException(status_code=500, detail=str(e))
|
| 116 |
|
| 117 |
+
|
| 118 |
@app.get("/generate_song")
|
| 119 |
async def generate_song(text: str):
|
| 120 |
try:
|