Spaces:
Running
Running
| from fastapi import APIRouter, HTTPException | |
| from pydantic import BaseModel | |
| from app.pipelines.text_ai import analyze_ai_text | |
| from app.pipelines.fakenews import analyze_fakenews_text | |
| router = APIRouter() | |
| class TextRequest(BaseModel): | |
| text: str | |
| async def analyze_text(body: TextRequest): | |
| if not body.text or not body.text.strip(): | |
| raise HTTPException(status_code=400, detail="Le texte ne peut pas être vide.") | |
| res = analyze_ai_text(body.text) | |
| return { | |
| "status": "success", | |
| "verdict": res["verdict"], | |
| "ai_prob": res["ai_prob"], | |
| "human_prob": res["human_prob"] | |
| } | |
| async def analyze_fakenews(body: TextRequest): | |
| if not body.text or not body.text.strip(): | |
| raise HTTPException(status_code=400, detail="Le texte ne peut pas être vide.") | |
| res = analyze_fakenews_text(body.text) | |
| return { | |
| "status": "success", | |
| "verdict": res["verdict"], | |
| "fake_prob": res["fake_prob"], | |
| "real_prob": res["real_prob"] | |
| } | |
| async def analyze_text_full(body: TextRequest): | |
| if not body.text or not body.text.strip(): | |
| raise HTTPException(status_code=400, detail="Le texte ne peut pas être vide.") | |
| res_ai = analyze_ai_text(body.text) | |
| res_fn = analyze_fakenews_text(body.text) | |
| is_ai = res_ai["is_ai"] | |
| is_fake = res_fn["is_fake"] | |
| if is_ai and is_fake: | |
| verdict = "DANGER MAX : Fake news générée par IA" | |
| elif is_ai and not is_fake: | |
| verdict = "Texte IA mais contenu vérifié" | |
| elif not is_ai and is_fake: | |
| verdict = "Désinformation humaine" | |
| else: | |
| verdict = "Texte humain, contenu vérifié" | |
| return { | |
| "status": "success", | |
| "verdict": verdict, | |
| "ai_prob": res_ai["ai_prob"], | |
| "fake_news_prob": res_fn["fake_prob"], | |
| "is_ai_generated": is_ai, | |
| "is_fake_news": is_fake | |
| } | |