Adam Cseresznye commited on
Commit ·
ae2bb22
1
Parent(s): f887d42
Update project files and add new assets
Browse files- README.md +95 -302
- logo/favicon.png +2 -2
- logo/{nechtrall.png → necthrall.png} +2 -2
- main.py +1 -1
- ui/pages.py +243 -67
- ui/policies.py +89 -0
README.md
CHANGED
|
@@ -7,345 +7,138 @@ sdk: docker
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
- Real RAG loop: fetch → parse → chunk → embed → retrieve → rerank → synthesize
|
| 19 |
-
- Inline citations with exact passage spans
|
| 20 |
-
- Lightweight credibility scoring (journal tier, citations, recency)
|
| 21 |
-
- Consensus estimation and contradiction detection
|
| 22 |
-
- Single-app stack: NiceGUI (UI) + FastAPI (API) in Python
|
| 23 |
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
##
|
| 27 |
|
| 28 |
-
|
| 29 |
-
- Retrieves ~30 OA papers
|
| 30 |
-
- Ranks credibility (journal tier, citations, recency)
|
| 31 |
-
- Consensus: “Moderate (≈65%)”
|
| 32 |
-
- Contradictions: shows 1–3 pairs with short explanations
|
| 33 |
-
- Synthesizes a 300–500 word summary with inline citations and passage spans
|
| 34 |
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
-
|
|
|
|
| 38 |
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
-
|
| 42 |
-
- macOS/Linux/Windows
|
| 43 |
-
- Basic network access to OA APIs
|
| 44 |
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
|
| 48 |
-
git clone <your-repo-url> necthrall-lite
|
| 49 |
-
cd necthrall-lite
|
| 50 |
-
pip install -e .
|
| 51 |
-
```
|
| 52 |
|
| 53 |
-
|
|
|
|
|
|
|
| 54 |
|
| 55 |
-
|
| 56 |
-
cp .env.example .env
|
| 57 |
-
# Edit .env to set your keys/emails and model choices
|
| 58 |
-
```
|
| 59 |
|
| 60 |
-
|
| 61 |
-
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
|
| 65 |
-
|
| 66 |
|
| 67 |
-
|
| 68 |
-
python -m necthrall_lite
|
| 69 |
-
# Follow the printed URL to open the UI
|
| 70 |
-
```
|
| 71 |
|
| 72 |
-
|
| 73 |
|
| 74 |
-
|
|
|
|
|
|
|
| 75 |
|
| 76 |
-
|
| 77 |
-
- UNPAYWALL_EMAIL: Required for Unpaywall OA resolution
|
| 78 |
-
- OPENALEX_EMAIL: Recommended for OpenAlex (good API citizenship)
|
| 79 |
-
- RAG_EMBEDDING_MODEL: e.g., all-MiniLM-L6-v2
|
| 80 |
-
- RAG_MAX_PAPERS: default 30
|
| 81 |
-
- RAG_TOP_K: default 12
|
| 82 |
-
- RAG_CHUNK_SIZE: default 800
|
| 83 |
-
- RAG_CHUNK_OVERLAP: default 120
|
| 84 |
-
- RAG_RERANK_ENABLED: true|false
|
| 85 |
-
- TIMEOUT_SEC: default 20
|
| 86 |
|
| 87 |
-
***
|
| 88 |
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
- Collect DOIs, OA status, and any fulltext URLs
|
| 94 |
-
- Backfill missing fulltexts via Unpaywall by DOI
|
| 95 |
-
- Prefer PMC/arXiv when available for direct PDFs
|
| 96 |
-
|
| 97 |
-
2) Download
|
| 98 |
-
- Download only the top ~30 OA PDFs
|
| 99 |
-
- Strictly API-based resolution (no scraping)
|
| 100 |
-
|
| 101 |
-
3) Parse & Chunk
|
| 102 |
-
|
| 103 |
-
Parse & Chunk
|
| 104 |
-
|
| 105 |
-
Extract text from PDFs using PyMuPDF4LLM (Markdown-preserving extraction)
|
| 106 |
-
|
| 107 |
-
LlamaIndex MarkdownNodeParser automatically detects document structure:
|
| 108 |
-
|
| 109 |
-
Headers (##, ###, ####) from font size analysis
|
| 110 |
-
|
| 111 |
-
Section boundaries and hierarchy
|
| 112 |
-
|
| 113 |
-
Table preservation
|
| 114 |
-
|
| 115 |
-
Multi-column reading order
|
| 116 |
-
|
| 117 |
-
Configurable chunk size/overlap (default 800/120 chars)
|
| 118 |
-
|
| 119 |
-
Chunks respect Markdown boundaries for coherent context
|
| 120 |
-
|
| 121 |
-
4) Embed & Index
|
| 122 |
-
- Encode chunks with sentence-transformers
|
| 123 |
-
- Build ephemeral FAISS index under data/index
|
| 124 |
-
|
| 125 |
-
5) Retrieve & Rerank
|
| 126 |
-
- Similarity search (top-k)
|
| 127 |
-
- Optional cross-encoder reranker
|
| 128 |
-
- Track passage spans for transparent citations
|
| 129 |
-
|
| 130 |
-
6) Credibility, Consensus, Contradictions
|
| 131 |
-
- Credibility: journal tier (simple mapping) + normalized citations + recency weights
|
| 132 |
-
- Consensus: label conclusion chunks (support/caution/neutral) and aggregate
|
| 133 |
-
- Contradictions: pair top conclusions; compact LLM check to tag supports/contradicts/unclear with brief rationale
|
| 134 |
-
|
| 135 |
-
7) Synthesize
|
| 136 |
-
- Short, citable narrative with inline citations and passage spans
|
| 137 |
-
- Show consensus gauge and contradiction callouts
|
| 138 |
-
- List ranked sources with OA links (when available)
|
| 139 |
-
|
| 140 |
-
8) Cleanup
|
| 141 |
-
- Ephemeral cache; discard index after response (configurable)
|
| 142 |
-
|
| 143 |
-
***
|
| 144 |
-
|
| 145 |
-
## Architecture
|
| 146 |
-
|
| 147 |
-
- Single Python app: NiceGUI (UI) + FastAPI (API)
|
| 148 |
-
- Pure LlamaIndex pipeline (no LangChain dependencies)
|
| 149 |
-
- Markdown-aware PDF extraction and chunking
|
| 150 |
-
- On-demand OA retrieval (OpenAlex, Unpaywall, PMC, arXiv)
|
| 151 |
-
- Per-query vector index (FAISS)
|
| 152 |
-
- BYO LLM for contradiction checks and synthesis
|
| 153 |
-
- No persistent warehouse or scheduled crawlers
|
| 154 |
-
|
| 155 |
-
***
|
| 156 |
-
|
| 157 |
-
## Project Structure
|
| 158 |
-
|
| 159 |
-
```text
|
| 160 |
-
necthrall-lite/
|
| 161 |
-
├── pyproject.toml
|
| 162 |
-
├── README.md
|
| 163 |
-
├── .gitignore
|
| 164 |
-
├── .env.example
|
| 165 |
-
├── LICENSE
|
| 166 |
-
├── tests/
|
| 167 |
-
│ ├── test_api_routes.py
|
| 168 |
-
│ ├── test_services.py
|
| 169 |
-
│ └── test_rag_pipeline.py
|
| 170 |
-
├── src/
|
| 171 |
-
│ └── necthrall_lite/
|
| 172 |
-
│ ├── __init__.py
|
| 173 |
-
│ ├── main.py # entrypoint: FastAPI + NiceGUI integration
|
| 174 |
-
│ ├── settings.py # env + config
|
| 175 |
-
│ ├── logging_conf.py
|
| 176 |
-
│ ├── api/
|
| 177 |
-
│ │ ├── __init__.py
|
| 178 |
-
│ │ ├── routes.py # /api/query, /api/health
|
| 179 |
-
│ │ ├── deps.py
|
| 180 |
-
│ │ └── schemas.py # Pydantic models
|
| 181 |
-
│ ├── core/
|
| 182 |
-
│ │ ├── __init__.py
|
| 183 |
-
│ │ ├── config.py
|
| 184 |
-
│ │ └── security.py
|
| 185 |
-
│ ├── clients/
|
| 186 |
-
│ │ ├── __init__.py
|
| 187 |
-
│ │ ├── openalex_client.py
|
| 188 |
-
│ │ ├── unpaywall_client.py
|
| 189 |
-
│ │ ├── pmc_client.py
|
| 190 |
-
│ │ └── arxiv_client.py
|
| 191 |
-
│ ├── loaders/
|
| 192 |
-
│ │ ├── __init__.py
|
| 193 |
-
│ │ ├── oa_link_resolver.py
|
| 194 |
-
│ │ ├── pdf_downloader.py
|
| 195 |
-
│ │ └── pdf_text_extractor.py
|
| 196 |
-
│ ├── rag/
|
| 197 |
-
│ │ ├── __init__.py
|
| 198 |
-
│ │ ├── chunking.py
|
| 199 |
-
│ │ ├── embeddings.py
|
| 200 |
-
│ │ ├── vectorstore.py
|
| 201 |
-
│ │ ├── retrieval.py
|
| 202 |
-
│ │ └── reranker.py
|
| 203 |
-
│ ├── services/
|
| 204 |
-
│ │ ├── __init__.py
|
| 205 |
-
│ │ ├── retrieval_service.py
|
| 206 |
-
│ │ ├── credibility_service.py
|
| 207 |
-
│ │ ├── contradiction_service.py
|
| 208 |
-
│ │ └── synthesis_service.py
|
| 209 |
-
│ ├── nlp/
|
| 210 |
-
│ │ ├── __init__.py
|
| 211 |
-
│ │ ├── spacy_utils.py
|
| 212 |
-
│ │ └── sentiment.py
|
| 213 |
-
│ ├── ui/
|
| 214 |
-
│ │ ├── __init__.py
|
| 215 |
-
│ │ ├── pages.py # NiceGUI UI
|
| 216 |
-
│ │ ├── styles.py
|
| 217 |
-
│ │ └── components/
|
| 218 |
-
│ │ ├── consensus_gauge.py
|
| 219 |
-
│ │ ├── credibility_badge.py
|
| 220 |
-
│ │ └── contradiction_callout.py
|
| 221 |
-
│ ├── integration/
|
| 222 |
-
│ �� ├── __init__.py
|
| 223 |
-
│ │ └── fastapi_nicegui.py
|
| 224 |
-
│ ├── configs/
|
| 225 |
-
│ │ ├── journal_tiers.json
|
| 226 |
-
│ │ └── prompts/
|
| 227 |
-
│ │ ├── contradiction_check.txt
|
| 228 |
-
│ │ └── synthesis_template.txt
|
| 229 |
-
│ └── data/
|
| 230 |
-
│ ├── .gitkeep
|
| 231 |
-
│ ├── cache/
|
| 232 |
-
│ └── index/
|
| 233 |
-
└── .vscode/
|
| 234 |
-
└── settings.json
|
| 235 |
-
```
|
| 236 |
-
|
| 237 |
-
***
|
| 238 |
-
|
| 239 |
-
## API (used by the UI)
|
| 240 |
-
|
| 241 |
-
- GET /api/health → { status: "ok" }
|
| 242 |
-
- POST /api/query
|
| 243 |
-
- Body: { topic: string, max_papers?: int, top_k?: int }
|
| 244 |
-
- Returns: { summary, consensus, contradictions[], sources[], timings, params }
|
| 245 |
-
|
| 246 |
-
***
|
| 247 |
-
|
| 248 |
-
## Configuration (Key Settings)
|
| 249 |
-
|
| 250 |
-
- max_papers: default 30
|
| 251 |
-
- chunk_size / chunk_overlap: default 800 / 120
|
| 252 |
-
- embedding_model: e.g., sentence-transformers/all-MiniLM-L6-v2
|
| 253 |
-
- top_k: default 12
|
| 254 |
-
- rerank_enabled: default true
|
| 255 |
-
- credibility_weights: journal tier 0.5, citations 0.3, recency 0.2
|
| 256 |
-
- llm_model: e.g., gpt-4o-mini or local provider
|
| 257 |
-
- timeout_sec: per-API and overall query budget
|
| 258 |
-
|
| 259 |
-
***
|
| 260 |
-
|
| 261 |
-
## Evaluation (Optional)
|
| 262 |
-
|
| 263 |
-
- Topics:
|
| 264 |
-
- “CRISPR off-target risks”
|
| 265 |
-
- “Intermittent fasting metabolic outcomes”
|
| 266 |
-
- “Climate adaptation crop resilience”
|
| 267 |
-
- Metrics:
|
| 268 |
-
- Faithfulness: statements backed by explicit passage spans
|
| 269 |
-
- Citation coverage: ≥5 citations with diverse sources
|
| 270 |
-
- Latency: ≤5–7 seconds end-to-end on a typical laptop
|
| 271 |
-
- Spot checks: contradictions flagged correctly; consensus gauge matches qualitative impression
|
| 272 |
-
|
| 273 |
-
***
|
| 274 |
-
|
| 275 |
-
## Development
|
| 276 |
-
|
| 277 |
-
- Install: `pip install -e .`
|
| 278 |
-
- Run: `python -m necthrall_lite`
|
| 279 |
-
- Test: `pytest -q`
|
| 280 |
-
- Lint/Format: add pre-commit, ruff/black if desired
|
| 281 |
-
- Run: `python -m necthrall_lite`
|
| 282 |
-
|
| 283 |
-
### Running tests
|
| 284 |
-
|
| 285 |
-
Use the pytest entry on your activated virtualenv. The project uses markers to split suites so you can run only the fast or longer tests:
|
| 286 |
-
|
| 287 |
-
- Run the fast unit tests only:
|
| 288 |
-
|
| 289 |
-
```
|
| 290 |
-
pytest -m "unit" -q
|
| 291 |
-
```
|
| 292 |
-
|
| 293 |
-
- Run the integration tests only (excludes tests marked `performance` or `slow` by default):
|
| 294 |
-
|
| 295 |
-
```
|
| 296 |
-
pytest -m "integration" -q
|
| 297 |
-
```
|
| 298 |
-
|
| 299 |
-
- Run performance/benchmark tests (long-running):
|
| 300 |
-
|
| 301 |
-
```
|
| 302 |
-
pytest -m "performance" -q
|
| 303 |
-
```
|
| 304 |
|
| 305 |
-
|
| 306 |
-
- These commands assume your virtualenv is activated (so `pytest` refers to the environment's pytest). You said you prefer not to use `python -m pytest` — the above uses the plain `pytest` entry as requested.
|
| 307 |
-
- CI scripts often prefer the explicit `python -m pytest` form for reproducibility; locally `pytest` is fine when the venv is active.
|
| 308 |
-
- By default `performance` and `slow` tests are skipped in `pytest.ini` unless you explicitly include them in marker expressions.
|
| 309 |
|
| 310 |
-
|
|
|
|
|
|
|
| 311 |
|
| 312 |
-
|
| 313 |
|
| 314 |
-
-
|
| 315 |
-
- **Ephemeral vector index**: per-query isolation and simplicity
|
| 316 |
-
- **LlamaIndex-native Markdown parsing**: PyMuPDF4LLM + MarkdownNodeParser preserves document structure without custom regex or external dependencies (pure LlamaIndex stack)
|
| 317 |
-
- **Credibility heuristics**: simple, transparent, adjustable weights
|
| 318 |
-
- **Minimal LLM usage**: contradiction verification + final synthesis
|
| 319 |
-
- **Inline citations with spans**: traceability by design
|
| 320 |
|
| 321 |
-
|
| 322 |
|
| 323 |
-
|
| 324 |
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
- PubMed Central: OA full-texts (plus OAI-PMH/ID services)
|
| 328 |
-
- arXiv: preprints with direct PDFs
|
| 329 |
|
| 330 |
-
|
| 331 |
|
| 332 |
-
##
|
| 333 |
|
| 334 |
-
|
| 335 |
-
- Better reranking and section-aware retrieval
|
| 336 |
-
- Claim-level extraction and structured evidence maps
|
| 337 |
-
- Export to Markdown/Word with citation styles
|
| 338 |
-
- More robust journal tiering and bias detection
|
| 339 |
|
| 340 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 341 |
|
| 342 |
-
##
|
| 343 |
|
| 344 |
-
|
| 345 |
|
| 346 |
-
***
|
|
|
|
| 347 |
|
| 348 |
-
##
|
| 349 |
|
| 350 |
-
|
| 351 |
|
|
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
+
<div align="center">
|
| 11 |
+
<img src="logo/necthrall.png" alt="Necthrall Logo" width="120">
|
| 12 |
+
<h1>Necthrall</h1>
|
| 13 |
+
<h3><i>Science, Distilled.</i> An open-source, AI research assistant.</h3>
|
| 14 |
|
| 15 |
+

|
| 16 |
+

|
| 17 |
+

|
| 18 |
|
| 19 |
+
<br/>
|
| 20 |
|
| 21 |
+
<strong><a href="https://necthrall-ai.hf.space">🔴 Live Demo on Hugging Face</a></strong>
|
| 22 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
---
|
| 25 |
+
|
| 26 |
+
## ⚡ Key Features
|
| 27 |
+
|
| 28 |
+
- **📄 Full-Text Analysis:** We don't just read abstracts. Necthrall downloads and chunks the actual PDFs to find evidence buried deep in Methods and Results.
|
| 29 |
+
- **🛡️ Privacy First:** Completely stateless. No database, no user accounts, no history.
|
| 30 |
+
- **🔍 Deep Search:** Queries **Semantic Scholar** to find hundreds of candidates per query, filtered down to the top 10 most relevant open-access papers.
|
| 31 |
+
- **✅ Verifiable:** Every sentence is backed by an inline citation `[1]` that links directly to the source passage.
|
| 32 |
+
- **🧠 Resilient:** Built on **LiteLLM**, Necthrall prioritizes **Google Gemini** for synthesis, automatically switching to **Groq** if the primary model is unavailable or fails.
|
| 33 |
+
|
| 34 |
+
---
|
| 35 |
|
| 36 |
+
## 🏗️ Architecture
|
| 37 |
|
| 38 |
+
Necthrall runs a **6-stage pipeline** for every query. It is optimized for speed (async/parallel) and transparency.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
```mermaid
|
| 41 |
+
graph TD
|
| 42 |
+
%% Define Custom Styles
|
| 43 |
+
classDef input fill:#6366f1,stroke:none,color:#fff,rx:10,ry:10,font-weight:bold;
|
| 44 |
+
classDef logic fill:#fff,stroke:#cbd5e1,stroke-width:1px,color:#475569,rx:5,ry:5;
|
| 45 |
+
classDef rag fill:#ecfdf5,stroke:#10b981,stroke-width:2px,color:#064e3b,rx:5,ry:5;
|
| 46 |
+
classDef llm fill:#eff6ff,stroke:#3b82f6,stroke-width:2px,color:#1e40af,rx:5,ry:5;
|
| 47 |
+
classDef result fill:#10b981,stroke:none,color:#fff,rx:10,ry:10,font-weight:bold;
|
| 48 |
|
| 49 |
+
%% The Flow
|
| 50 |
+
Start(["🔎 User Query"]):::input --> B
|
| 51 |
|
| 52 |
+
subgraph " 1. Retrieval Phase "
|
| 53 |
+
direction TB
|
| 54 |
+
B["⚡ Query Expansion Agent<br/><i>Multi-variant generation</i>"]:::logic
|
| 55 |
+
B --> C["📚 Async Retrieval<br/><i>Semantic Scholar API (Parallel)</i>"]:::logic
|
| 56 |
+
C --> D["⚖️ Composite Reranker<br/><i>Relevance + Authority Scoring</i>"]:::logic
|
| 57 |
+
D --> E["⬇️ Document Ingestion<br/><i>Direct PDF Fetching & Parsing</i>"]:::logic
|
| 58 |
+
end
|
| 59 |
|
| 60 |
+
E --> F
|
|
|
|
|
|
|
| 61 |
|
| 62 |
+
subgraph " 2. Processing Phase "
|
| 63 |
+
direction TB
|
| 64 |
+
F["🧠 In-Memory Vector Store<br/><i>FAISS + Dense Embeddings</i>"]:::rag
|
| 65 |
+
F --> G["🤖 Contextual Synthesis<br/><i>LLM Reasoning + Citation Mapping</i>"]:::llm
|
| 66 |
+
end
|
| 67 |
|
| 68 |
+
G --> H(["✨ Verified Response"]):::result
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
+
%% Styling Links
|
| 71 |
+
linkStyle default stroke:#94a3b8,stroke-width:2px;
|
| 72 |
+
````
|
| 73 |
|
| 74 |
+
### The Stack
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
+
* **UI/Server:** NiceGUI + FastAPI (Single Python app)
|
| 77 |
+
* **RAG:** LlamaIndex + FAISS (Ephemeral in-memory indices)
|
| 78 |
+
* **Data:** Semantic Scholar API + Unpaywall
|
| 79 |
+
* **LLM Routing:** LiteLLM
|
| 80 |
|
| 81 |
+
-----
|
| 82 |
|
| 83 |
+
## 🚀 Quickstart
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
+
### Prerequisites
|
| 86 |
|
| 87 |
+
* Python 3.11+
|
| 88 |
+
* [Semantic Scholar API Key](https://www.semanticscholar.org/product/api) (Free)
|
| 89 |
+
* LLM Provider Key (Google Gemini or Groq)
|
| 90 |
|
| 91 |
+
### Local Development
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
+
1. **Clone & Install**
|
| 94 |
|
| 95 |
+
```bash
|
| 96 |
+
git clone [https://github.com/adamcseresznye/necthrall.git](https://github.com/adamcseresznye/necthrall.git)
|
| 97 |
+
cd necthrall
|
| 98 |
+
pip install -r requirements.txt
|
| 99 |
+
```
|
| 100 |
|
| 101 |
+
2. **Configure Environment**
|
| 102 |
+
Create a `.env` file in the root directory
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
+
3. **Run the App**
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
+
```bash
|
| 107 |
+
python main.py
|
| 108 |
+
```
|
| 109 |
|
| 110 |
+
The UI will be available at `http://localhost:8080`.
|
| 111 |
|
| 112 |
+
-----
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
+
## 🔒 Privacy & Data Retention
|
| 115 |
|
| 116 |
+
Necthrall is designed to be **ephemeral** and privacy-first:
|
| 117 |
|
| 118 |
+
* **No Database:** We do not store user search queries or results.
|
| 119 |
+
* **Memory Only:** Vector indices (FAISS) are built in RAM and destroyed immediately after the response is generated.
|
|
|
|
|
|
|
| 120 |
|
| 121 |
+
-----
|
| 122 |
|
| 123 |
+
## 🛠️ Configuration
|
| 124 |
|
| 125 |
+
Necthrall uses **LiteLLM** for model routing. You can configure the following in your `.env` file:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
+
| Variable | Description | Required |
|
| 128 |
+
| :--- | :--- | :--- |
|
| 129 |
+
| `SEMANTIC_SCHOLAR_API_KEY` | For searching papers | **Yes** |
|
| 130 |
+
| `GOOGLE_API_KEY` | Primary LLM (e.g., Gemini 2.0 Flash) | **Yes** |
|
| 131 |
+
| `GROQ_API_KEY` | Fallback LLM (e.g., Llama 3.3) | Optional |
|
| 132 |
+
-----
|
| 133 |
|
| 134 |
+
## 🙏 Acknowledgements
|
| 135 |
|
| 136 |
+
This project is made possible by the open-science ecosystem:
|
| 137 |
|
| 138 |
+
- **Semantic Scholar**: Necthrall uses the Semantic Scholar API for paper retrieval and citation data.
|
| 139 |
+
- **Hugging Face**: For hosting the demo infrastructure and models.
|
| 140 |
|
| 141 |
+
## 📄 License
|
| 142 |
|
| 143 |
+
GPL-3.0 license
|
| 144 |
|
logo/favicon.png
CHANGED
|
|
Git LFS Details
|
|
|
Git LFS Details
|
logo/{nechtrall.png → necthrall.png}
RENAMED
|
File without changes
|
main.py
CHANGED
|
@@ -132,4 +132,4 @@ ui.run_with(
|
|
| 132 |
if __name__ == "__main__":
|
| 133 |
import uvicorn
|
| 134 |
|
| 135 |
-
uvicorn.run("main:app", host="0.0.0.0", port=7860, log_level="info")
|
|
|
|
| 132 |
if __name__ == "__main__":
|
| 133 |
import uvicorn
|
| 134 |
|
| 135 |
+
uvicorn.run("main:app", host="0.0.0.0", port=7860, log_level="info", reload=True)
|
ui/pages.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
"""Page definitions for the
|
| 2 |
|
| 3 |
from pathlib import Path
|
| 4 |
from nicegui import ui, context, app
|
|
@@ -12,10 +12,11 @@ from ui.components import (
|
|
| 12 |
render_error,
|
| 13 |
render_exception_error,
|
| 14 |
)
|
|
|
|
| 15 |
|
| 16 |
# Path to logo directory
|
| 17 |
LOGO_DIR = (
|
| 18 |
-
Path(__file__).resolve().parent.parent.joinpath("logo").joinpath("
|
| 19 |
)
|
| 20 |
|
| 21 |
|
|
@@ -28,6 +29,18 @@ def init_ui(fastapi_app):
|
|
| 28 |
|
| 29 |
@ui.page("/")
|
| 30 |
async def index_page():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
# Inject custom CSS
|
| 32 |
ui.add_head_html(f"<style>{CUSTOM_CSS}</style>")
|
| 33 |
ui.add_body_html(
|
|
@@ -35,7 +48,7 @@ def init_ui(fastapi_app):
|
|
| 35 |
<script data-name="BMC-Widget" data-cfasync="false"
|
| 36 |
src="https://cdnjs.buymeacoffee.com/1.0.0/widget.prod.min.js"
|
| 37 |
data-id="acseresznye"
|
| 38 |
-
data-description="Support
|
| 39 |
data-message=""
|
| 40 |
data-color="#FFDD00"
|
| 41 |
data-position="Right"
|
|
@@ -51,34 +64,42 @@ def init_ui(fastapi_app):
|
|
| 51 |
# =====================================================================
|
| 52 |
# DIALOG: HOW IT WORKS
|
| 53 |
# =====================================================================
|
| 54 |
-
with ui.dialog() as about_dialog, ui.card().classes("q-pa-md"):
|
| 55 |
with ui.row().classes("w-full items-center justify-between"):
|
| 56 |
-
ui.label("How
|
| 57 |
ui.button(icon="close", on_click=about_dialog.close).props(
|
| 58 |
"flat round dense"
|
| 59 |
)
|
| 60 |
|
| 61 |
-
with ui.column().classes(
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
ui.label(
|
| 66 |
-
"1. Search: We scan millions of
|
| 67 |
-
).classes("text-base")
|
| 68 |
|
| 69 |
-
# Step 2
|
| 70 |
-
with ui.row().classes("items-center gap-
|
| 71 |
-
ui.icon("filter_alt"
|
|
|
|
|
|
|
| 72 |
ui.label(
|
| 73 |
-
"2. Filter: We rank
|
| 74 |
-
).classes("text-base")
|
| 75 |
|
| 76 |
-
# Step 3
|
| 77 |
-
with ui.row().classes("items-center gap-
|
| 78 |
-
ui.icon("auto_awesome"
|
|
|
|
|
|
|
| 79 |
ui.label(
|
| 80 |
-
"3. Synthesize: AI
|
| 81 |
-
).classes("text-base")
|
| 82 |
|
| 83 |
# =====================================================================
|
| 84 |
# DIALOG: PRIVACY POLICY
|
|
@@ -94,20 +115,7 @@ def init_ui(fastapi_app):
|
|
| 94 |
)
|
| 95 |
|
| 96 |
with ui.scroll_area().classes("h-64 pr-4"):
|
| 97 |
-
ui.markdown(
|
| 98 |
-
"""
|
| 99 |
-
**Last Updated: December 2025**
|
| 100 |
-
|
| 101 |
-
1. **No Personal Data Retention:** Nechtrall is a stateless application. We do not create user accounts, nor do we store your search history or personal details in our databases.
|
| 102 |
-
|
| 103 |
-
2. **Third-Party Processing:** To answer your questions, your anonymized queries are processed by:
|
| 104 |
-
- **Semantic Scholar:** To retrieve relevant scientific papers.
|
| 105 |
-
- **LLM Providers (Google/Groq):** To analyze text and generate answers.
|
| 106 |
-
These providers may retain data transiently for abuse monitoring, but we do not store it.
|
| 107 |
-
|
| 108 |
-
3. **Local Storage:** We use your browser's local storage solely to save session preferences (like dark mode), which never leave your device.
|
| 109 |
-
"""
|
| 110 |
-
).classes("text-slate-700")
|
| 111 |
|
| 112 |
# =====================================================================
|
| 113 |
# DIALOG: TERMS OF SERVICE
|
|
@@ -120,27 +128,20 @@ def init_ui(fastapi_app):
|
|
| 120 |
)
|
| 121 |
|
| 122 |
with ui.scroll_area().classes("h-64 pr-4"):
|
| 123 |
-
ui.markdown(
|
| 124 |
-
"""
|
| 125 |
-
**Last Updated: December 2025**
|
| 126 |
-
|
| 127 |
-
1. **Research Purpose Only:** Nechtrall is an experimental AI tool designed for academic research assistance. It is **not** a substitute for professional medical, legal, or financial advice.
|
| 128 |
-
|
| 129 |
-
2. **Accuracy Disclaimer:** AI models can make mistakes ("hallucinations"). While we strive to verify citations against real papers, **you must verify important claims** by reading the original source documents linked in the results.
|
| 130 |
-
|
| 131 |
-
3. **No Liability:** The creators of Nechtrall accept no liability for any damages or losses resulting from reliance on the information provided by this tool. By using this service, you agree to cross-check all information.
|
| 132 |
-
"""
|
| 133 |
-
).classes("text-slate-700")
|
| 134 |
|
| 135 |
# State containers
|
| 136 |
results_container = None
|
|
|
|
| 137 |
|
| 138 |
def is_connected() -> bool:
|
| 139 |
-
"""Check if the client is still connected."""
|
| 140 |
try:
|
| 141 |
-
return
|
|
|
|
| 142 |
except Exception:
|
| 143 |
-
|
|
|
|
| 144 |
|
| 145 |
async def handle_search():
|
| 146 |
nonlocal results_container
|
|
@@ -151,12 +152,21 @@ def init_ui(fastapi_app):
|
|
| 151 |
return
|
| 152 |
|
| 153 |
# Clear previous results
|
| 154 |
-
if results_container
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
# Show loading
|
| 158 |
-
if not is_connected():
|
| 159 |
-
return
|
| 160 |
|
| 161 |
# --- START: Enhanced Loading UI ---
|
| 162 |
loading_timer = None
|
|
@@ -174,10 +184,12 @@ def init_ui(fastapi_app):
|
|
| 174 |
"text-xl text-slate-600 font-medium animate-pulse text-center"
|
| 175 |
)
|
| 176 |
|
| 177 |
-
# 3. Tip
|
| 178 |
ui.label(
|
| 179 |
"This may take 15-30 seconds. We are reading real papers."
|
| 180 |
-
).classes(
|
|
|
|
|
|
|
| 181 |
|
| 182 |
# Simulated progress steps
|
| 183 |
messages = [
|
|
@@ -212,13 +224,63 @@ def init_ui(fastapi_app):
|
|
| 212 |
return
|
| 213 |
|
| 214 |
# Clear loading
|
| 215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
|
| 217 |
with results_container:
|
| 218 |
if result.success and result.answer:
|
| 219 |
# Success - show answer and sources
|
| 220 |
render_answer(result)
|
| 221 |
render_sources(result.passages)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
else:
|
| 223 |
# Failed
|
| 224 |
error_msg = (
|
|
@@ -256,7 +318,7 @@ def init_ui(fastapi_app):
|
|
| 256 |
"w-12 h-12 md:w-20 md:h-20 object-contain"
|
| 257 |
).props("no-spinner")
|
| 258 |
|
| 259 |
-
ui.label("
|
| 260 |
"text-2xl md:text-4xl font-bold text-slate-800 leading-none pb-1 md:pb-2"
|
| 261 |
)
|
| 262 |
|
|
@@ -281,7 +343,9 @@ def init_ui(fastapi_app):
|
|
| 281 |
# The Subtitle (Value Prop)
|
| 282 |
ui.label(
|
| 283 |
"Ask complex questions. Get cited, verifiable answers."
|
| 284 |
-
).classes(
|
|
|
|
|
|
|
| 285 |
# --- HERO SECTION END ---
|
| 286 |
# Search container
|
| 287 |
with ui.column().classes("search-container"):
|
|
@@ -302,9 +366,10 @@ def init_ui(fastapi_app):
|
|
| 302 |
)
|
| 303 |
|
| 304 |
# Example queries
|
| 305 |
-
|
| 306 |
"example-queries gap-2 mt-4 flex-wrap justify-center"
|
| 307 |
-
)
|
|
|
|
| 308 |
ui.label("Try:").classes("text-slate-400 text-sm")
|
| 309 |
|
| 310 |
async def set_example(text: str):
|
|
@@ -323,21 +388,132 @@ def init_ui(fastapi_app):
|
|
| 323 |
# Results container
|
| 324 |
results_container = ui.column().classes("w-full mt-6")
|
| 325 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
# =====================================================================
|
| 327 |
-
# FOOTER
|
| 328 |
# =====================================================================
|
| 329 |
with ui.footer(fixed=False).classes(
|
| 330 |
"bg-white text-slate-500 border-t border-slate-200 q-py-xl"
|
| 331 |
):
|
| 332 |
-
|
| 333 |
-
|
|
|
|
| 334 |
"font-bold"
|
| 335 |
)
|
| 336 |
ui.label(
|
| 337 |
"AI can make mistakes. Always verify important citations."
|
| 338 |
-
).classes("italic text-sm")
|
| 339 |
|
| 340 |
-
with ui.row().classes(
|
|
|
|
|
|
|
| 341 |
ui.label("Privacy Policy").classes(
|
| 342 |
"cursor-pointer hover:text-slate-800 text-sm"
|
| 343 |
).on("click", privacy_dialog.open)
|
|
@@ -351,6 +527,6 @@ def init_ui(fastapi_app):
|
|
| 351 |
ui.label("|").classes("text-slate-300")
|
| 352 |
|
| 353 |
ui.link(
|
| 354 |
-
"
|
| 355 |
-
"https://
|
| 356 |
).classes("text-slate-500 hover:text-slate-800 text-sm")
|
|
|
|
| 1 |
+
"""Page definitions for the Necthrall UI."""
|
| 2 |
|
| 3 |
from pathlib import Path
|
| 4 |
from nicegui import ui, context, app
|
|
|
|
| 12 |
render_error,
|
| 13 |
render_exception_error,
|
| 14 |
)
|
| 15 |
+
from ui.policies import PRIVACY_POLICY, TERMS_OF_SERVICE
|
| 16 |
|
| 17 |
# Path to logo directory
|
| 18 |
LOGO_DIR = (
|
| 19 |
+
Path(__file__).resolve().parent.parent.joinpath("logo").joinpath("necthrall.png")
|
| 20 |
)
|
| 21 |
|
| 22 |
|
|
|
|
| 29 |
|
| 30 |
@ui.page("/")
|
| 31 |
async def index_page():
|
| 32 |
+
# POSTHOG ANALYTICS INJECTION
|
| 33 |
+
ui.add_head_html(
|
| 34 |
+
"""<script>
|
| 35 |
+
!function(t,e){var o,n,p,r;e.__SV||(window.posthog && window.posthog.__loaded)||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.crossOrigin="anonymous",p.async=!0,p.src=s.api_host.replace(".i.posthog.com","-assets.i.posthog.com")+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="init Dr Ur fi Lr zr ci Or jr capture Ai calculateEventProperties qr register register_once register_for_session unregister unregister_for_session Jr getFeatureFlag getFeatureFlagPayload isFeatureEnabled reloadFeatureFlags updateEarlyAccessFeatureEnrollment getEarlyAccessFeatures on onFeatureFlags onSurveysLoaded onSessionId getSurveys getActiveMatchingSurveys renderSurvey displaySurvey cancelPendingSurvey canRenderSurvey canRenderSurveyAsync identify setPersonProperties group resetGroups setPersonPropertiesForFlags resetPersonPropertiesForFlags setGroupPropertiesForFlags resetGroupPropertiesForFlags reset get_distinct_id getGroups get_session_id get_session_replay_url alias set_config startSessionRecording stopSessionRecording sessionRecordingStarted captureException loadToolbar get_property getSessionProperty Gr Br createPersonProfile Vr Cr Kr opt_in_capturing opt_out_capturing has_opted_in_capturing has_opted_out_capturing get_explicit_consent_status is_capturing clear_opt_in_out_capturing Hr debug O Wr getPageViewId captureTraceFeedback captureTraceMetric Rr".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);
|
| 36 |
+
posthog.init('phc_VM394FZcfxWRAKV9FndVjTIwEQ1EKLBdqUzlmwLBu5i', {
|
| 37 |
+
api_host: 'https://us.i.posthog.com',
|
| 38 |
+
defaults: '2025-11-30',
|
| 39 |
+
person_profiles: 'identified_only', // or 'always' to create profiles for anonymous users as well
|
| 40 |
+
})
|
| 41 |
+
</script>"""
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
# Inject custom CSS
|
| 45 |
ui.add_head_html(f"<style>{CUSTOM_CSS}</style>")
|
| 46 |
ui.add_body_html(
|
|
|
|
| 48 |
<script data-name="BMC-Widget" data-cfasync="false"
|
| 49 |
src="https://cdnjs.buymeacoffee.com/1.0.0/widget.prod.min.js"
|
| 50 |
data-id="acseresznye"
|
| 51 |
+
data-description="Support Necthrall development"
|
| 52 |
data-message=""
|
| 53 |
data-color="#FFDD00"
|
| 54 |
data-position="Right"
|
|
|
|
| 64 |
# =====================================================================
|
| 65 |
# DIALOG: HOW IT WORKS
|
| 66 |
# =====================================================================
|
| 67 |
+
with ui.dialog() as about_dialog, ui.card().classes("q-pa-md w-full max-w-lg"):
|
| 68 |
with ui.row().classes("w-full items-center justify-between"):
|
| 69 |
+
ui.label("How Necthrall Works").classes("text-xl font-bold")
|
| 70 |
ui.button(icon="close", on_click=about_dialog.close).props(
|
| 71 |
"flat round dense"
|
| 72 |
)
|
| 73 |
|
| 74 |
+
with ui.column().classes(
|
| 75 |
+
"gap-4 mt-4"
|
| 76 |
+
): # Increased gap slightly for readability
|
| 77 |
+
# Step 1: Highlight "Open Access" (Your data source)
|
| 78 |
+
with ui.row().classes("items-start md:items-center gap-3"):
|
| 79 |
+
ui.icon("travel_explore").classes(
|
| 80 |
+
"text-blue-500 shrink-0 text-xl md:text-2xl"
|
| 81 |
+
)
|
| 82 |
ui.label(
|
| 83 |
+
"1. Search: We scan millions of open-access scientific papers."
|
| 84 |
+
).classes("text-sm md:text-base break-words flex-1")
|
| 85 |
|
| 86 |
+
# Step 2: Highlight "Credibility" (Your composite score: relevance + impact + authority)
|
| 87 |
+
with ui.row().classes("items-start md:items-center gap-3"):
|
| 88 |
+
ui.icon("filter_alt").classes(
|
| 89 |
+
"text-green-500 shrink-0 text-xl md:text-2xl"
|
| 90 |
+
)
|
| 91 |
ui.label(
|
| 92 |
+
"2. Filter: We rank results by semantic relevance, credibility and citation impact."
|
| 93 |
+
).classes("text-sm md:text-base break-words flex-1")
|
| 94 |
|
| 95 |
+
# Step 3: Highlight "Full Text" & "Inline Citations" (Your key V3 features)
|
| 96 |
+
with ui.row().classes("items-start md:items-center gap-3"):
|
| 97 |
+
ui.icon("auto_awesome").classes(
|
| 98 |
+
"text-purple-500 shrink-0 text-xl md:text-2xl"
|
| 99 |
+
)
|
| 100 |
ui.label(
|
| 101 |
+
"3. Synthesize: AI analyzes the full PDF text and writes a summary with inline citations."
|
| 102 |
+
).classes("text-sm md:text-base break-words flex-1")
|
| 103 |
|
| 104 |
# =====================================================================
|
| 105 |
# DIALOG: PRIVACY POLICY
|
|
|
|
| 115 |
)
|
| 116 |
|
| 117 |
with ui.scroll_area().classes("h-64 pr-4"):
|
| 118 |
+
ui.markdown(PRIVACY_POLICY).classes("text-slate-700")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
# =====================================================================
|
| 121 |
# DIALOG: TERMS OF SERVICE
|
|
|
|
| 128 |
)
|
| 129 |
|
| 130 |
with ui.scroll_area().classes("h-64 pr-4"):
|
| 131 |
+
ui.markdown(TERMS_OF_SERVICE).classes("text-slate-700")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
# State containers
|
| 134 |
results_container = None
|
| 135 |
+
example_queries_row = None
|
| 136 |
|
| 137 |
def is_connected() -> bool:
|
| 138 |
+
"""Check if the client is still connected (soft check)."""
|
| 139 |
try:
|
| 140 |
+
# Only return False if explicitly disconnected, not transient issues
|
| 141 |
+
return not getattr(client, "is_deleted", False)
|
| 142 |
except Exception:
|
| 143 |
+
# Assume connected on exception (avoid spurious errors)
|
| 144 |
+
return True
|
| 145 |
|
| 146 |
async def handle_search():
|
| 147 |
nonlocal results_container
|
|
|
|
| 152 |
return
|
| 153 |
|
| 154 |
# Clear previous results
|
| 155 |
+
if results_container:
|
| 156 |
+
try:
|
| 157 |
+
results_container.clear()
|
| 158 |
+
except RuntimeError:
|
| 159 |
+
# Client deleted, exit gracefully
|
| 160 |
+
return
|
| 161 |
+
|
| 162 |
+
# Hide example queries
|
| 163 |
+
if example_queries_row:
|
| 164 |
+
try:
|
| 165 |
+
example_queries_row.set_visibility(False)
|
| 166 |
+
except RuntimeError:
|
| 167 |
+
pass
|
| 168 |
|
| 169 |
# Show loading
|
|
|
|
|
|
|
| 170 |
|
| 171 |
# --- START: Enhanced Loading UI ---
|
| 172 |
loading_timer = None
|
|
|
|
| 184 |
"text-xl text-slate-600 font-medium animate-pulse text-center"
|
| 185 |
)
|
| 186 |
|
| 187 |
+
# 3. Tip (responsive)
|
| 188 |
ui.label(
|
| 189 |
"This may take 15-30 seconds. We are reading real papers."
|
| 190 |
+
).classes(
|
| 191 |
+
"text-sm md:text-base lg:text-lg text-slate-400 italic text-center max-w-xl mx-auto"
|
| 192 |
+
)
|
| 193 |
|
| 194 |
# Simulated progress steps
|
| 195 |
messages = [
|
|
|
|
| 224 |
return
|
| 225 |
|
| 226 |
# Clear loading
|
| 227 |
+
try:
|
| 228 |
+
results_container.clear()
|
| 229 |
+
except RuntimeError:
|
| 230 |
+
# Client was deleted, silently ignore
|
| 231 |
+
return
|
| 232 |
|
| 233 |
with results_container:
|
| 234 |
if result.success and result.answer:
|
| 235 |
# Success - show answer and sources
|
| 236 |
render_answer(result)
|
| 237 |
render_sources(result.passages)
|
| 238 |
+
|
| 239 |
+
# Persist result to localStorage for recovery if user navigates away
|
| 240 |
+
try:
|
| 241 |
+
import json
|
| 242 |
+
|
| 243 |
+
result_data = {
|
| 244 |
+
"answer": result.answer,
|
| 245 |
+
"execution_time": result.execution_time,
|
| 246 |
+
"finalists": len(result.finalists),
|
| 247 |
+
"passages": [
|
| 248 |
+
{
|
| 249 |
+
"content": (
|
| 250 |
+
passage.node.get_content()
|
| 251 |
+
if hasattr(passage.node, "get_content")
|
| 252 |
+
else str(passage.node)
|
| 253 |
+
),
|
| 254 |
+
"title": (
|
| 255 |
+
passage.node.metadata.get(
|
| 256 |
+
"paper_title", "Unknown"
|
| 257 |
+
)
|
| 258 |
+
if hasattr(passage.node, "metadata")
|
| 259 |
+
else "Unknown"
|
| 260 |
+
),
|
| 261 |
+
"section": (
|
| 262 |
+
passage.node.metadata.get("section", "")
|
| 263 |
+
if hasattr(passage.node, "metadata")
|
| 264 |
+
else ""
|
| 265 |
+
),
|
| 266 |
+
"url": (
|
| 267 |
+
passage.node.metadata.get("pdf_url", "")
|
| 268 |
+
or passage.node.metadata.get("url", "")
|
| 269 |
+
if hasattr(passage.node, "metadata")
|
| 270 |
+
else ""
|
| 271 |
+
),
|
| 272 |
+
}
|
| 273 |
+
for passage in result.passages
|
| 274 |
+
],
|
| 275 |
+
"query": query_text,
|
| 276 |
+
}
|
| 277 |
+
ui.run_javascript(
|
| 278 |
+
f"localStorage.setItem('necthrall_last_result', JSON.stringify({json.dumps(result_data)}))"
|
| 279 |
+
)
|
| 280 |
+
except Exception as e:
|
| 281 |
+
logger.debug(
|
| 282 |
+
f"Failed to persist result to localStorage: {e}"
|
| 283 |
+
)
|
| 284 |
else:
|
| 285 |
# Failed
|
| 286 |
error_msg = (
|
|
|
|
| 318 |
"w-12 h-12 md:w-20 md:h-20 object-contain"
|
| 319 |
).props("no-spinner")
|
| 320 |
|
| 321 |
+
ui.label("Necthrall").classes(
|
| 322 |
"text-2xl md:text-4xl font-bold text-slate-800 leading-none pb-1 md:pb-2"
|
| 323 |
)
|
| 324 |
|
|
|
|
| 343 |
# The Subtitle (Value Prop)
|
| 344 |
ui.label(
|
| 345 |
"Ask complex questions. Get cited, verifiable answers."
|
| 346 |
+
).classes(
|
| 347 |
+
"text-base md:text-lg text-slate-500 max-w-full md:max-w-2xl text-center md:text-left break-words"
|
| 348 |
+
)
|
| 349 |
# --- HERO SECTION END ---
|
| 350 |
# Search container
|
| 351 |
with ui.column().classes("search-container"):
|
|
|
|
| 366 |
)
|
| 367 |
|
| 368 |
# Example queries
|
| 369 |
+
example_queries_row = ui.row().classes(
|
| 370 |
"example-queries gap-2 mt-4 flex-wrap justify-center"
|
| 371 |
+
)
|
| 372 |
+
with example_queries_row:
|
| 373 |
ui.label("Try:").classes("text-slate-400 text-sm")
|
| 374 |
|
| 375 |
async def set_example(text: str):
|
|
|
|
| 388 |
# Results container
|
| 389 |
results_container = ui.column().classes("w-full mt-6")
|
| 390 |
|
| 391 |
+
# Attempt to restore cached result from localStorage on page load
|
| 392 |
+
def restore_cached_result():
|
| 393 |
+
"""Restore result from localStorage if available."""
|
| 394 |
+
try:
|
| 395 |
+
import json
|
| 396 |
+
|
| 397 |
+
# Retrieve cached result from localStorage
|
| 398 |
+
cached_json = ui.run_javascript(
|
| 399 |
+
"localStorage.getItem('necthrall_last_result')", timeout=5
|
| 400 |
+
)
|
| 401 |
+
if cached_json:
|
| 402 |
+
cached_data = json.loads(cached_json)
|
| 403 |
+
search_input.value = cached_data.get("query", "")
|
| 404 |
+
|
| 405 |
+
# Populate the results container
|
| 406 |
+
with results_container:
|
| 407 |
+
# Render answer
|
| 408 |
+
with ui.column().classes("answer-section w-full"):
|
| 409 |
+
with ui.row().classes("items-center gap-3 mb-4"):
|
| 410 |
+
with ui.row().classes("gap-2"):
|
| 411 |
+
ui.label(
|
| 412 |
+
f"⏱️ {cached_data['execution_time']:.1f}s"
|
| 413 |
+
).classes("stats-badge")
|
| 414 |
+
ui.label(
|
| 415 |
+
f"📄 {cached_data['finalists']} papers analyzed"
|
| 416 |
+
).classes("stats-badge")
|
| 417 |
+
ui.label(
|
| 418 |
+
f"📝 {len(cached_data['passages'])} sources cited"
|
| 419 |
+
).classes("stats-badge")
|
| 420 |
+
|
| 421 |
+
ui.markdown(cached_data["answer"]).classes(
|
| 422 |
+
"answer-text"
|
| 423 |
+
)
|
| 424 |
+
|
| 425 |
+
# Render sources
|
| 426 |
+
if cached_data["passages"]:
|
| 427 |
+
with ui.column().classes("sources-section w-full"):
|
| 428 |
+
ui.label("SOURCES CITED").classes(
|
| 429 |
+
"sources-title"
|
| 430 |
+
)
|
| 431 |
+
|
| 432 |
+
for idx, passage in enumerate(
|
| 433 |
+
cached_data["passages"]
|
| 434 |
+
):
|
| 435 |
+
with (
|
| 436 |
+
ui.expansion()
|
| 437 |
+
.classes("source-card")
|
| 438 |
+
.props("dense") as expansion
|
| 439 |
+
):
|
| 440 |
+
with expansion.add_slot("header"):
|
| 441 |
+
with ui.column().classes("w-full"):
|
| 442 |
+
ui.label(
|
| 443 |
+
passage["title"]
|
| 444 |
+
).classes("source-title")
|
| 445 |
+
|
| 446 |
+
meta_parts = []
|
| 447 |
+
if passage["section"]:
|
| 448 |
+
meta_parts.append(
|
| 449 |
+
passage["section"]
|
| 450 |
+
)
|
| 451 |
+
meta_parts.append(
|
| 452 |
+
f"Citation [{idx + 1}]"
|
| 453 |
+
)
|
| 454 |
+
ui.label(
|
| 455 |
+
" • ".join(meta_parts)
|
| 456 |
+
).classes("source-meta")
|
| 457 |
+
|
| 458 |
+
if passage["url"]:
|
| 459 |
+
with ui.row().classes(
|
| 460 |
+
"items-center mt-2"
|
| 461 |
+
):
|
| 462 |
+
with (
|
| 463 |
+
ui.element("a")
|
| 464 |
+
.props(
|
| 465 |
+
f'href="{passage["url"]}" target="_blank"'
|
| 466 |
+
)
|
| 467 |
+
.classes(
|
| 468 |
+
"source-link-btn"
|
| 469 |
+
)
|
| 470 |
+
):
|
| 471 |
+
ui.label(
|
| 472 |
+
"📄 Open Access PDF"
|
| 473 |
+
)
|
| 474 |
+
else:
|
| 475 |
+
with ui.row().classes(
|
| 476 |
+
"items-center mt-2"
|
| 477 |
+
):
|
| 478 |
+
ui.html(
|
| 479 |
+
'<span class="source-link-badge">📄 PDF not available</span>',
|
| 480 |
+
sanitize=False,
|
| 481 |
+
)
|
| 482 |
+
|
| 483 |
+
with ui.column().classes(
|
| 484 |
+
"passage-content"
|
| 485 |
+
):
|
| 486 |
+
ui.label(
|
| 487 |
+
passage["content"]
|
| 488 |
+
).classes("source-snippet")
|
| 489 |
+
|
| 490 |
+
logger.info(
|
| 491 |
+
f"✅ Restored cached result for query: {cached_data['query']}"
|
| 492 |
+
)
|
| 493 |
+
except Exception as e:
|
| 494 |
+
logger.debug(f"No cached result to restore: {e}")
|
| 495 |
+
|
| 496 |
+
# Run restoration on page load
|
| 497 |
+
ui.timer(0.5, restore_cached_result, once=True)
|
| 498 |
+
|
| 499 |
# =====================================================================
|
| 500 |
+
# FOOTER (centered)
|
| 501 |
# =====================================================================
|
| 502 |
with ui.footer(fixed=False).classes(
|
| 503 |
"bg-white text-slate-500 border-t border-slate-200 q-py-xl"
|
| 504 |
):
|
| 505 |
+
# Center everything on all sizes: branding and links stacked and centered
|
| 506 |
+
with ui.column().classes("w-full items-center gap-2 text-center"):
|
| 507 |
+
ui.label("© 2025 Necthrall AI. Research responsibly.").classes(
|
| 508 |
"font-bold"
|
| 509 |
)
|
| 510 |
ui.label(
|
| 511 |
"AI can make mistakes. Always verify important citations."
|
| 512 |
+
).classes("italic text-sm break-words max-w-full px-4")
|
| 513 |
|
| 514 |
+
with ui.row().classes(
|
| 515 |
+
"gap-3 items-center justify-center flex-wrap mt-1"
|
| 516 |
+
):
|
| 517 |
ui.label("Privacy Policy").classes(
|
| 518 |
"cursor-pointer hover:text-slate-800 text-sm"
|
| 519 |
).on("click", privacy_dialog.open)
|
|
|
|
| 527 |
ui.label("|").classes("text-slate-300")
|
| 528 |
|
| 529 |
ui.link(
|
| 530 |
+
"GitHub",
|
| 531 |
+
"https://github.com/adamcseresznye/necthrall",
|
| 532 |
).classes("text-slate-500 hover:text-slate-800 text-sm")
|
ui/policies.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Legal policies text for Necthrall UI."""
|
| 2 |
+
|
| 3 |
+
PRIVACY_POLICY = """
|
| 4 |
+
**Last Updated:** December 4, 2025
|
| 5 |
+
|
| 6 |
+
**1. Introduction**
|
| 7 |
+
Necthrall ("we," "us," or "our") operates the Necthrall application (the "Service"). This page informs you of our policies regarding the collection, use, and disclosure of personal data when you use our Service and the choices you have associated with that data.
|
| 8 |
+
|
| 9 |
+
We use your data to provide and improve the Service. By using the Service, you agree to the collection and use of information in accordance with this policy.
|
| 10 |
+
|
| 11 |
+
**2. Information Collection and Use**
|
| 12 |
+
While using our Service, we minimize the collection of Personal Data. The Service is designed to be stateless and does not maintain persistent user accounts.
|
| 13 |
+
|
| 14 |
+
**2.1. Usage Data**
|
| 15 |
+
We may process information that your browser sends whenever you visit our Service ("Usage Data"). This Usage Data is collected automatically by our hosting provider, Hugging Face Spaces, and may include information such as:
|
| 16 |
+
|
| 17 |
+
* Your computer's Internet Protocol address (e.g., IP address).
|
| 18 |
+
* Browser type and browser version.
|
| 19 |
+
* The pages of our Service that you visit, the time and date of your visit, and the time spent on those pages.
|
| 20 |
+
* Other diagnostic data.
|
| 21 |
+
|
| 22 |
+
**2.2. Cookies and Local Storage**
|
| 23 |
+
We use Local Storage to store your preferences (such as "Dark Mode") on your device. We do not use cookies for tracking or advertising purposes.
|
| 24 |
+
|
| 25 |
+
**3. Data Retention and Ephemeral Nature**
|
| 26 |
+
The Service is hosted on **Hugging Face Spaces**, which utilizes ephemeral containerization technology.
|
| 27 |
+
|
| 28 |
+
* **Ephemeral Processing:** Any files, indices, or temporary data generated during your session are stored in ephemeral storage and are automatically permanently deleted upon the termination of the session or restart of the application container.
|
| 29 |
+
* **Log Retention:** Server logs (containing IP addresses and timestamps) are retained by Hugging Face for a period of **30 days** for security and abuse prevention purposes, after which they are deleted.
|
| 30 |
+
|
| 31 |
+
**4. Service Providers (Third-Party Processors)**
|
| 32 |
+
We employ third-party companies and individuals ("Service Providers") to facilitate our Service, to provide the Service on our behalf, and to assist us in analyzing how our Service is used. These third parties have access to your data only to perform these tasks on our behalf and are obligated not to disclose or use it for any other purpose.
|
| 33 |
+
|
| 34 |
+
The Service utilizes the following third-party API providers:
|
| 35 |
+
|
| 36 |
+
* **Semantic Scholar (Allen Institute for AI):** For the retrieval of scientific literature metadata.
|
| 37 |
+
* [Privacy Policy](https://www.google.com/search?q=https://www.semanticscholar.org/product/api%23terms)
|
| 38 |
+
* **Google (Vertex AI / Gemini):** For natural language processing and query optimization.
|
| 39 |
+
* [Google Cloud Privacy Notice](https://cloud.google.com/terms/cloud-privacy-notice)
|
| 40 |
+
* **Groq:** For large language model inference.
|
| 41 |
+
* [Groq Privacy Policy](https://wow.groq.com/privacy-policy/)
|
| 42 |
+
|
| 43 |
+
**5. Data Security**
|
| 44 |
+
The security of your data is important to us, but remember that no method of transmission over the Internet, or method of electronic storage is 100% secure. While we strive to use commercially acceptable means to protect your Personal Data, including HTTPS/TLS encryption for all data in transit, we cannot guarantee its absolute security.
|
| 45 |
+
|
| 46 |
+
**6. Links to Other Sites**
|
| 47 |
+
Our Service may contain links to other sites that are not operated by us (e.g., links to full-text PDF articles). If you click on a third-party link, you will be directed to that third party's site. We strongly advise you to review the Privacy Policy of every site you visit. We have no control over and assume no responsibility for the content, privacy policies, or practices of any third-party sites or services.
|
| 48 |
+
|
| 49 |
+
**7. Children's Privacy**
|
| 50 |
+
Our Service does not address anyone under the age of 18 ("Children"). We do not knowingly collect personally identifiable information from anyone under the age of 18.
|
| 51 |
+
|
| 52 |
+
**8. Changes to This Privacy Policy**
|
| 53 |
+
We may update our Privacy Policy from time to time. We will notify you of any changes by posting the new Privacy Policy on this page and updating the "Last Updated" date at the top of this policy. You are advised to review this Privacy Policy periodically for any changes.
|
| 54 |
+
|
| 55 |
+
**9. Contact Us**
|
| 56 |
+
If you have any questions about this Privacy Policy, please contact us:
|
| 57 |
+
|
| 58 |
+
* By visiting our page on GitHub: https://github.com/adamcseresznye/necthrall
|
| 59 |
+
"""
|
| 60 |
+
|
| 61 |
+
TERMS_OF_SERVICE = """
|
| 62 |
+
**Last Updated:** December 4, 2025
|
| 63 |
+
|
| 64 |
+
1. **Acceptance of Terms** By accessing or using the Necthrall application ("Service"), you agree to be bound by these Terms of Service ("Terms"). If you disagree with any part of the terms, you may not access the Service.
|
| 65 |
+
|
| 66 |
+
2. **Description of Service** Necthrall is an AI-powered scientific research assistant designed to retrieve, synthesize, and summarize academic literature. The Service is hosted on Hugging Face Spaces and relies on third-party APIs (including Semantic Scholar, Google AI Studio, and Groq) to function. We reserve the right to modify, suspend, or discontinue the Service at any time without notice.
|
| 67 |
+
|
| 68 |
+
3. **Critical AI Disclaimer (Must Read)** 3.1. Research Purpose Only: The Service is an experimental tool intended solely for academic and informational purposes. It is not a substitute for professional medical, legal, financial, or engineering advice. 3.2. Risk of Error ("Hallucinations"): You acknowledge that Large Language Models (LLMs) can generate incorrect, misleading, or fabricated information ("hallucinations"). While Necthrall attempts to ground answers in retrieved citations, we cannot guarantee accuracy. 3.3. Verification Required: You agree to independently verify all claims, data, and citations provided by the Service against the original source documents linked in the results. Do not rely on this tool for critical decision-making.
|
| 69 |
+
4. **User Conduct & Prohibited Uses** You agree not to use the Service:
|
| 70 |
+
|
| 71 |
+
In any way that violates any applicable national or international law or regulation.
|
| 72 |
+
|
| 73 |
+
To generate content that is fraudulent, deceptive, or promotes illegal activities.
|
| 74 |
+
|
| 75 |
+
To reverse engineer, decompile, or attempt to extract the source code or underlying algorithms of the Service (except as permitted by open-source licenses, if applicable).
|
| 76 |
+
|
| 77 |
+
To interfere with or disrupt the integrity or performance of the Service (e.g., DDoS attacks, scraping, or excessive automated querying).
|
| 78 |
+
|
| 79 |
+
5. **Intellectual Property** The Service and its original content (excluding underlying open-source components and third-party API data), features, and functionality are and will remain the exclusive property of Necthrall and its licensors. The "Necthrall" name and logo are trademarks of the Service.
|
| 80 |
+
|
| 81 |
+
6. **Third-Party Services & Content** The Service retrieves content from third-party sources (e.g., Semantic Scholar). We do not claim ownership of the academic papers, abstracts, or metadata retrieved. Your use of such content may be subject to the terms and conditions of the respective rights holders.
|
| 82 |
+
|
| 83 |
+
7. **Disclaimer of Warranties ("As Is")** THE SERVICE IS PROVIDED ON AN "AS IS" AND "AS AVAILABLE" BASIS. WE DISCLAIM ALL WARRANTIES OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. WE DO NOT WARRANT THAT THE SERVICE WILL BE UNINTERRUPTED, SECURE, OR ERROR-FREE.
|
| 84 |
+
8. **Limitation of Liability** TO THE MAXIMUM EXTENT PERMITTED BY LAW, NECTHRALL AND ITS CREATORS SHALL NOT BE LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL, CONSEQUENTIAL, OR PUNITIVE DAMAGES, OR ANY LOSS OF PROFITS OR DATA, ARISING OUT OF OR IN CONNECTION WITH YOUR USE OF THE SERVICE, OR RELIANCE ON ANY INFORMATION PROVIDED BY THE AI.
|
| 85 |
+
|
| 86 |
+
9. **Changes to Terms** We reserve the right to modify these Terms at any time. We will provide notice of significant changes by updating the "Last Updated" date at the top of this page. Your continued use of the Service after any such change constitutes your acceptance of the new Terms.
|
| 87 |
+
|
| 88 |
+
10. **Contact Us** If you have any questions about these Terms, please contact us at https://github.com/adamcseresznye/necthrall.
|
| 89 |
+
"""
|