Spaces:
Runtime error
Runtime error
File size: 1,020 Bytes
8d63192 aeb02ac f3b1912 c0f3434 a894f41 f3b1912 696bdbb f3b1912 11bf9e7 f3b1912 596c31b f3b1912 696bdbb f3b1912 c0f3434 400caeb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import os
from fastapi import FastAPI, Request
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse
from transformers import MBartForConditionalGeneration, MBart50TokenizerFast
model = MBartForConditionalGeneration.from_pretrained("facebook/mbart-large-50-one-to-many-mmt")
tokenizer = MBart50TokenizerFast.from_pretrained("facebook/mbart-large-50-one-to-many-mmt", src_lang="en_XX")
app = FastAPI()
@app.get("/infer_t5")
def t5(input):
model_inputs = tokenizer(input, return_tensors="pt")
# translate from English to Malayalam
generated_tokens = model.generate(
**model_inputs,
forced_bos_token_id=tokenizer.lang_code_to_id["ml_IN"]
)
output = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
return {"output":output}
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") |