CoolFace
Apppublic

annyss/palestine-smart-library

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
App README

๐Ÿ‡ต๐Ÿ‡ธ Palestine Smart Library โ€” AI for Palestine Competition

A RAG-based (Retrieval-Augmented Generation) multilingual chatbot answering questions on the Palestinian cause from 15 official documents, with zero hallucination.


Features

FeatureDetails
Bilingual RAG ChatArabic & English, auto-detected, same language response
Anti-HallucinationCosine similarity threshold + strict system prompt
CitationsEvery answer cites [Document Title, Page X]
Upload PDFIndex new documents instantly without restart
Discourse AnalysisKeyword/entity frequency + AI thematic analysis
Compare DocumentsSide-by-side LLM comparison of two documents
Document SummaryPer-document AI summaries
Interactive MapFolium map of Palestinian cities, camps, crossings
Historical TimelinePlotly timeline from 1897 to 2025
Word CloudArabic & English word clouds per document
StatisticsCharts: pages, word counts, language distribution
Export ChatDownload full conversation as text
Auto-translateTranslate answers to the opposite language

Architecture

User Query (Arabic or English)
        โ”‚
        โ–ผ
Language Detection (langdetect)
        โ”‚
        โ–ผ
Query Embedding: "query: {text}"
   [multilingual-e5-large]
        โ”‚
        โ–ผ
FAISS IndexFlatIP (cosine similarity)
   top-k=5 chunks retrieved
        โ”‚
        โ–ผ
Similarity Threshold โ‰ฅ 0.35?
   NO  โ†’ "Not found in documents"
   YES โ†’ Continue
        โ”‚
        โ–ผ
LLM (Qwen3-30B-A3B-Thinking via OpenAI-compatible API)
   Strict system prompt โ€” no external knowledge
        โ”‚
        โ–ผ
Answer + Citations [Title, Page X]
  (in same language as query)

Tech Stack

ComponentTechnology
LLMQwen3-30B-A3B-Thinking (configurable)
Embeddingsintfloat/multilingual-e5-large
Vector DBFAISS (IndexFlatIP, cosine similarity)
PDF ParsingPyMuPDF (fitz) โ€” Arabic RTL support
Language Detectionlangdetect
UIGradio 4.x
MapsFolium + HeatMap
ChartsPlotly
Word CloudsWordCloud library

Quick Start

1. Clone and configure

bash
git clone <repo>
cd coderag
cp .env.example .env
# Edit .env โ€” add your API key and model endpoint

2. Install dependencies

bash
pip install -r requirements.txt

3. Build the FAISS index (run once)

bash
python build_index.py
# Takes ~5-15 min first time (downloads multilingual-e5-large + embeds 15 PDFs)
# Saves index/faiss.index + index/metadata.pkl for instant reload

4. Run the app

bash
python app.py
# Open http://localhost:7860

Environment Variables (.env)

env
LLM_PROVIDER=openai_compatible       # "groq" or "openai_compatible"
OPENAI_COMPATIBLE_KEY=sk-...         # API key
OPENAI_COMPATIBLE_BASE_URL=https://api.together.xyz/v1
OPENAI_COMPATIBLE_MODEL=Qwen/Qwen3-30B-A3B-Thinking
GROQ_API_KEY=gsk_...                 # Only needed if LLM_PROVIDER=groq
EMBEDDING_MODEL=intfloat/multilingual-e5-large

Document Corpus (15 PDFs)

English (8)

  • โ€”UN General Assembly Resolution 194 (1948)
  • โ€”UNRWA Technical Report 2024
  • โ€”Humanitarian Situation Update 176 โ€“ Gaza Strip (OCHA)
  • โ€”Gaza Update Report โ€“ November 2024 (OPT)
  • โ€”Israel-Palestine History Timeline 2024โ€“25
  • โ€”Palestinian Historical Calendar
  • โ€”Palestinian Identity โ€“ Rashid Khalidi
  • โ€”The Hundred Years' War on Palestine

Arabic (7)

  • โ€”ุชู‚ุฑูŠุฑ ุบุฒุฉ ุงู„ุฅู†ุณุงู†ูŠ 2024
  • โ€”ุฐุงูƒุฑุฉ ุงู„ู…ูƒุงู†
  • โ€”ุดุฎุตูŠุงุช ูู„ุณุทูŠู†ูŠุฉ
  • โ€”ูู„ุณุทูŠู† ุงู„ุนุฑุจูŠุฉ
  • โ€”ูู„ุณุทูŠู†
  • โ€”ูƒุชุงุจ ุงู„ู†ุฎุจุฉ โ€“ ุงู„ุฌุฒุก ุงู„ุฃูˆู„
  • โ€”ูƒุชุงุจ ุงู„ู†ุฎุจุฉ โ€“ ุงู„ุฌุฒุก ุงู„ุซุงู†ูŠ

Anti-Hallucination Design

  1. 1.Vector similarity threshold: Best retrieved chunk cosine similarity < 0.35 โ†’ system returns the exact string "This information was not found in the available documents." โ€” LLM is never called.
  2. 2.Strict system prompt: LLM instructed to answer only from provided excerpts, cite sources, and not use external knowledge.
  3. 3.Temperature = 0.1: Minimal creativity, maximum factuality.
  4. 4.No web search: Completely offline retrieval (no external APIs during inference).

Project Structure

coderag/
โ”œโ”€โ”€ app.py                  # Main Gradio app
โ”œโ”€โ”€ build_index.py          # One-time index builder
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ .env                    # API keys (never commit)
โ”œโ”€โ”€ .env.example
โ”œโ”€โ”€ official_docs/          # 15 PDFs
โ”œโ”€โ”€ index/                  # FAISS index (built by build_index.py)
โ”œโ”€โ”€ rag/
โ”‚   โ”œโ”€โ”€ document_loader.py  # PDF loading + chunking + metadata
โ”‚   โ”œโ”€โ”€ embeddings.py       # multilingual-e5-large wrapper
โ”‚   โ”œโ”€โ”€ vector_store.py     # FAISS wrapper with dynamic add
โ”‚   โ””โ”€โ”€ generator.py        # LLM generation + anti-hallucination
โ”œโ”€โ”€ tabs/
โ”‚   โ”œโ”€โ”€ chat_tab.py
โ”‚   โ”œโ”€โ”€ discourse_tab.py
โ”‚   โ”œโ”€โ”€ compare_tab.py
โ”‚   โ”œโ”€โ”€ summary_tab.py
โ”‚   โ”œโ”€โ”€ map_tab.py
โ”‚   โ”œโ”€โ”€ timeline_tab.py
โ”‚   โ”œโ”€โ”€ wordcloud_tab.py
โ”‚   โ”œโ”€โ”€ statistics_tab.py
โ”‚   โ”œโ”€โ”€ upload_tab.py
โ”‚   โ””โ”€โ”€ about_tab.py
โ””โ”€โ”€ utils/
    โ””โ”€โ”€ language.py         # Language detection

Competition

AI for Palestine โ€” Smart Library Submission deadline: April 24, 2026 Team email: anisbensab@gmail.com