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 ...@@ -6,6 +6,7 @@ from fastapi import FastAPI, HTTPException, status
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
import schemas import schemas
import classifiers
from ScraperNoticias.globalScraper import GlobalScraper from ScraperNoticias.globalScraper import GlobalScraper
# APP # APP
...@@ -63,8 +64,24 @@ async def predict_toxicity( ...@@ -63,8 +64,24 @@ async def predict_toxicity(
Returns: Returns:
The toxicity of the text.""" The toxicity of the text."""
# TODO: Aquí invocamos al modelo de toxicidad y devolvemos la predicción. pred = classifiers.predict_toxicity(text.text)
return {"prediction": 0.0} 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"]) @app.post("/scrap", response_model=schemas.ScrapedComments, tags=["Scraper"])
async def scrap_url( async def scrap_url(
......
...@@ -8,7 +8,8 @@ class InputText(BaseModel): ...@@ -8,7 +8,8 @@ class InputText(BaseModel):
class OutputPrediction(BaseModel): class OutputPrediction(BaseModel):
"""Schema to define the output predictions' structure.""" """Schema to define the output predictions' structure."""
prediction: float label: str
score: float
class InputURL(BaseModel): class InputURL(BaseModel):
url: HttpUrl 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