|
1 | 1 | from fastapi import FastAPI, Request, Form |
2 | 2 | from fastapi.templating import Jinja2Templates |
3 | 3 | from fastapi.responses import HTMLResponse |
4 | | -from classifier_model import load_models, classify_text |
| 4 | +from app.classifier_model import load_models, classify_text |
| 5 | +import os |
5 | 6 |
|
6 | 7 | print("svc_texpose - starting") |
7 | 8 |
|
|
11 | 12 | # Initialize FastAPI app |
12 | 13 | app = FastAPI() |
13 | 14 |
|
14 | | -# Set up Jinja2 templates |
15 | | -templates = Jinja2Templates(directory="templates") |
| 15 | +BASE_DIR = os.path.dirname(os.path.abspath(__file__)) # Gets /app/app/ |
| 16 | +TEMPLATES_DIR = os.path.join(BASE_DIR, "templates") |
| 17 | + |
| 18 | +templates = Jinja2Templates(directory=TEMPLATES_DIR) |
| 19 | + |
16 | 20 |
|
17 | 21 | @app.get("/", response_class=HTMLResponse) |
18 | 22 | async def root(request: Request): |
19 | 23 | return templates.TemplateResponse("index.html", {"request": request, "prediction": None, "input_text": ""}) |
20 | 24 |
|
21 | 25 | @app.post("/classify", response_class=HTMLResponse) |
22 | | -async def classify(request: Request, input_text: str = Form(...)): |
| 26 | +async def classify(request: Request, input_text: str = Form(default="")): |
23 | 27 | if input_text.strip(): # Ensure input is not empty |
24 | 28 | result = classify_text(input_text, model_ai_hum, model_llm, tokenizer) |
25 | 29 | prediction = result["type"] |
|
0 commit comments