44from app .classifier_model import load_models , classify_text
55import os
66from fastapi .staticfiles import StaticFiles
7+ from fastapi .responses import JSONResponse
78
89
910print ("svc_texpose - starting" )
2526async def root (request : Request ):
2627 return templates .TemplateResponse ("index.html" , {"request" : request , "prediction" : None , "input_text" : "" })
2728
28- @app .post ("/classify" , response_class = HTMLResponse )
29- async def classify (request : Request , input_text : str = Form (default = "" )):
30- if input_text .strip (): # Ensure input is not empty
29+
30+
31+
32+ @app .post ("/api/classify" )
33+ async def classify_api (request : Request ):
34+ data = await request .json ()
35+ input_text = data .get ("input_text" , "" )
36+
37+ if input_text .strip ():
3138 result = classify_text (input_text , model_ai_hum , model_llm , tokenizer )
3239 prediction = result ["type" ]
3340
34- # Ensure "llm" exists and is not empty
3541 if result .get ("llm" ):
3642 prediction += f" Using { result ['llm' ]} "
3743
38- return templates .TemplateResponse ("index.html" , {"request" : request , "prediction" : prediction , "input_text" : input_text })
44+ return JSONResponse (content = {"prediction" : prediction })
45+
46+ return JSONResponse (content = {"prediction" : "No text provided." })
3947
40- return templates . TemplateResponse ( "index.html" , { "request" : request , "prediction" : "No text provided." , "input_text" : "" })
48+
0 commit comments