rajeshradhakrishnan's picture
English-Malayalam Translate v28
0203d1c
raw
history blame
868 Bytes
import os
from fastapi import FastAPI, Request
from fastapi.staticfiles import StaticFiles
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from transformers import pipeline
app = FastAPI()
pipe_flan = pipeline("translation_xx_to_en", model="google/flan-t5-base")
@app.get("/infer_t5")
def t5(input):
output = pipe_flan(input)
return {"output": output[0]["generated_text"]}
app.mount("/", StaticFiles(directory="static", html=True), name="static")
# @app.get("/")
# def index() -> FileResponse:
# return FileResponse(path="/app/static/index.html", media_type="text/html")
templates = Jinja2Templates(directory="templates")
@app.get("/", response_class=HTMLResponse)
async def index():
apikey = {"APIKEY": os.environ.get("API_KEY")}
return templates.TemplateResponse("index.html", {"apikey": apikey})