Spaces:
Runtime error
Runtime error
Update TextGen/router.py
Browse files- TextGen/router.py +34 -2
TextGen/router.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
from pydantic import BaseModel
|
| 2 |
-
|
|
|
|
| 3 |
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
|
| 5 |
from langchain.chains import LLMChain
|
|
@@ -11,6 +12,12 @@ from langchain_google_genai import (
|
|
| 11 |
)
|
| 12 |
from TextGen import app
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
class Generate(BaseModel):
|
| 15 |
text:str
|
| 16 |
|
|
@@ -52,4 +59,29 @@ def api_home():
|
|
| 52 |
|
| 53 |
@app.post("/api/generate", summary="Generate text from prompt", tags=["Generate"], response_model=Generate)
|
| 54 |
def inference(input_prompt: str):
|
| 55 |
-
return generate_text(prompt=input_prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from pydantic import BaseModel
|
| 2 |
+
from fastapi import FastAPI, HTTPException, Query
|
| 3 |
+
from fastapi.responses import FileResponse
|
| 4 |
from fastapi.middleware.cors import CORSMiddleware
|
| 5 |
|
| 6 |
from langchain.chains import LLMChain
|
|
|
|
| 12 |
)
|
| 13 |
from TextGen import app
|
| 14 |
|
| 15 |
+
my_hf_token=os.environ["HF_TOKEN"]
|
| 16 |
+
|
| 17 |
+
tts_client = Client("https://jofthomas-xtts.hf.space/--replicas/sxv98/",hf_token=my_hf_token)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
class Generate(BaseModel):
|
| 22 |
text:str
|
| 23 |
|
|
|
|
| 59 |
|
| 60 |
@app.post("/api/generate", summary="Generate text from prompt", tags=["Generate"], response_model=Generate)
|
| 61 |
def inference(input_prompt: str):
|
| 62 |
+
return generate_text(prompt=input_prompt)
|
| 63 |
+
|
| 64 |
+
@app.get("/generate_wav")
|
| 65 |
+
async def generate_wav(text: str, language: str = "en"):
|
| 66 |
+
try:
|
| 67 |
+
# Use the Gradio client to generate the wav file
|
| 68 |
+
result = tts_client.predict(
|
| 69 |
+
text, # str in 'Text Prompt' Textbox component
|
| 70 |
+
language, # str in 'Language' Dropdown component
|
| 71 |
+
"./narator_out.wav", # str (filepath on your computer (or URL) of file) in 'Reference Audio' Audio component
|
| 72 |
+
"./narator_out.wav", # str (filepath on your computer (or URL) of file) in 'Use Microphone for Reference' Audio component
|
| 73 |
+
False, # bool in 'Use Microphone' Checkbox component
|
| 74 |
+
False, # bool in 'Cleanup Reference Voice' Checkbox component
|
| 75 |
+
False, # bool in 'Do not use language auto-detect' Checkbox component
|
| 76 |
+
True, # bool in 'Agree' Checkbox component
|
| 77 |
+
fn_index=1
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
# Get the path of the generated wav file
|
| 81 |
+
wav_file_path = result[1]
|
| 82 |
+
|
| 83 |
+
# Return the generated wav file as a response
|
| 84 |
+
return FileResponse(wav_file_path, media_type="audio/wav", filename="output.wav")
|
| 85 |
+
|
| 86 |
+
except Exception as e:
|
| 87 |
+
raise HTTPException(status_code=500, detail=str(e))
|