-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebui.py
33 lines (23 loc) · 947 Bytes
/
webui.py
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
33
from fastapi import FastAPI, Request, Form
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from fastapi.staticfiles import StaticFiles
from core.logger import Logger
from config.init_config import load_model_paths
from utils.pipeline import Pipeline
logger = Logger(__name__)
app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
TOML_PATH = "config/paths.toml"
init_config = load_model_paths(TOML_PATH)
pipeline = Pipeline()
@app.get("/", response_class=HTMLResponse)
async def read_item(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
@app.post("/predict/")
async def predict(request: Request, text: str = Form(...)):
result = pipeline.get_sentiment(text)
return {"result": result}
# To run the webui, run the following command:
# uvicorn webui:app --reload