Spaces:
Sleeping
Sleeping
fixed analyze.py
Browse files- app/routers/analyze.py +6 -21
app/routers/analyze.py
CHANGED
|
@@ -1,13 +1,7 @@
|
|
| 1 |
-
from fastapi import
|
| 2 |
-
from
|
| 3 |
-
from pydantic import BaseModel, HttpUrl, Field
|
| 4 |
from typing import Dict, Any, List
|
| 5 |
import logging
|
| 6 |
-
import sys
|
| 7 |
-
import os
|
| 8 |
-
|
| 9 |
-
# Add src to Python path
|
| 10 |
-
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'src'))
|
| 11 |
|
| 12 |
from mediaunmasked.scrapers.article_scraper import ArticleScraper
|
| 13 |
from mediaunmasked.analyzers.scoring import MediaScorer
|
|
@@ -17,20 +11,11 @@ from mediaunmasked.utils.logging_config import setup_logging
|
|
| 17 |
setup_logging()
|
| 18 |
logger = logging.getLogger(__name__)
|
| 19 |
|
| 20 |
-
# Initialize
|
| 21 |
-
|
| 22 |
scraper = ArticleScraper()
|
| 23 |
scorer = MediaScorer()
|
| 24 |
|
| 25 |
-
# Configure CORS
|
| 26 |
-
app.add_middleware(
|
| 27 |
-
CORSMiddleware,
|
| 28 |
-
allow_origins=["*"],
|
| 29 |
-
allow_credentials=True,
|
| 30 |
-
allow_methods=["*"],
|
| 31 |
-
allow_headers=["*"],
|
| 32 |
-
)
|
| 33 |
-
|
| 34 |
class ArticleRequest(BaseModel):
|
| 35 |
url: HttpUrl
|
| 36 |
|
|
@@ -55,7 +40,7 @@ class AnalysisResponse(BaseModel):
|
|
| 55 |
flagged_phrases: List[str]
|
| 56 |
media_score: MediaScore
|
| 57 |
|
| 58 |
-
@
|
| 59 |
async def analyze_article(request: ArticleRequest) -> AnalysisResponse:
|
| 60 |
"""
|
| 61 |
Analyze an article for bias, sentiment, and credibility.
|
|
@@ -138,7 +123,7 @@ async def analyze_article(request: ArticleRequest) -> AnalysisResponse:
|
|
| 138 |
detail=f"Analysis failed: {str(e)}"
|
| 139 |
)
|
| 140 |
|
| 141 |
-
@
|
| 142 |
async def debug_response():
|
| 143 |
mock_analysis = {
|
| 144 |
"headline": "Test Headline",
|
|
|
|
| 1 |
+
from fastapi import APIRouter, HTTPException
|
| 2 |
+
from pydantic import BaseModel, HttpUrl
|
|
|
|
| 3 |
from typing import Dict, Any, List
|
| 4 |
import logging
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
from mediaunmasked.scrapers.article_scraper import ArticleScraper
|
| 7 |
from mediaunmasked.analyzers.scoring import MediaScorer
|
|
|
|
| 11 |
setup_logging()
|
| 12 |
logger = logging.getLogger(__name__)
|
| 13 |
|
| 14 |
+
# Initialize router and dependencies
|
| 15 |
+
router = APIRouter(tags=["analysis"])
|
| 16 |
scraper = ArticleScraper()
|
| 17 |
scorer = MediaScorer()
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
class ArticleRequest(BaseModel):
|
| 20 |
url: HttpUrl
|
| 21 |
|
|
|
|
| 40 |
flagged_phrases: List[str]
|
| 41 |
media_score: MediaScore
|
| 42 |
|
| 43 |
+
@router.post("/analyze", response_model=AnalysisResponse)
|
| 44 |
async def analyze_article(request: ArticleRequest) -> AnalysisResponse:
|
| 45 |
"""
|
| 46 |
Analyze an article for bias, sentiment, and credibility.
|
|
|
|
| 123 |
detail=f"Analysis failed: {str(e)}"
|
| 124 |
)
|
| 125 |
|
| 126 |
+
@router.get("/debug")
|
| 127 |
async def debug_response():
|
| 128 |
mock_analysis = {
|
| 129 |
"headline": "Test Headline",
|