File size: 837 Bytes
8d63192
aeb02ac
f3b1912
c0f3434
aeb02ac
596c31b
f3b1912
 
 
11bf9e7
f3b1912
affce81
596c31b
f3b1912
 
596c31b
 
f3b1912
 
 
c0f3434
 
 
 
1f030e7
aeb02ac
c0f3434
0203d1c
aeb02ac
4a794f1
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
import os
from fastapi import FastAPI, Request
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse
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("/chat")
async def index():
    apikey = {"APIKEY": os.environ.get("API_KEY")}
    return templates.TemplateResponse("chat.html", {"apikey": apikey})