Commit 227a17ae by Jaime Collado

Added toxicity and constructiveness models

parent c31e087e
Showing with 21 additions and 3 deletions
......@@ -6,6 +6,7 @@ from fastapi import FastAPI, HTTPException, status
from fastapi.middleware.cors import CORSMiddleware
import schemas
import classifiers
from ScraperNoticias.globalScraper import GlobalScraper
# APP
......@@ -63,8 +64,24 @@ async def predict_toxicity(
Returns:
The toxicity of the text."""
# TODO: Aquí invocamos al modelo de toxicidad y devolvemos la predicción.
return {"prediction": 0.0}
pred = classifiers.predict_toxicity(text.text)
print(pred, type(pred))
return pred[0]
@app.post("/constructividad", response_model=schemas.OutputPrediction, tags=["Prediction"])
async def predict_constructiveness(
text: schemas.InputText
):
"""Predicts constructiveness based on a given input text.
Args:
text: String containing news.
Returns:
The constructiveness of the text."""
pred = classifiers.predict_constructiveness(text.text)
return pred[0]
@app.post("/scrap", response_model=schemas.ScrapedComments, tags=["Scraper"])
async def scrap_url(
......
......@@ -8,7 +8,8 @@ class InputText(BaseModel):
class OutputPrediction(BaseModel):
"""Schema to define the output predictions' structure."""
prediction: float
label: str
score: float
class InputURL(BaseModel):
url: HttpUrl
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment