End-to-End Arabic NLP Application Deployed on OCI
Developed by: Abdulrahman Awadh Asban Internship @ Innovation Team β Riyadh, Saudi Arabia FebruaryβMarch 2026
This project is a complete Arabic NLP pipeline that:
- Accepts Arabic text input (Modern Standard Arabic or dialects)
- Cleans and normalizes the text (removes diacritics, normalizes characters, strips punctuation)
- Sends the cleaned text to a Hugging Face-hosted LLM via the Inference API
- Returns a structured JSON response with the original text, cleaned text, word counts, and an AI-generated summary
- Exposes the pipeline as a REST API via FastAPI
- Provides an HTML interface for browser-based testing
- Deployed on Oracle Cloud Infrastructure (OCI)
User (HTML Page)
β
FastAPI Backend (main.py)
β
Arabic Text Preprocessing (text_processing.py)
β
Hugging Face Inference API (model.py)
β
Structured JSON Response
β
Display in HTML
Why Hugging Face Inference API instead of loading the model locally? Loading Arabic LLMs locally requires 8GB+ of RAM. Using the Inference API offloads model execution to Hugging Face servers, keeping the OCI VM lightweight and the solution 100% free.
arabic_summarizer/
β
βββ main.py β FastAPI app & /summarize endpoint
βββ text_processing.py β Arabic text cleaning functions
βββ model.py β Hugging Face Inference API integration
βββ templates/
β βββ index.html β HTML testing interface
βββ .env β API keys (Hidden by .gitignore file)
βββ requirements.txt β Project dependencies
βββ README.md β Project documentation
| Component | Technology |
|---|---|
| Language | Python 3 |
| API Framework | FastAPI + Uvicorn |
| AI Integration | Hugging Face Inference API |
| Models | Qwen/Qwen2.5-72B-Instruct, meta-llama/Llama-3.1-8B-Instruct |
| Frontend | HTML + JavaScript (Fetch API) |
| Cloud Platform | Oracle Cloud Infrastructure (OCI) |
| Secret Management | python-dotenv |
Implemented in text_processing.py using Python's re (Regular Expressions) module.
| Step | What it does | Example |
|---|---|---|
| 1. Remove diacritics | Strips all harakat (tashkeel) using Unicode range \u064Bβ\u0652 |
ΩΩΨͺΩΨ¨Ω β ΩΨͺΨ¨ |
| 2. Normalize Alef | Converts Ψ£ Ψ₯ Ψ’ β Ψ§ | Ψ§ΩΨ³Ψ§Ω β Ψ₯ΩΨ³Ψ§Ω |
| 3. Remove punctuation | Strips non-Arabic, non-space characters | removes Ψ . ! etc. |
| 4. Remove numbers | Removes Arabic (Ω -Ω©) and Western (0-9) digits | |
| 5. Collapse whitespace | Replaces multiple spaces with single space |
re is Python's built-in library for pattern matching. It was chosen over specialized Arabic NLP libraries (like camel-tools or farasa) because:
- No installation required beyond standard Python
- Sufficient for structural text cleaning tasks
- Lightweight and fast for deployment on a small OCI VM
Implemented in model.py using the Hugging Face Inference API via requests.
Qwen/Qwen2.5-72B-Instruct
- Developed by Alibaba Cloud
- Strong multilingual capabilities with excellent Arabic support
- Handles both Modern Standard Arabic and dialects well
- Available on Hugging Face Inference API free tier
meta-llama/Llama-3.1-8B-Instruct
- Developed by Meta
- Lightweight (8B parameters), fast response
- Included for A/B testing and model comparison
ALLaM-7B was tested but returned an error: model too large to be loaded automatically. Hugging Face restricts models larger than 10GB from the free Serverless Inference API unless individual permission is granted. This is a known limitation documented in the Hugging Face community forums.
After testing both models on 6 Arabic texts (Formal Arabic, Riyadh dialect, Jeddah dialect):
| Formal Arabic | Riyadh Dialect | Jeddah Dialect | |
|---|---|---|---|
| Qwen 2.5 | β Excellent | β Excellent | β Excellent |
| LLaMA 3.1 | _FOLLOW) |
β Complete breakdown (Chinese characters appeared) |
Conclusion: Qwen 2.5 significantly outperforms LLaMA 3.1 on Arabic text, especially dialectal Arabic. This is likely due to larger Arabic training data in Qwen's pretraining corpus.
Implemented in main.py.
POST /summarize
Request Body (JSON):
{
"text": "Ψ§ΩΩΨ΅ Ψ§ΩΨΉΨ±Ψ¨Ω ΩΩΨ§",
"model_choice": "qwen"
}model_choice options: "qwen" (default) or "llama"
Response (JSON):
{
"original_text": "...",
"cleaned_text": "...",
"original_word_count": 95,
"cleaned_word_count": 94,
"summary": "...",
"model_used": "qwen"
}- Automatic documentation at
/docs(Swagger UI) - Built-in data validation via Pydantic
- High performance (async-capable)
- Industry standard for Python APIs
CORSMiddleware is added to allow the HTML frontend (served from a different origin) to communicate with the API without being blocked by the browser's same-origin policy.
Located in templates/index.html.
- Arabic text input (RTL layout)
- Model selector (A/B Testing between Qwen and LLaMA)
- Displays: summary, word counts before/after cleaning, cleaned text
- Communicates with FastAPI via JavaScript
fetch()POST requests
- Provider: Oracle Cloud Infrastructure (OCI)
- Region: Saudi Arabia Central (Riyadh)
- OS: Ubuntu (Linux)
- Instance Name: Abdulrahman test
1. Connect to VM:
ssh -i ssh-key-2026-01-29.key opc@<PUBLIC_IP>2. Install dependencies:
sudo apt update
sudo apt install python3-pip python3-venv -y
python3 -m venv venv
source venv/bin/activate
pip install fastapi uvicorn requests python-dotenv3. Upload project files and create .env:
echo "HF_API_KEY=your_key_here" > .env4. Run the server:
uvicorn main:app --host 0.0.0.0 --port 80005. Configure OCI Security List: Open port 8000 in the OCI Console β VCN β Security List β Add Ingress Rule.
6. Access the app:
http://<PUBLIC_IP>:8000/docs
- API keys are stored in
.envand never hardcoded in source files .envis excluded from version control (add to.gitignore)- SSH private key permissions are restricted using
icaclson Windows to comply with OpenSSH requirements
# Clone the project
git clone <repo-url>
cd arabic_summarizer
# Create virtual environment
python -m venv venv
venv\Scripts\activate # Windows
source venv/bin/activate # Linux/Mac
# Install dependencies
pip install -r requirements.txt
# Create .env file
echo HF_API_KEY=your_key_here > .env
# Run
uvicorn main:app --reload| Resource | URL |
|---|---|
| Hugging Face Inference Providers Docs | https://huggingface.co/docs/inference-providers/providers/hf-inference |
Python re Module Documentation |
https://docs.python.org/3/library/re.html |
| Requests Library β POST Requests | https://requests.readthedocs.io/en/latest/user/quickstart/#more-complicated-post-requests |
| HTTP Status Codes β MDN | https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status |
| Unicode Arabic Block (U+0600βU+06FF) | https://unicode.org/charts/PDF/U0600.pdf |
| Resource | URL |
|---|---|
| Removing Arabic Diacritics using Python β Stack Overflow | https://stackoverflow.com/questions/66988153/removing-arabic-diacritics-using-python |
| Unicode Explorer (Arabic character lookup) | https://unicode-explorer.com/search/ |
| Arabic NLP Survey β MDPI Computers Journal | https://www.mdpi.com/2073-431X/14/11/497 |
| Resource | URL |
|---|---|
| FastAPI Official Tutorial | https://fastapi.tiangolo.com/tutorial/ |
| FastAPI β Request Body with Pydantic | https://fastapi.tiangolo.com/tutorial/body/ |
| Hugging Face β Text Generation Task | https://huggingface.co/tasks/text-generation |
| OCI β Connect to Linux Instance via SSH | https://docs.oracle.com/en-us/iaas/Content/Compute/Tasks/accessinginstance.htm |
| OCI β Security Lists and Ingress Rules | https://docs.oracle.com/en-us/iaas/Content/Network/Concepts/securitylists.htm |
| python-dotenv Documentation | https://pypi.org/project/python-dotenv/ |
| Pydantic V2 Documentation | https://docs.pydantic.dev/latest/ |
| Arabic NLP Challenges β Towards Data Science | https://towardsdatascience.com/arabic-nlp-unique-challenges-and-their-solutions |
| Qwen2.5 Model Card β Hugging Face | https://huggingface.co/Qwen/Qwen2.5-72B-Instruct |
| LLaMA 3.1 Model Card β Hugging Face | https://huggingface.co/meta-llama/Llama-3.1-8B-Instruct |
This project was developed as part of an AI internship at Innovation Team, Riyadh, Saudi Arabia.