Spaces:
Sleeping
Download CLAUDE.md from Bjornpool/truthscan-ai-backend: direct link, hf CLI and curl.
- Browser
- Download file 5.21 kB
-
https://huggingface.co/spaces/Bjornpool/truthscan-ai-backend/resolve/main/CLAUDE.md
- Command line
-
hf download hf://spaces/Bjornpool/truthscan-ai-backend/CLAUDE.md
-
curl -L -o CLAUDE.md https://huggingface.co/spaces/Bjornpool/truthscan-ai-backend/resolve/main/CLAUDE.md
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
TruthScan AI is a master's thesis full-stack application for real-time news credibility analysis. It fetches articles from RSS feeds, runs them through HuggingFace Transformer models (sentiment analysis + fake news detection), and presents results in a bilingual (PL/EN) Next.js dashboard.
Commands
Backend (TruthScan AI_backend/)
# Install dependencies
cd "TruthScan AI_backend"
pip install -r requirements.txt
# Start dev server (http://127.0.0.1:8000)
python -m uvicorn app.main:app
# Run tests
python truthscan_test.py
Swagger UI available at http://localhost:8000/docs.
Frontend (TruthScan AI_frontend/)
# Install dependencies
cd "TruthScan AI_frontend"
npm install
# Start dev server (http://localhost:3000)
npm run dev
# Build for production
npm run build
# Lint
npm run lint
Architecture
Data Flow
Browser (Next.js :3000)
β HTTP/SSE β FastAPI (:8000)
β RSS fetch β feedparser + BeautifulSoup
β NLP pipeline β HuggingFace Transformers
β JSON/SSE response β React UI
Backend (app/)
config.pyβ All constants: 10 RSS sources (BBC, CNN, NYTimes, Guardian, AlJazeera, PolsatNews, etc.), CORS settings, sentiment label mappings (PL/EN), cache TTLs.nlp_service.pyβ Plug-in NLP pipeline:- Abstract base class
ModelAdapterwithanalyze_sentiment()andanalyze_fake_news(). - Three adapters:
RoBERTaAdapter(en),XLMRoBERTaAdapter(pl/en/no),NorBERTAdapter(no). - All adapters lazy-load their pipelines on first use.
- Global registry
_REGISTRY; active adapter changed viaset_active_adapter(name). register_adapter(adapter)adds custom/fine-tuned checkpoints at runtime.- Public functions
analyze_news()/analyze_news_batch()preserve the original interface βroutes/news.pyrequires no changes. - Uses
ThreadPoolExecutor(max 3 workers) for parallel batch processing.
- Abstract base class
rss_utils.pyβ RSS fetching with 7s timeout, HTML stripping via BeautifulSoup, simple in-memory TTL cache.storage.pyβ Thread-safe JSON file persistence for saved articles (saved_articles.json).routes/news.pyβ Main endpoints:GET /news/{source}(5 articles with NLP),GET /stream-news/{source}(SSE streaming),GET /emotion-stats/{source},GET /charts-data.routes/saved.pyβ CRUD for saved articles.routes/misc.pyβGET /sourceslists available RSS sources.
Frontend (app/ + components/ + lib/)
- Routing: Next.js App Router β pages at
app/page.tsx(home),app/dashboard/page.tsx,app/saved/page.tsx. - State: Zustand store in
stores/newsCache.tsxβ caches articles per source/language with 5-min TTL, persisted tolocalStorage(key:truthscan_news_cache_v1). - API client:
lib/fetchNews.tsβfetchOneSource()andfetchAllNews()(concurrent, 3 workers default), plusnormalizeArticle(). - SSE streaming:
hooks/useNewsStream.tsconsumesGET /stream-news/{source}, tracks progress and collects articles, writes to Zustand cache on completion. - i18n:
lib/locales.jsholds all PL/EN UI strings. Language state managed inhooks/useLanguage.ts, synced vialocalStorageandapp:langchangecustom event. - Charts: Recharts via
hooks/useDashboardCharts.tsandhooks/useCachedEmotionStats.ts. - PDF export:
hooks/usePDFExport.ts(jsPDF) +components/PDFGenerator.tsx(react-to-print). - Dark mode: Tailwind
.darkclass toggle, CSS variables instyles/globals.css.
Master's Thesis Goals
The thesis extends TruthScan AI by comparing NLP models across three languages: Polish, Norwegian, and English. Models under comparison: XLM-RoBERTa, NorBERT 3, HerBERT.
Planned work items:
nlp_service.pyplug-in architecture β replace the hardcoded model with a swappable interface so each model (XLM-RoBERTa, NorBERT 3, HerBERT) can be loaded and hot-swapped without changing route logic.Norwegian RSS sources in
config.pyβ add NRK, VG, and Dagbladet alongside the existing 10 sources.SENTIMENT_MAPextension β add a"no"(Norwegian) key to the sentiment label mapping inconfig.py, parallel to the existing"pl"and"en"keys.Benchmarking module β new module that measures F1, accuracy, and inference time per model/language combination and exposes results via a dedicated API endpoint (or offline report).
PostgreSQL migration β replace
storage.py/saved_articles.jsonwith a PostgreSQL backend (SQLAlchemy or asyncpg).storage.pyread/write interface should be preserved so routes need minimal changes.Public deployment β frontend on Vercel, backend + models on Hugging Face Spaces.
Environment
- Backend API base URL:
process.env.NEXT_PUBLIC_API_URL(defaults tohttp://127.0.0.1:8000). - Backend CORS is open (
"*") β intentional for thesis/dev use. - NLP models are downloaded automatically by HuggingFace on first run (can be slow).