Spaces:
Sleeping
Sleeping
File size: 847 Bytes
7d63c90 |
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 34 35 36 37 38 |
from fastapi import FastAPI
from fastapi.responses import JSONResponse
from fastapi.middleware.cors import CORSMiddleware
from textclassifier import TextClassifier
from dto import ClassifyRequest
from transformers import pipeline
hub_model_id = "NathyB/Hate-Speech-Detection-in-Amharic-Language-mBERT"
text_classifier = pipeline("text-classification", model=hub_model_id)
app = FastAPI()
# Setup cors
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.post("/textclassify")
def classifyText(request_body:ClassifyRequest):
text = request_body.text
summary = TextClassifier(text_classifier).classify(text)
return JSONResponse(content=summary, status_code=201)
# Get route
@app.get("/")
def home():
return {"hello":"world"} |