my question is how do I post the output using json as backend? just need to post translate text my backend coding
from fastapi import FastAPI, Form, Depends, Request
from fastapi.templating import Jinja2Templates
from googletrans import Translator
import uvicorn
#connect to translator
translator = Translator(service_urls=['translate.googleapis.com'])
app = FastAPI(debug=True)
templates = Jinja2Templates(directory="template")
@app.get("/")
async def home(request: Request):
return ('index.html',{'request': request})
@app.post("/")
async def trans(request: Request):
text = request.get('Input_text')
lang = request.get('lang_select')
# detect language text
#dt = translator.detect(text)
# detect input language
#dt2 = dt.lang
# translate the text
translated = translator.translate(text,lang)
out_text = translated.text
pronouce = out_text.pronunciation
#transData={'request': request ,'text_translate': out_text,'text_pronouce':pronouce}
return ({'request': request ,'text_translate': out_text,'text_pronouce':pronouce})
if __name__=="__main__":
uvicorn.run(app,host="127.0.0.1",port=8000)
and json format to post the output
{
"text_translate": "out_text"
"text_pronouce":"pronouce"
}
clearly, my post-return make this code not function properly. Any help or solution is appreciated...stuck for days now