Najeeb was born out of a desire to simplify access to Egypt's Digital Portal services. Navigating government websites can be overwhelming, so we envisioned an intelligent assistant that could quickly answer user questions. By combining web scraping, data preprocessing, and a smart chatbot architecture, Najeeb provides a user-friendly way to get information about digital services in Egypt.
We have built a comprehensive pipeline that can be run any time. It can be customized for any website with small tweaks:
- Scraping: Retrieves updated data.
- Preprocessing: A simple but powerful process that resulted in a less than 1MB TF-IDF model and matrix for retrieval.
- TODO: Can be enhanced later by using a morphological analyzer for lemmatization (achievable using Camel-tools).
- Chatbot: A mix between rule-based and corpus/retrieval-based chatbots for better conversation and human interaction.
- API Integration: A simple API integration for the UI.
- CLI Tool: A CLI tool to handle the pipeline and server.
An intelligent assistant that answers your questions about Egypt's Digital Portal services using web scraping, data preprocessing, and a combination of rule-based and TF-IDF retrieval chatbot logic.
-
Clone the repository:
git clone https://github.com/Abdo-Eid/Najeeb_chatbot cd Najeeb_chatbot -
Create a virtual environment (recommended):
python -m venv venv source venv/bin/activate # On Linux/macOS venv\Scripts\activate # On Windows
-
Install dependencies:
pip install -r requirements.txt
- Configure
config.py:
Review and adjust the file paths and chatbot rules inconfig.pyto match your environment and desired chatbot behavior.
The project includes a CLI tool (manage.py) to run different parts of the pipeline.
-
Scrape service URLs:
python manage.py scrape_url
This command uses Playwright to extract all service URLs from the Egypt Digital Portal, grouped by category, and saves them to
data/services_by_category.json. -
Scrape service details:
python manage.py scrape_services
This command uses
requestsandBeautifulSoupto scrape details for each service URL and saves the data todata/scraped_services_data.json. -
Preprocess the data:
python manage.py preprocess
This command normalizes Arabic text, removes stopwords, extracts keywords using TF-IDF, and saves the enriched data, vectorizer, and service matrix to the
data/directory. -
Run the complete pipeline:
python manage.py run_pipeline
This command executes the scraping and preprocessing steps sequentially.
-
Start the Flask API server:
python manage.py run_app
This starts the Flask server, which serves the chatbot API and web UI. You can add
--debugto enable debug mode.python manage.py run_app --debug
-
Access the web UI:
Open your web browser and go to
http://127.0.0.1:5000to interact with the chatbot.
The chatbot provides a simple API endpoint for sending messages and receiving responses.
Request:
- Content-Type:
application/json - Example request:
{
"message": "ما هي خدمات المرور؟"
}Response:
{
"response": {
"type": "tfidf",
"data": {
"category": "خدمات المرور",
"service_name": "استخراج شهادة بيانات لرخصة قيادة",
"service_url": "https://digital.gov.eg/services/654a2c9f18e999a945badc97",
"description": "تتيح لك هذه الخدمة استخراج شهادة بيانات لرخصة القيادة الخاصة بك.",
"terms": ["رخصة القيادة", "شهادة بيانات", "المرور"],
"keywords": ["شهادة", "بيانات", "رخصة", "قيادة"]
}
}
}Contributions are welcome! Here's how you can contribute:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Implement your changes.
- Test your changes thoroughly.
- Submit a pull request with a clear description of your changes.
