initial UI
Browse files- QUICKSTART.md +126 -0
- README_SETUP.md +158 -0
- check_dependencies.py +29 -0
- requirements.txt +2 -0
- run_app.py +43 -0
- src/app.py +216 -0
- src/index.html +1139 -0
- src/model_loader.py +255 -0
- test_model_load.py +44 -0
QUICKSTART.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Bayan - Quick Start Guide
|
| 2 |
+
|
| 3 |
+
## 🚀 Quick Start
|
| 4 |
+
|
| 5 |
+
### 1. Install Dependencies
|
| 6 |
+
```bash
|
| 7 |
+
pip install -r requirements.txt
|
| 8 |
+
```
|
| 9 |
+
|
| 10 |
+
**Note:** If you have issues, install PyTorch separately:
|
| 11 |
+
- CPU: `pip install torch --index-url https://download.pytorch.org/whl/cpu`
|
| 12 |
+
- GPU: Visit https://pytorch.org/get-started/locally/
|
| 13 |
+
|
| 14 |
+
### 2. Run the Application
|
| 15 |
+
```bash
|
| 16 |
+
python run_app.py
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
### 3. Open in Browser
|
| 20 |
+
Navigate to: **http://localhost:5000**
|
| 21 |
+
|
| 22 |
+
## 📁 Project Structure
|
| 23 |
+
|
| 24 |
+
```
|
| 25 |
+
Bayan/
|
| 26 |
+
├── src/
|
| 27 |
+
│ ├── app.py # Flask backend server
|
| 28 |
+
│ ├── model_loader.py # Model loading and inference
|
| 29 |
+
│ └── index.html # Web interface
|
| 30 |
+
├── models/
|
| 31 |
+
│ └── arabic_summarization_model/
|
| 32 |
+
│ └── content/drive/MyDrive/arabic_summarization_model/
|
| 33 |
+
│ ├── config.json
|
| 34 |
+
│ ├── model.safetensors
|
| 35 |
+
│ └── ... (other model files)
|
| 36 |
+
├── run_app.py # Application launcher
|
| 37 |
+
├── requirements.txt # Python dependencies
|
| 38 |
+
└── README_SETUP.md # Detailed setup guide
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
## 🔧 Features
|
| 42 |
+
|
| 43 |
+
✅ **Robust Error Handling**
|
| 44 |
+
- Path validation for model files
|
| 45 |
+
- Graceful fallbacks if model loading fails
|
| 46 |
+
- Input validation and sanitization
|
| 47 |
+
- Clear error messages
|
| 48 |
+
|
| 49 |
+
✅ **Security**
|
| 50 |
+
- Input length limits (max 5000 characters)
|
| 51 |
+
- CORS enabled for web interface
|
| 52 |
+
- Safe model loading
|
| 53 |
+
- Error logging
|
| 54 |
+
|
| 55 |
+
✅ **User Experience**
|
| 56 |
+
- Loading indicators
|
| 57 |
+
- Real-time feedback
|
| 58 |
+
- Arabic language support
|
| 59 |
+
- Responsive design
|
| 60 |
+
|
| 61 |
+
## 🧪 Testing
|
| 62 |
+
|
| 63 |
+
### Test API Health
|
| 64 |
+
```bash
|
| 65 |
+
curl http://localhost:5000/api/health
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
### Test Summarization
|
| 69 |
+
```bash
|
| 70 |
+
curl -X POST http://localhost:5000/api/summarize \
|
| 71 |
+
-H "Content-Type: application/json" \
|
| 72 |
+
-d '{"text": "نص تجريبي للاختبار", "length": 2, "full_text": true}'
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
## 🐛 Troubleshooting
|
| 76 |
+
|
| 77 |
+
### Model Not Found
|
| 78 |
+
- Verify model path: `models/arabic_summarization_model/content/drive/MyDrive/arabic_summarization_model/`
|
| 79 |
+
- Check that `config.json` exists
|
| 80 |
+
- The app will search multiple possible locations automatically
|
| 81 |
+
|
| 82 |
+
### Dependencies Missing
|
| 83 |
+
```bash
|
| 84 |
+
python check_dependencies.py
|
| 85 |
+
pip install -r requirements.txt
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
### Port Already in Use
|
| 89 |
+
```bash
|
| 90 |
+
set PORT=5001
|
| 91 |
+
python run_app.py
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
## 📝 API Documentation
|
| 95 |
+
|
| 96 |
+
### POST /api/summarize
|
| 97 |
+
Summarize Arabic text.
|
| 98 |
+
|
| 99 |
+
**Request:**
|
| 100 |
+
```json
|
| 101 |
+
{
|
| 102 |
+
"text": "النص العربي...",
|
| 103 |
+
"length": 2, // 1=short, 2=medium, 3=long
|
| 104 |
+
"full_text": true
|
| 105 |
+
}
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
**Response:**
|
| 109 |
+
```json
|
| 110 |
+
{
|
| 111 |
+
"status": "success",
|
| 112 |
+
"summary": "الملخص...",
|
| 113 |
+
"original_length": 500,
|
| 114 |
+
"summary_length": 150
|
| 115 |
+
}
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
## 🎯 Next Steps
|
| 119 |
+
|
| 120 |
+
1. Install dependencies: `pip install -r requirements.txt`
|
| 121 |
+
2. Run the app: `python run_app.py`
|
| 122 |
+
3. Open browser: http://localhost:5000
|
| 123 |
+
4. Write Arabic text and click "توليد الملخص"
|
| 124 |
+
|
| 125 |
+
For detailed information, see `README_SETUP.md`.
|
| 126 |
+
|
README_SETUP.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Bayan - Arabic Text Summarization Setup Guide
|
| 2 |
+
|
| 3 |
+
## Overview
|
| 4 |
+
Bayan is an Arabic text summarization application with a web interface. This guide will help you set up and run the application.
|
| 5 |
+
|
| 6 |
+
## Prerequisites
|
| 7 |
+
- Python 3.8 or higher
|
| 8 |
+
- pip (Python package manager)
|
| 9 |
+
- At least 4GB RAM (8GB+ recommended for better performance)
|
| 10 |
+
- Model files in the correct location (see below)
|
| 11 |
+
|
| 12 |
+
## Installation Steps
|
| 13 |
+
|
| 14 |
+
### 1. Install Dependencies
|
| 15 |
+
```bash
|
| 16 |
+
pip install -r requirements.txt
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
**Note:** If you encounter issues installing PyTorch, you may need to install it separately:
|
| 20 |
+
- For CPU: `pip install torch --index-url https://download.pytorch.org/whl/cpu`
|
| 21 |
+
- For CUDA: Visit https://pytorch.org/get-started/locally/ for the appropriate command
|
| 22 |
+
|
| 23 |
+
### 2. Verify Model Location
|
| 24 |
+
The model should be located at:
|
| 25 |
+
```
|
| 26 |
+
models/arabic_summarization_model/content/drive/MyDrive/arabic_summarization_model/
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
Required files:
|
| 30 |
+
- `config.json`
|
| 31 |
+
- `tokenizer.json`
|
| 32 |
+
- `model.safetensors`
|
| 33 |
+
- `sentencepiece.bpe.model`
|
| 34 |
+
- Other tokenizer/model files
|
| 35 |
+
|
| 36 |
+
### 3. Run the Application
|
| 37 |
+
|
| 38 |
+
#### Option A: Using the run script (Recommended)
|
| 39 |
+
```bash
|
| 40 |
+
python run_app.py
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
#### Option B: Direct Flask run
|
| 44 |
+
```bash
|
| 45 |
+
cd src
|
| 46 |
+
python app.py
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
#### Option C: Using Flask CLI
|
| 50 |
+
```bash
|
| 51 |
+
cd src
|
| 52 |
+
export FLASK_APP=app.py
|
| 53 |
+
flask run
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
### 4. Access the Application
|
| 57 |
+
Open your browser and navigate to:
|
| 58 |
+
```
|
| 59 |
+
http://localhost:5000
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
## Configuration
|
| 63 |
+
|
| 64 |
+
### Environment Variables
|
| 65 |
+
- `PORT`: Server port (default: 5000)
|
| 66 |
+
- `DEBUG`: Enable debug mode (default: False)
|
| 67 |
+
```bash
|
| 68 |
+
export DEBUG=True
|
| 69 |
+
export PORT=8080
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
## Troubleshooting
|
| 73 |
+
|
| 74 |
+
### Model Not Found Error
|
| 75 |
+
If you see "Model not found" error:
|
| 76 |
+
1. Verify the model path exists
|
| 77 |
+
2. Check that all required files are present
|
| 78 |
+
3. The application will search multiple possible paths automatically
|
| 79 |
+
|
| 80 |
+
### Out of Memory Error
|
| 81 |
+
If you encounter memory issues:
|
| 82 |
+
1. Close other applications
|
| 83 |
+
2. Use CPU mode (it will automatically use CPU if CUDA is not available)
|
| 84 |
+
3. Reduce the `MAX_TEXT_LENGTH` in `src/app.py` if needed
|
| 85 |
+
|
| 86 |
+
### Port Already in Use
|
| 87 |
+
If port 5000 is already in use:
|
| 88 |
+
```bash
|
| 89 |
+
export PORT=5001
|
| 90 |
+
python run_app.py
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
### Slow Performance
|
| 94 |
+
- First run will be slower as the model loads
|
| 95 |
+
- Subsequent requests will be faster
|
| 96 |
+
- Using GPU (CUDA) significantly improves performance
|
| 97 |
+
|
| 98 |
+
## API Endpoints
|
| 99 |
+
|
| 100 |
+
### Health Check
|
| 101 |
+
```
|
| 102 |
+
GET /api/health
|
| 103 |
+
```
|
| 104 |
+
Returns server status and model loading state.
|
| 105 |
+
|
| 106 |
+
### Summarize Text
|
| 107 |
+
```
|
| 108 |
+
POST /api/summarize
|
| 109 |
+
Content-Type: application/json
|
| 110 |
+
|
| 111 |
+
{
|
| 112 |
+
"text": "النص العربي المراد تلخيصه...",
|
| 113 |
+
"length": 2, // 1=short, 2=medium, 3=long
|
| 114 |
+
"full_text": true
|
| 115 |
+
}
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
Response:
|
| 119 |
+
```json
|
| 120 |
+
{
|
| 121 |
+
"status": "success",
|
| 122 |
+
"summary": "الملخص المولد...",
|
| 123 |
+
"original_length": 500,
|
| 124 |
+
"summary_length": 150
|
| 125 |
+
}
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
## Security Features
|
| 129 |
+
|
| 130 |
+
- Input validation (text length limits)
|
| 131 |
+
- CORS enabled for web interface
|
| 132 |
+
- Error handling and logging
|
| 133 |
+
- Path validation for model files
|
| 134 |
+
- Safe model loading with fallbacks
|
| 135 |
+
|
| 136 |
+
## Development
|
| 137 |
+
|
| 138 |
+
### Running in Debug Mode
|
| 139 |
+
```bash
|
| 140 |
+
export DEBUG=True
|
| 141 |
+
python run_app.py
|
| 142 |
+
```
|
| 143 |
+
|
| 144 |
+
### Testing the API
|
| 145 |
+
```bash
|
| 146 |
+
curl -X POST http://localhost:5000/api/summarize \
|
| 147 |
+
-H "Content-Type: application/json" \
|
| 148 |
+
-d '{"text": "نص تجريبي للاختبار", "length": 2, "full_text": true}'
|
| 149 |
+
```
|
| 150 |
+
|
| 151 |
+
## Support
|
| 152 |
+
|
| 153 |
+
For issues or questions:
|
| 154 |
+
1. Check the logs in the terminal
|
| 155 |
+
2. Verify model files are correct
|
| 156 |
+
3. Ensure all dependencies are installed
|
| 157 |
+
4. Check Python version compatibility
|
| 158 |
+
|
check_dependencies.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Check if all required dependencies are installed."""
|
| 2 |
+
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
required_packages = {
|
| 6 |
+
'flask': 'Flask',
|
| 7 |
+
'flask_cors': 'flask-cors',
|
| 8 |
+
'transformers': 'transformers',
|
| 9 |
+
'torch': 'torch',
|
| 10 |
+
'sentencepiece': 'sentencepiece',
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
missing = []
|
| 14 |
+
for module, package in required_packages.items():
|
| 15 |
+
try:
|
| 16 |
+
__import__(module)
|
| 17 |
+
print(f"✓ {package} is installed")
|
| 18 |
+
except ImportError:
|
| 19 |
+
print(f"✗ {package} is NOT installed")
|
| 20 |
+
missing.append(package)
|
| 21 |
+
|
| 22 |
+
if missing:
|
| 23 |
+
print(f"\nMissing packages: {', '.join(missing)}")
|
| 24 |
+
print("Install them with: pip install -r requirements.txt")
|
| 25 |
+
sys.exit(1)
|
| 26 |
+
else:
|
| 27 |
+
print("\nAll dependencies are installed!")
|
| 28 |
+
sys.exit(0)
|
| 29 |
+
|
requirements.txt
CHANGED
|
@@ -6,3 +6,5 @@ sentencepiece
|
|
| 6 |
scikit-learn
|
| 7 |
numpy
|
| 8 |
pandas
|
|
|
|
|
|
|
|
|
| 6 |
scikit-learn
|
| 7 |
numpy
|
| 8 |
pandas
|
| 9 |
+
flask
|
| 10 |
+
flask-cors
|
run_app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Simple script to run the Bayan application.
|
| 3 |
+
Usage: python run_app.py
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import sys
|
| 7 |
+
import os
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
# Add src directory to path
|
| 11 |
+
src_path = Path(__file__).parent / 'src'
|
| 12 |
+
sys.path.insert(0, str(src_path))
|
| 13 |
+
|
| 14 |
+
# Change to src directory
|
| 15 |
+
os.chdir(src_path)
|
| 16 |
+
|
| 17 |
+
# Import and run the app
|
| 18 |
+
if __name__ == '__main__':
|
| 19 |
+
from app import app, load_model
|
| 20 |
+
import logging
|
| 21 |
+
|
| 22 |
+
logging.basicConfig(
|
| 23 |
+
level=logging.INFO,
|
| 24 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
logger = logging.getLogger(__name__)
|
| 28 |
+
logger.info("Starting Bayan application...")
|
| 29 |
+
|
| 30 |
+
# Load model
|
| 31 |
+
if not load_model():
|
| 32 |
+
logger.error("Failed to load model. Server will start but summarization will not work.")
|
| 33 |
+
logger.error("Please check that the model files are in the correct location.")
|
| 34 |
+
|
| 35 |
+
# Run the app
|
| 36 |
+
port = int(os.environ.get('PORT', 5000))
|
| 37 |
+
debug = os.environ.get('DEBUG', 'False').lower() == 'true'
|
| 38 |
+
|
| 39 |
+
logger.info(f"Starting server on http://localhost:{port}")
|
| 40 |
+
logger.info("Press Ctrl+C to stop the server")
|
| 41 |
+
|
| 42 |
+
app.run(host='0.0.0.0', port=port, debug=debug)
|
| 43 |
+
|
src/app.py
ADD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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Flask backend server for Arabic text summarization.
|
| 3 |
+
Provides API endpoints for the Bayan web application.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
import logging
|
| 8 |
+
from flask import Flask, request, jsonify
|
| 9 |
+
from flask_cors import CORS
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
import traceback
|
| 12 |
+
|
| 13 |
+
from model_loader import SummarizationModel
|
| 14 |
+
|
| 15 |
+
# Configure logging
|
| 16 |
+
logging.basicConfig(
|
| 17 |
+
level=logging.INFO,
|
| 18 |
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
| 19 |
+
)
|
| 20 |
+
logger = logging.getLogger(__name__)
|
| 21 |
+
|
| 22 |
+
# Initialize Flask app
|
| 23 |
+
app = Flask(__name__, static_folder='.', static_url_path='')
|
| 24 |
+
CORS(app) # Enable CORS for all routes
|
| 25 |
+
|
| 26 |
+
# Configuration
|
| 27 |
+
MAX_TEXT_LENGTH = 5000 # Maximum characters for input text
|
| 28 |
+
MAX_SUMMARY_LENGTH = 512 # Maximum tokens for summary
|
| 29 |
+
MIN_TEXT_LENGTH = 10 # Minimum characters for summarization
|
| 30 |
+
|
| 31 |
+
# Global model instance
|
| 32 |
+
model = None
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def get_model_path():
|
| 36 |
+
"""Get the model path, handling different possible locations."""
|
| 37 |
+
base_path = Path(__file__).parent.parent
|
| 38 |
+
current_dir = Path.cwd()
|
| 39 |
+
|
| 40 |
+
# Try different possible paths
|
| 41 |
+
possible_paths = [
|
| 42 |
+
base_path / "models" / "arabic_summarization_model" / "content" / "drive" / "MyDrive" / "arabic_summarization_model",
|
| 43 |
+
base_path / "models" / "arabic_summarization_model",
|
| 44 |
+
current_dir / "models" / "arabic_summarization_model" / "content" / "drive" / "MyDrive" / "arabic_summarization_model",
|
| 45 |
+
current_dir / "models" / "arabic_summarization_model",
|
| 46 |
+
Path("models") / "arabic_summarization_model" / "content" / "drive" / "MyDrive" / "arabic_summarization_model",
|
| 47 |
+
Path("models") / "arabic_summarization_model",
|
| 48 |
+
]
|
| 49 |
+
|
| 50 |
+
for path in possible_paths:
|
| 51 |
+
path = path.resolve() # Resolve to absolute path
|
| 52 |
+
if path.exists() and (path / "config.json").exists():
|
| 53 |
+
logger.info(f"Found model at: {path}")
|
| 54 |
+
return str(path)
|
| 55 |
+
|
| 56 |
+
# Provide helpful error message
|
| 57 |
+
error_msg = f"Model not found. Searched in:\n"
|
| 58 |
+
for p in possible_paths:
|
| 59 |
+
error_msg += f" - {p.resolve()}\n"
|
| 60 |
+
error_msg += "\nPlease ensure the model files are in one of these locations."
|
| 61 |
+
raise FileNotFoundError(error_msg)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def load_model():
|
| 65 |
+
"""Load the summarization model."""
|
| 66 |
+
global model
|
| 67 |
+
try:
|
| 68 |
+
model_path = get_model_path()
|
| 69 |
+
logger.info(f"Loading model from: {model_path}")
|
| 70 |
+
model = SummarizationModel(model_path)
|
| 71 |
+
logger.info("Model loaded successfully")
|
| 72 |
+
return True
|
| 73 |
+
except Exception as e:
|
| 74 |
+
logger.error(f"Error loading model: {str(e)}")
|
| 75 |
+
logger.error(traceback.format_exc())
|
| 76 |
+
return False
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
@app.route('/')
|
| 80 |
+
def index():
|
| 81 |
+
"""Serve the main HTML file."""
|
| 82 |
+
return app.send_static_file('index.html')
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
@app.route('/api/health', methods=['GET'])
|
| 86 |
+
def health_check():
|
| 87 |
+
"""Health check endpoint."""
|
| 88 |
+
return jsonify({
|
| 89 |
+
'status': 'healthy',
|
| 90 |
+
'model_loaded': model is not None
|
| 91 |
+
})
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
@app.route('/api/summarize', methods=['POST'])
|
| 95 |
+
def summarize():
|
| 96 |
+
"""
|
| 97 |
+
Summarize Arabic text.
|
| 98 |
+
|
| 99 |
+
Expected JSON payload:
|
| 100 |
+
{
|
| 101 |
+
"text": "Arabic text to summarize",
|
| 102 |
+
"length": 1-3 (1=short, 2=medium, 3=long),
|
| 103 |
+
"full_text": true/false (whether to summarize full text or just first paragraph)
|
| 104 |
+
}
|
| 105 |
+
"""
|
| 106 |
+
if model is None:
|
| 107 |
+
return jsonify({
|
| 108 |
+
'error': 'Model not loaded. Please check server logs.',
|
| 109 |
+
'status': 'error'
|
| 110 |
+
}), 503
|
| 111 |
+
|
| 112 |
+
try:
|
| 113 |
+
# Validate request
|
| 114 |
+
if not request.is_json:
|
| 115 |
+
return jsonify({
|
| 116 |
+
'error': 'Request must be JSON',
|
| 117 |
+
'status': 'error'
|
| 118 |
+
}), 400
|
| 119 |
+
|
| 120 |
+
data = request.get_json()
|
| 121 |
+
|
| 122 |
+
# Validate input text
|
| 123 |
+
text = data.get('text', '').strip()
|
| 124 |
+
if not text:
|
| 125 |
+
return jsonify({
|
| 126 |
+
'error': 'Text is required',
|
| 127 |
+
'status': 'error'
|
| 128 |
+
}), 400
|
| 129 |
+
|
| 130 |
+
if len(text) < MIN_TEXT_LENGTH:
|
| 131 |
+
return jsonify({
|
| 132 |
+
'error': f'Text must be at least {MIN_TEXT_LENGTH} characters',
|
| 133 |
+
'status': 'error'
|
| 134 |
+
}), 400
|
| 135 |
+
|
| 136 |
+
if len(text) > MAX_TEXT_LENGTH:
|
| 137 |
+
return jsonify({
|
| 138 |
+
'error': f'Text must be at most {MAX_TEXT_LENGTH} characters',
|
| 139 |
+
'status': 'error'
|
| 140 |
+
}), 400
|
| 141 |
+
|
| 142 |
+
# Get parameters
|
| 143 |
+
length = int(data.get('length', 2)) # Default to medium
|
| 144 |
+
length = max(1, min(3, length)) # Clamp between 1 and 3
|
| 145 |
+
|
| 146 |
+
full_text = data.get('full_text', True)
|
| 147 |
+
|
| 148 |
+
# Calculate max_length based on length parameter
|
| 149 |
+
# Short: ~30% of input, Medium: ~50%, Long: ~70%
|
| 150 |
+
input_length = len(text.split())
|
| 151 |
+
length_multipliers = {1: 0.3, 2: 0.5, 3: 0.7}
|
| 152 |
+
max_length = max(20, int(input_length * length_multipliers[length]))
|
| 153 |
+
max_length = min(max_length, MAX_SUMMARY_LENGTH)
|
| 154 |
+
|
| 155 |
+
# Generate summary
|
| 156 |
+
logger.info(f"Generating summary: length={length}, max_length={max_length}, text_length={len(text)}")
|
| 157 |
+
summary = model.summarize(text, max_length=max_length, min_length=max(10, max_length // 3))
|
| 158 |
+
|
| 159 |
+
return jsonify({
|
| 160 |
+
'summary': summary,
|
| 161 |
+
'status': 'success',
|
| 162 |
+
'original_length': len(text),
|
| 163 |
+
'summary_length': len(summary)
|
| 164 |
+
})
|
| 165 |
+
|
| 166 |
+
except ValueError as e:
|
| 167 |
+
logger.error(f"Validation error: {str(e)}")
|
| 168 |
+
return jsonify({
|
| 169 |
+
'error': f'Invalid input: {str(e)}',
|
| 170 |
+
'status': 'error'
|
| 171 |
+
}), 400
|
| 172 |
+
|
| 173 |
+
except Exception as e:
|
| 174 |
+
logger.error(f"Error during summarization: {str(e)}")
|
| 175 |
+
logger.error(traceback.format_exc())
|
| 176 |
+
return jsonify({
|
| 177 |
+
'error': 'An error occurred during summarization. Please try again.',
|
| 178 |
+
'status': 'error',
|
| 179 |
+
'details': str(e) if app.debug else None
|
| 180 |
+
}), 500
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
@app.errorhandler(404)
|
| 184 |
+
def not_found(error):
|
| 185 |
+
"""Handle 404 errors."""
|
| 186 |
+
return jsonify({
|
| 187 |
+
'error': 'Endpoint not found',
|
| 188 |
+
'status': 'error'
|
| 189 |
+
}), 404
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
@app.errorhandler(500)
|
| 193 |
+
def internal_error(error):
|
| 194 |
+
"""Handle 500 errors."""
|
| 195 |
+
logger.error(f"Internal server error: {str(error)}")
|
| 196 |
+
return jsonify({
|
| 197 |
+
'error': 'Internal server error',
|
| 198 |
+
'status': 'error'
|
| 199 |
+
}), 500
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
if __name__ == '__main__':
|
| 203 |
+
# Load model on startup
|
| 204 |
+
logger.info("Starting Bayan server...")
|
| 205 |
+
|
| 206 |
+
if not load_model():
|
| 207 |
+
logger.error("Failed to load model. Server will start but summarization will not work.")
|
| 208 |
+
logger.error("Please check that the model files are in the correct location.")
|
| 209 |
+
|
| 210 |
+
# Run the app
|
| 211 |
+
port = int(os.environ.get('PORT', 5000))
|
| 212 |
+
debug = os.environ.get('DEBUG', 'False').lower() == 'true'
|
| 213 |
+
|
| 214 |
+
logger.info(f"Starting server on port {port} (debug={debug})")
|
| 215 |
+
app.run(host='0.0.0.0', port=port, debug=debug)
|
| 216 |
+
|
src/index.html
ADDED
|
@@ -0,0 +1,1139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
<html lang="ar" dir="rtl" class="h-full">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>بيان - مساعد الكتابة العربية الذكي</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<script src="/_sdk/element_sdk.js"></script>
|
| 9 |
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
| 10 |
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 11 |
+
<link href="https://fonts.googleapis.com/css2?family=Noto+Kufi+Arabic:wght@300;400;500;600;700;800&family=Tajawal:wght@300;400;500;700;800&display=swap" rel="stylesheet">
|
| 12 |
+
<style>
|
| 13 |
+
body {
|
| 14 |
+
box-sizing: border-box;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
* {
|
| 18 |
+
font-family: 'Tajawal', 'Noto Kufi Arabic', sans-serif;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
.gradient-bg {
|
| 22 |
+
background: linear-gradient(165deg, #0a1628 0%, #1a2744 40%, #0f1b2e 100%);
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
.gradient-accent {
|
| 26 |
+
background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
.text-gradient {
|
| 30 |
+
background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
|
| 31 |
+
-webkit-background-clip: text;
|
| 32 |
+
-webkit-text-fill-color: transparent;
|
| 33 |
+
background-clip: text;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
.card-hover {
|
| 37 |
+
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
.card-hover:hover {
|
| 41 |
+
transform: translateY(-4px);
|
| 42 |
+
box-shadow: 0 20px 40px -10px rgba(59, 130, 246, 0.3);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
.spelling-error {
|
| 46 |
+
background: rgba(239, 68, 68, 0.15);
|
| 47 |
+
border-bottom: 2px solid #ef4444;
|
| 48 |
+
cursor: pointer;
|
| 49 |
+
position: relative;
|
| 50 |
+
padding: 0 2px;
|
| 51 |
+
border-radius: 2px;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
.grammar-error {
|
| 55 |
+
background: rgba(251, 191, 36, 0.15);
|
| 56 |
+
border-bottom: 2px solid #fbbf24;
|
| 57 |
+
cursor: pointer;
|
| 58 |
+
position: relative;
|
| 59 |
+
padding: 0 2px;
|
| 60 |
+
border-radius: 2px;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
.punctuation-suggestion {
|
| 64 |
+
background: rgba(34, 197, 94, 0.15);
|
| 65 |
+
border-bottom: 2px solid #22c55e;
|
| 66 |
+
cursor: pointer;
|
| 67 |
+
position: relative;
|
| 68 |
+
padding: 0 2px;
|
| 69 |
+
border-radius: 2px;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
.editor-content {
|
| 73 |
+
line-height: 2.2;
|
| 74 |
+
letter-spacing: 0.02em;
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
.page {
|
| 78 |
+
display: none;
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
.page.active {
|
| 82 |
+
display: block;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
.nav-link {
|
| 86 |
+
position: relative;
|
| 87 |
+
transition: all 0.3s ease;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
.nav-link::after {
|
| 91 |
+
content: '';
|
| 92 |
+
position: absolute;
|
| 93 |
+
bottom: -2px;
|
| 94 |
+
right: 0;
|
| 95 |
+
width: 0;
|
| 96 |
+
height: 2px;
|
| 97 |
+
background: var(--primary-color);
|
| 98 |
+
transition: width 0.3s ease;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
.nav-link:hover::after,
|
| 102 |
+
.nav-link.active::after {
|
| 103 |
+
width: 100%;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
.tooltip {
|
| 107 |
+
position: absolute;
|
| 108 |
+
background: var(--surface-color);
|
| 109 |
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
| 110 |
+
border-radius: 12px;
|
| 111 |
+
padding: 16px;
|
| 112 |
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
|
| 113 |
+
z-index: 1000;
|
| 114 |
+
max-width: 300px;
|
| 115 |
+
display: none;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
.tooltip.show {
|
| 119 |
+
display: block;
|
| 120 |
+
}
|
| 121 |
+
|
| 122 |
+
.score-circle {
|
| 123 |
+
transition: stroke-dashoffset 1s ease-in-out;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
.feature-icon {
|
| 127 |
+
width: 48px;
|
| 128 |
+
height: 48px;
|
| 129 |
+
display: flex;
|
| 130 |
+
align-items: center;
|
| 131 |
+
justify-content: center;
|
| 132 |
+
border-radius: 12px;
|
| 133 |
+
font-size: 24px;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
.animate-fade-in {
|
| 137 |
+
animation: fadeIn 0.6s ease-in-out;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
@keyframes fadeIn {
|
| 141 |
+
from { opacity: 0; transform: translateY(20px); }
|
| 142 |
+
to { opacity: 1; transform: translateY(0); }
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
.animate-float {
|
| 146 |
+
animation: float 6s ease-in-out infinite;
|
| 147 |
+
}
|
| 148 |
+
|
| 149 |
+
@keyframes float {
|
| 150 |
+
0%, 100% { transform: translateY(0px); }
|
| 151 |
+
50% { transform: translateY(-20px); }
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.editor-textarea {
|
| 155 |
+
background: linear-gradient(180deg, #ffffff 0%, #fafbfc 100%);
|
| 156 |
+
color: #1a202c;
|
| 157 |
+
resize: none;
|
| 158 |
+
min-height: 500px;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
.editor-textarea:focus {
|
| 162 |
+
outline: none;
|
| 163 |
+
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
:root {
|
| 167 |
+
--primary-color: #3b82f6;
|
| 168 |
+
--secondary-color: #8b5cf6;
|
| 169 |
+
--text-color: #f1f5f9;
|
| 170 |
+
--text-secondary: #cbd5e1;
|
| 171 |
+
--surface-color: #1e293b;
|
| 172 |
+
--background-color: #0f172a;
|
| 173 |
+
--success-color: #22c55e;
|
| 174 |
+
--warning-color: #fbbf24;
|
| 175 |
+
--error-color: #ef4444;
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
.pricing-badge {
|
| 179 |
+
position: absolute;
|
| 180 |
+
top: -12px;
|
| 181 |
+
right: 50%;
|
| 182 |
+
transform: translateX(50%);
|
| 183 |
+
padding: 4px 16px;
|
| 184 |
+
border-radius: 20px;
|
| 185 |
+
font-size: 12px;
|
| 186 |
+
font-weight: 700;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
.suggestion-item {
|
| 190 |
+
transition: all 0.2s ease;
|
| 191 |
+
cursor: pointer;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
.suggestion-item:hover {
|
| 195 |
+
background: rgba(59, 130, 246, 0.1);
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
input[type="range"] {
|
| 199 |
+
-webkit-appearance: none;
|
| 200 |
+
appearance: none;
|
| 201 |
+
background: transparent;
|
| 202 |
+
cursor: pointer;
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
input[type="range"]::-webkit-slider-track {
|
| 206 |
+
background: rgba(255, 255, 255, 0.1);
|
| 207 |
+
height: 6px;
|
| 208 |
+
border-radius: 3px;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
input[type="range"]::-webkit-slider-thumb {
|
| 212 |
+
-webkit-appearance: none;
|
| 213 |
+
appearance: none;
|
| 214 |
+
background: var(--primary-color);
|
| 215 |
+
height: 18px;
|
| 216 |
+
width: 18px;
|
| 217 |
+
border-radius: 50%;
|
| 218 |
+
margin-top: -6px;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
.summary-preview {
|
| 222 |
+
max-height: 0;
|
| 223 |
+
overflow: hidden;
|
| 224 |
+
transition: max-height 0.4s ease-in-out;
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
.summary-preview.show {
|
| 228 |
+
max-height: 400px;
|
| 229 |
+
}
|
| 230 |
+
</style>
|
| 231 |
+
<style>@view-transition { navigation: auto; }</style>
|
| 232 |
+
<script src="/_sdk/data_sdk.js" type="text/javascript"></script>
|
| 233 |
+
</head>
|
| 234 |
+
<body class="h-full" style="background-color: var(--background-color); color: var(--text-color);">
|
| 235 |
+
<div class="h-full overflow-auto"><!-- Navigation -->
|
| 236 |
+
<nav class="fixed top-0 right-0 left-0 z-50 backdrop-blur-xl border-b" style="background: rgba(15, 23, 42, 0.85); border-color: rgba(255, 255, 255, 0.08);">
|
| 237 |
+
<div class="max-w-7xl mx-auto px-6 py-4">
|
| 238 |
+
<div class="flex items-center justify-between"><!-- Logo & Brand (Right side in RTL) -->
|
| 239 |
+
<div class="flex items-center gap-3">
|
| 240 |
+
<div class="w-10 h-10 rounded-xl flex items-center justify-center gradient-accent"><span class="text-white text-xl font-bold">ب</span>
|
| 241 |
+
</div><span id="nav-brand" class="text-2xl font-bold text-gradient">بيان</span>
|
| 242 |
+
</div><!-- Nav Links (Center) -->
|
| 243 |
+
<div class="hidden md:flex items-center gap-8"><button onclick="showPage('home')" class="nav-link active text-base font-medium" style="color: var(--text-color);" data-page="home">الرئيسية</button> <button onclick="showPage('features')" class="nav-link text-base font-medium" style="color: var(--text-secondary);" data-page="features">الميزات</button> <button onclick="showPage('editor')" class="nav-link text-base font-medium" style="color: var(--text-secondary);" data-page="editor">المحرر</button> <button onclick="showPage('pricing')" class="nav-link text-base font-medium" style="color: var(--text-secondary);" data-page="pricing">الأسعار</button>
|
| 244 |
+
</div><!-- CTA Buttons (Left side in RTL) -->
|
| 245 |
+
<div class="flex items-center gap-4"><button class="text-base font-medium transition-colors hover:text-white" style="color: var(--text-secondary);">تسجيل الدخول</button> <button id="nav-cta" class="px-6 py-2.5 rounded-xl text-base font-bold text-white gradient-accent transition-all hover:scale-105 hover:shadow-lg"> ابدأ الكتابة مجانًا </button>
|
| 246 |
+
</div>
|
| 247 |
+
</div>
|
| 248 |
+
</div>
|
| 249 |
+
</nav><!-- Home Page -->
|
| 250 |
+
<div id="page-home" class="page active"><!-- Hero Section -->
|
| 251 |
+
<section class="gradient-bg min-h-screen pt-28 pb-20 relative overflow-hidden"><!-- Background Decoration -->
|
| 252 |
+
<div class="absolute inset-0 overflow-hidden pointer-events-none">
|
| 253 |
+
<div class="absolute top-20 left-20 w-96 h-96 rounded-full opacity-20" style="background: radial-gradient(circle, var(--primary-color) 0%, transparent 70%); filter: blur(80px);"></div>
|
| 254 |
+
<div class="absolute bottom-20 right-20 w-96 h-96 rounded-full opacity-20" style="background: radial-gradient(circle, var(--secondary-color) 0%, transparent 70%); filter: blur(80px);"></div>
|
| 255 |
+
</div>
|
| 256 |
+
<div class="max-w-7xl mx-auto px-6 relative z-10">
|
| 257 |
+
<div class="grid lg:grid-cols-2 gap-16 items-center"><!-- Hero Content -->
|
| 258 |
+
<div class="text-center lg:text-right animate-fade-in">
|
| 259 |
+
<div class="inline-flex items-center gap-2 px-5 py-2 rounded-full text-sm font-bold mb-8" style="background: rgba(59, 130, 246, 0.15); color: var(--primary-color); border: 1px solid rgba(59, 130, 246, 0.3);"><span class="w-2 h-2 rounded-full animate-pulse" style="background: var(--primary-color);"></span> <span>مدعوم بالذكاء الاصطناعي</span>
|
| 260 |
+
</div>
|
| 261 |
+
<h1 id="hero-headline" class="text-5xl lg:text-7xl font-bold leading-tight mb-6" style="line-height: 1.3;">اكتب العربية<br><span class="text-gradient">بثقة واحتراف</span></h1>
|
| 262 |
+
<p id="hero-subheadline" class="text-xl lg:text-2xl leading-relaxed mb-10" style="color: var(--text-secondary); line-height: 1.9;">مساعد ذكي يصحح الإملاء والنحو وعلامات الترقيم ويُلخّص النصوص العربية بدقة عالية.</p>
|
| 263 |
+
<div class="flex flex-col sm:flex-row gap-4 justify-center lg:justify-start mb-12"><button id="hero-cta-primary" onclick="showPage('editor')" class="px-8 py-4 rounded-2xl text-lg font-bold text-white gradient-accent transition-all hover:scale-105 hover:shadow-2xl"> ابدأ الكتابة الآن </button> <button class="px-8 py-4 rounded-2xl text-lg font-bold transition-all hover:scale-105 border-2" style="border-color: rgba(255, 255, 255, 0.2); color: var(--text-color);"> شاهد العرض التوضيحي </button>
|
| 264 |
+
</div><!-- Stats -->
|
| 265 |
+
<div class="flex items-center gap-8 justify-center lg:justify-start">
|
| 266 |
+
<div class="text-center">
|
| 267 |
+
<div class="text-3xl font-bold text-gradient">
|
| 268 |
+
+١٠ مليون
|
| 269 |
+
</div>
|
| 270 |
+
<div class="text-sm mt-1" style="color: var(--text-secondary);">
|
| 271 |
+
كلمة تم تصحيحها
|
| 272 |
+
</div>
|
| 273 |
+
</div>
|
| 274 |
+
<div class="w-px h-12" style="background: rgba(255, 255, 255, 0.2);"></div>
|
| 275 |
+
<div class="text-center">
|
| 276 |
+
<div class="text-3xl font-bold text-gradient">
|
| 277 |
+
٩٩٪
|
| 278 |
+
</div>
|
| 279 |
+
<div class="text-sm mt-1" style="color: var(--text-secondary);">
|
| 280 |
+
دقة التصحيح
|
| 281 |
+
</div>
|
| 282 |
+
</div>
|
| 283 |
+
<div class="w-px h-12" style="background: rgba(255, 255, 255, 0.2);"></div>
|
| 284 |
+
<div class="text-center">
|
| 285 |
+
<div class="text-3xl font-bold text-gradient">
|
| 286 |
+
+٥٠ ألف
|
| 287 |
+
</div>
|
| 288 |
+
<div class="text-sm mt-1" style="color: var(--text-secondary);">
|
| 289 |
+
مستخدم نشط
|
| 290 |
+
</div>
|
| 291 |
+
</div>
|
| 292 |
+
</div>
|
| 293 |
+
</div><!-- Editor Mockup -->
|
| 294 |
+
<div class="relative animate-float">
|
| 295 |
+
<div class="rounded-3xl overflow-hidden shadow-2xl" style="background: var(--surface-color); border: 1px solid rgba(255, 255, 255, 0.1);"><!-- Editor Header -->
|
| 296 |
+
<div class="flex items-center justify-between p-4 border-b" style="border-color: rgba(255, 255, 255, 0.1);">
|
| 297 |
+
<div class="flex items-center gap-3">
|
| 298 |
+
<div class="w-3 h-3 rounded-full" style="background: #ef4444;"></div>
|
| 299 |
+
<div class="w-3 h-3 rounded-full" style="background: #fbbf24;"></div>
|
| 300 |
+
<div class="w-3 h-3 rounded-full" style="background: #22c55e;"></div>
|
| 301 |
+
</div><span class="text-sm" style="color: var(--text-secondary);">محرر بيان</span>
|
| 302 |
+
<div class="w-20"></div>
|
| 303 |
+
</div><!-- Mock Editor Content -->
|
| 304 |
+
<div class="p-8 editor-content text-right text-lg" dir="rtl" style="background: linear-gradient(180deg, #ffffff 0%, #fafbfc 100%); color: #1a202c; min-height: 300px;">
|
| 305 |
+
<p class="mb-4">مرحباً بكم في <span class="spelling-error">محرر بيان</span> للكتابة العربية<span class="punctuation-suggestion">.</span></p>
|
| 306 |
+
<p class="mb-4">نحن <span class="grammar-error">نساعدك</span> على كتابة نصوص عربية صحيحة وواضحة بفضل الذكاء الاصطناعي المتقدم<span class="punctuation-suggestion">.</span></p>
|
| 307 |
+
<p>جرّب المحرر الآن وشاهد كيف يمكن أن تصبح كتابتك أفضل!</p>
|
| 308 |
+
</div><!-- Mock Stats Bar -->
|
| 309 |
+
<div class="flex items-center justify-between p-4 border-t" style="border-color: rgba(255, 255, 255, 0.1);">
|
| 310 |
+
<div class="flex items-center gap-6">
|
| 311 |
+
<div class="flex items-center gap-2">
|
| 312 |
+
<div class="w-3 h-3 rounded-full" style="background: #ef4444;"></div><span class="text-sm" style="color: var(--text-secondary);">١ إملائي</span>
|
| 313 |
+
</div>
|
| 314 |
+
<div class="flex items-center gap-2">
|
| 315 |
+
<div class="w-3 h-3 rounded-full" style="background: #fbbf24;"></div><span class="text-sm" style="color: var(--text-secondary);">١ نحوي</span>
|
| 316 |
+
</div>
|
| 317 |
+
<div class="flex items-center gap-2">
|
| 318 |
+
<div class="w-3 h-3 rounded-full" style="background: #22c55e;"></div><span class="text-sm" style="color: var(--text-secondary);">٢ ترقيم</span>
|
| 319 |
+
</div>
|
| 320 |
+
</div>
|
| 321 |
+
<div class="flex items-center gap-2"><span class="text-2xl font-bold text-gradient">٩٢</span> <span class="text-sm" style="color: var(--text-secondary);">التقييم</span>
|
| 322 |
+
</div>
|
| 323 |
+
</div>
|
| 324 |
+
</div><!-- Floating Suggestion Card -->
|
| 325 |
+
<div class="absolute -bottom-6 -left-6 p-4 rounded-2xl shadow-xl animate-pulse" style="background: var(--surface-color); border: 1px solid rgba(34, 197, 94, 0.3); max-width: 280px;">
|
| 326 |
+
<div class="flex items-start gap-3">
|
| 327 |
+
<div class="w-10 h-10 rounded-xl flex items-center justify-center" style="background: rgba(34, 197, 94, 0.15);"><span style="color: #22c55e; font-size: 20px;">✓</span>
|
| 328 |
+
</div>
|
| 329 |
+
<div>
|
| 330 |
+
<div class="text-sm font-bold mb-1">
|
| 331 |
+
تصحيح تلقائي
|
| 332 |
+
</div>
|
| 333 |
+
<div class="text-xs" style="color: var(--text-secondary);">
|
| 334 |
+
تم إصلاح ٣ أخطاء في النص
|
| 335 |
+
</div>
|
| 336 |
+
</div>
|
| 337 |
+
</div>
|
| 338 |
+
</div>
|
| 339 |
+
</div>
|
| 340 |
+
</div>
|
| 341 |
+
</div>
|
| 342 |
+
</section><!-- Features Preview Section -->
|
| 343 |
+
<section class="py-24" style="background: var(--background-color);">
|
| 344 |
+
<div class="max-w-7xl mx-auto px-6">
|
| 345 |
+
<div class="text-center mb-16">
|
| 346 |
+
<h2 class="text-4xl lg:text-5xl font-bold mb-6">ميزات <span class="text-gradient">قوية ومتقدمة</span></h2>
|
| 347 |
+
<p class="text-xl max-w-3xl mx-auto" style="color: var(--text-secondary); line-height: 1.9;">كل ما تحتاجه لكتابة ن��وص عربية احترافية وخالية من الأخطاء</p>
|
| 348 |
+
</div>
|
| 349 |
+
<div class="grid md:grid-cols-2 lg:grid-cols-4 gap-6"><!-- Feature 1: Spelling -->
|
| 350 |
+
<div class="card-hover p-8 rounded-3xl" style="background: var(--surface-color); border: 1px solid rgba(255, 255, 255, 0.08);">
|
| 351 |
+
<div class="feature-icon mb-6" style="background: rgba(239, 68, 68, 0.15); color: #ef4444;">
|
| 352 |
+
✎
|
| 353 |
+
</div>
|
| 354 |
+
<h3 class="text-xl font-bold mb-3">التدقيق الإملائي الذكي</h3>
|
| 355 |
+
<p class="text-sm leading-relaxed" style="color: var(--text-secondary); line-height: 1.8;">فهم الجذور الصرفية والسياق لتصحيح الأخطاء الإملائية بدقة عالية</p>
|
| 356 |
+
</div><!-- Feature 2: Grammar -->
|
| 357 |
+
<div class="card-hover p-8 rounded-3xl" style="background: var(--surface-color); border: 1px solid rgba(255, 255, 255, 0.08);">
|
| 358 |
+
<div class="feature-icon mb-6" style="background: rgba(251, 191, 36, 0.15); color: #fbbf24;">
|
| 359 |
+
◉
|
| 360 |
+
</div>
|
| 361 |
+
<h3 class="text-xl font-bold mb-3">تصحيح القواعد النحوية</h3>
|
| 362 |
+
<p class="text-sm leading-relaxed" style="color: var(--text-secondary); line-height: 1.8;">توافق الفعل والفاعل واقتراح الإعراب الصحيح بشكل تلقائي</p>
|
| 363 |
+
</div><!-- Feature 3: Punctuation -->
|
| 364 |
+
<div class="card-hover p-8 rounded-3xl" style="background: var(--surface-color); border: 1px solid rgba(255, 255, 255, 0.08);">
|
| 365 |
+
<div class="feature-icon mb-6" style="background: rgba(34, 197, 94, 0.15); color: #22c55e;">
|
| 366 |
+
⸲
|
| 367 |
+
</div>
|
| 368 |
+
<h3 class="text-xl font-bold mb-3">تصحيح علامات الترقيم</h3>
|
| 369 |
+
<p class="text-sm leading-relaxed" style="color: var(--text-secondary); line-height: 1.8;">الفواصل والنقط وعلامات الاقتباس العربية في المكان الصحيح</p>
|
| 370 |
+
</div><!-- Feature 4: Summarization -->
|
| 371 |
+
<div class="card-hover p-8 rounded-3xl" style="background: var(--surface-color); border: 1px solid rgba(255, 255, 255, 0.08);">
|
| 372 |
+
<div class="feature-icon mb-6" style="background: rgba(139, 92, 246, 0.15); color: #8b5cf6;">
|
| 373 |
+
⊞
|
| 374 |
+
</div>
|
| 375 |
+
<h3 class="text-xl font-bold mb-3">تلخيص النصوص العربية</h3>
|
| 376 |
+
<p class="text-sm leading-relaxed" style="color: var(--text-secondary); line-height: 1.8;">الحفاظ على المعنى والأسلوب مع تقليل طول النص بذكاء</p>
|
| 377 |
+
</div>
|
| 378 |
+
</div>
|
| 379 |
+
<div class="text-center mt-12"><button onclick="showPage('features')" class="px-8 py-4 rounded-2xl text-lg font-bold border-2 transition-all hover:scale-105" style="border-color: var(--primary-color); color: var(--primary-color);"> استكشف جميع الميزات ← </button>
|
| 380 |
+
</div>
|
| 381 |
+
</div>
|
| 382 |
+
</section>
|
| 383 |
+
</div><!-- Features Page -->
|
| 384 |
+
<div id="page-features" class="page">
|
| 385 |
+
<section class="pt-32 pb-24" style="background: var(--background-color);">
|
| 386 |
+
<div class="max-w-7xl mx-auto px-6">
|
| 387 |
+
<div class="text-center mb-20">
|
| 388 |
+
<h1 class="text-5xl lg:text-6xl font-bold mb-6">ميزات <span class="text-gradient">شاملة ومتكاملة</span></h1>
|
| 389 |
+
<p class="text-xl max-w-3xl mx-auto" style="color: var(--text-secondary); line-height: 1.9;">أدوات متخصصة مصممة خصيصًا للغة العربية</p>
|
| 390 |
+
</div><!-- Feature 1: Spelling Check -->
|
| 391 |
+
<div class="grid lg:grid-cols-2 gap-16 items-center mb-32">
|
| 392 |
+
<div class="order-2 lg:order-1">
|
| 393 |
+
<div class="p-8 rounded-3xl" style="background: var(--surface-color); border: 1px solid rgba(255, 255, 255, 0.08);">
|
| 394 |
+
<div class="text-right text-xl editor-content" dir="rtl" style="color: var(--text-color); line-height: 2;">
|
| 395 |
+
<p class="mb-4">الكتابة <span class="spelling-error">الصحيحه</span> مهمة جدًا في التواصل الفعّال.</p>
|
| 396 |
+
<div class="mt-6 p-4 rounded-xl" style="background: rgba(239, 68, 68, 0.1); border-right: 4px solid #ef4444;">
|
| 397 |
+
<div class="text-sm font-bold mb-2" style="color: #ef4444;">
|
| 398 |
+
خطأ إملائي
|
| 399 |
+
</div>
|
| 400 |
+
<div class="flex items-center justify-between text-base">
|
| 401 |
+
<div><span style="text-decoration: line-through; color: var(--text-secondary);">الصحيحه</span> <span class="mx-3">←</span> <span style="color: #22c55e; font-weight: 600;">الصحيحة</span>
|
| 402 |
+
</div>
|
| 403 |
+
</div>
|
| 404 |
+
<div class="text-sm mt-3" style="color: var(--text-secondary);">
|
| 405 |
+
التاء المربوطة (ة) تُستخدم مع الصفات المؤنثة
|
| 406 |
+
</div>
|
| 407 |
+
</div>
|
| 408 |
+
</div>
|
| 409 |
+
</div>
|
| 410 |
+
</div>
|
| 411 |
+
<div class="order-1 lg:order-2 text-right">
|
| 412 |
+
<div class="feature-icon mb-6" style="background: rgba(239, 68, 68, 0.15); color: #ef4444; width: 64px; height: 64px; font-size: 32px;">
|
| 413 |
+
✎
|
| 414 |
+
</div>
|
| 415 |
+
<h2 class="text-4xl font-bold mb-6">التدقيق الإملائي الذكي</h2>
|
| 416 |
+
<p class="text-lg mb-8 leading-relaxed" style="color: var(--text-secondary); line-height: 2;">محرك ذكي يفهم الجذور الصرفية والسياق اللغوي لتصحيح الأخطاء الإملائية التي تفوتها البرامج التقليدية.</p>
|
| 417 |
+
<ul class="space-y-4">
|
| 418 |
+
<li class="flex items-center gap-4">
|
| 419 |
+
<div class="w-6 h-6 rounded-full flex items-center justify-center" style="background: rgba(34, 197, 94, 0.2);"><span style="color: #22c55e; font-size: 14px;">✓</span>
|
| 420 |
+
</div><span class="text-base">اقتراحات حسب السياق اللغوي</span></li>
|
| 421 |
+
<li class="flex items-center gap-4">
|
| 422 |
+
<div class="w-6 h-6 rounded-full flex items-center justify-center" style="background: rgba(34, 197, 94, 0.2);"><span style="color: #22c55e; font-size: 14px;">✓</span>
|
| 423 |
+
</div><span class="text-base">التعرف على الجذور الصرفية العربية</span></li>
|
| 424 |
+
<li class="flex items-center gap-4">
|
| 425 |
+
<div class="w-6 h-6 rounded-full flex items-center justify-center" style="background: rgba(34, 197, 94, 0.2);"><span style="color: #22c55e; font-size: 14px;">✓</span>
|
| 426 |
+
</div><span class="text-base">تصحيح فوري أثناء الكتابة</span></li>
|
| 427 |
+
</ul>
|
| 428 |
+
</div>
|
| 429 |
+
</div><!-- Feature 2: Grammar Check -->
|
| 430 |
+
<div class="grid lg:grid-cols-2 gap-16 items-center mb-32">
|
| 431 |
+
<div class="text-right">
|
| 432 |
+
<div class="feature-icon mb-6" style="background: rgba(251, 191, 36, 0.15); color: #fbbf24; width: 64px; height: 64px; font-size: 32px;">
|
| 433 |
+
◉
|
| 434 |
+
</div>
|
| 435 |
+
<h2 class="text-4xl font-bold mb-6">تصحيح القواعد النحوية</h2>
|
| 436 |
+
<p class="text-lg mb-8 leading-relaxed" style="color: var(--text-secondary); line-height: 2;">فهم عميق لقواعد النحو العربي بما في ذلك الإعراب وتوافق الفعل مع الفاعل والصفات.</p>
|
| 437 |
+
<ul class="space-y-4">
|
| 438 |
+
<li class="flex items-center gap-4">
|
| 439 |
+
<div class="w-6 h-6 rounded-full flex items-center justify-center" style="background: rgba(34, 197, 94, 0.2);"><span style="color: #22c55e; font-size: 14px;">✓</span>
|
| 440 |
+
</div><span class="text-base">توافق الفعل والفاعل تلقائيًا</span></li>
|
| 441 |
+
<li class="flex items-center gap-4">
|
| 442 |
+
<div class="w-6 h-6 rounded-full flex items-center justify-center" style="background: rgba(34, 197, 94, 0.2);"><span style="color: #22c55e; font-size: 14px;">✓</span>
|
| 443 |
+
</div><span class="text-base">اقتراح الإعراب الصحيح للكلمات</span></li>
|
| 444 |
+
<li class="flex items-center gap-4">
|
| 445 |
+
<div class="w-6 h-6 rounded-full flex items-center justify-center" style="background: rgba(34, 197, 94, 0.2);"><span style="color: #22c55e; font-size: 14px;">✓</span>
|
| 446 |
+
</div><span class="text-base">شرح تفصيلي لكل تصحيح</span></li>
|
| 447 |
+
</ul>
|
| 448 |
+
</div>
|
| 449 |
+
<div>
|
| 450 |
+
<div class="p-8 rounded-3xl" style="background: var(--surface-color); border: 1px solid rgba(255, 255, 255, 0.08);">
|
| 451 |
+
<div class="text-right text-xl editor-content" dir="rtl" style="color: var(--text-color); line-height: 2;">
|
| 452 |
+
<p class="mb-4">الطلاب <span class="grammar-error">ذهبوا</span> إلى المدرسة صباحًا.</p>
|
| 453 |
+
<div class="mt-6 p-4 rounded-xl" style="background: rgba(251, 191, 36, 0.1); border-right: 4px solid #fbbf24;">
|
| 454 |
+
<div class="text-sm font-bold mb-2" style="color: #fbbf24;">
|
| 455 |
+
اقتراح نحوي
|
| 456 |
+
</div>
|
| 457 |
+
<div class="text-base mb-3"><span style="color: var(--text-secondary);">يُفضل:</span> <span style="color: #22c55e; font-weight: 600; margin-right: 8px;">ذهب الطلاب</span>
|
| 458 |
+
</div>
|
| 459 |
+
<div class="text-sm" style="color: var(--text-secondary); line-height: 1.7;">
|
| 460 |
+
في اللغة العربية الفصحى، عندما يتقدم الفعل على الفاعل الجمع، يُفضل إفراد الفعل.
|
| 461 |
+
</div>
|
| 462 |
+
</div>
|
| 463 |
+
</div>
|
| 464 |
+
</div>
|
| 465 |
+
</div>
|
| 466 |
+
</div><!-- Feature 3: Punctuation -->
|
| 467 |
+
<div class="grid lg:grid-cols-2 gap-16 items-center mb-32">
|
| 468 |
+
<div class="order-2 lg:order-1">
|
| 469 |
+
<div class="p-8 rounded-3xl" style="background: var(--surface-color); border: 1px solid rgba(255, 255, 255, 0.08);">
|
| 470 |
+
<div class="text-right text-xl editor-content" dir="rtl" style="color: var(--text-color); line-height: 2;">
|
| 471 |
+
<p class="mb-4">قال المعلم<span class="punctuation-suggestion">:</span> <span class="punctuation-suggestion">«</span>الدرس مهم جدًا<span class="punctuation-suggestion">»</span><span class="punctuation-suggestion">.</span></p>
|
| 472 |
+
<div class="mt-6 p-4 rounded-xl" style="background: rgba(34, 197, 94, 0.1); border-right: 4px solid #22c55e;">
|
| 473 |
+
<div class="text-sm font-bold mb-2" style="color: #22c55e;">
|
| 474 |
+
✓ تم إصلاح علامات الترقيم
|
| 475 |
+
</div>
|
| 476 |
+
<div class="text-sm" style="color: var(--text-secondary); line-height: 1.7;">
|
| 477 |
+
• أُضيفت النقطتان بعد "قال المعلم"<br>
|
| 478 |
+
• استُخدمت علامات الاقتباس العربية «»<br>
|
| 479 |
+
• أُضيفت النقطة في نهاية الجملة
|
| 480 |
+
</div>
|
| 481 |
+
</div>
|
| 482 |
+
</div>
|
| 483 |
+
</div>
|
| 484 |
+
</div>
|
| 485 |
+
<div class="order-1 lg:order-2 text-right">
|
| 486 |
+
<div class="feature-icon mb-6" style="background: rgba(34, 197, 94, 0.15); color: #22c55e; width: 64px; height: 64px; font-size: 32px;">
|
| 487 |
+
⸲
|
| 488 |
+
</div>
|
| 489 |
+
<h2 class="text-4xl font-bold mb-6">تصحيح علامات الترقيم</h2>
|
| 490 |
+
<p class="text-lg mb-8 leading-relaxed" style="color: var(--text-secondary); line-height: 2;">كشف وتصحيح تلقائي لعلامات الترقيم العربية بما في ذلك الوضع الصحيح للفواصل والنقاط وعلامات الاقتباس.</p>
|
| 491 |
+
<ul class="space-y-4">
|
| 492 |
+
<li class="flex items-center gap-4">
|
| 493 |
+
<div class="w-6 h-6 rounded-full flex items-center justify-center" style="background: rgba(34, 197, 94, 0.2);"><span style="color: #22c55e; font-size: 14px;">✓</span>
|
| 494 |
+
</div><span class="text-base">علامات الترقيم العربية الأصيلة</span></li>
|
| 495 |
+
<li class="flex items-center gap-4">
|
| 496 |
+
<div class="w-6 h-6 rounded-full flex items-center justify-center" style="background: rgba(34, 197, 94, 0.2);"><span style="color: #22c55e; font-size: 14px;">✓</span>
|
| 497 |
+
</div><span class="text-base">تحليل بنية الجمل والفقرات</span></li>
|
| 498 |
+
<li class="flex items-center gap-4">
|
| 499 |
+
<div class="w-6 h-6 rounded-full flex items-center justify-center" style="background: rgba(34, 197, 94, 0.2);"><span style="color: #22c55e; font-size: 14px;">✓</span>
|
| 500 |
+
</div><span class="text-base">معالجة علامات الاقتباس والحوار</span></li>
|
| 501 |
+
</ul>
|
| 502 |
+
</div>
|
| 503 |
+
</div><!-- Feature 4: Summarization -->
|
| 504 |
+
<div class="grid lg:grid-cols-2 gap-16 items-center">
|
| 505 |
+
<div class="text-right">
|
| 506 |
+
<div class="feature-icon mb-6" style="background: rgba(139, 92, 246, 0.15); color: #8b5cf6; width: 64px; height: 64px; font-size: 32px;">
|
| 507 |
+
⊞
|
| 508 |
+
</div>
|
| 509 |
+
<h2 class="text-4xl font-bold mb-6">تلخيص النصوص العربية</h2>
|
| 510 |
+
<p class="text-lg mb-8 leading-relaxed" style="color: var(--text-secondary); line-height: 2;">توليد ملخصات دقيقة وموجزة للنصوص الطويلة مع الحفاظ على المعنى الأساسي والأسلوب العربي الأصيل.</p>
|
| 511 |
+
<ul class="space-y-4">
|
| 512 |
+
<li class="flex items-center gap-4">
|
| 513 |
+
<div class="w-6 h-6 rounded-full flex items-center justify-center" style="background: rgba(34, 197, 94, 0.2);"><span style="color: #22c55e; font-size: 14px;">✓</span>
|
| 514 |
+
</div><span class="text-base">طول ملخص قابل للتعديل</span></li>
|
| 515 |
+
<li class="flex items-center gap-4">
|
| 516 |
+
<div class="w-6 h-6 rounded-full flex items-center justify-center" style="background: rgba(34, 197, 94, 0.2);"><span style="color: #22c55e; font-size: 14px;">✓</span>
|
| 517 |
+
</div><span class="text-base">استخراج النقاط الرئيسية</span></li>
|
| 518 |
+
<li class="flex items-center gap-4">
|
| 519 |
+
<div class="w-6 h-6 rounded-full flex items-center justify-center" style="background: rgba(34, 197, 94, 0.2);"><span style="color: #22c55e; font-size: 14px;">✓</span>
|
| 520 |
+
</div><span class="text-base">الحفاظ على فصاحة اللغة</span></li>
|
| 521 |
+
</ul>
|
| 522 |
+
</div>
|
| 523 |
+
<div>
|
| 524 |
+
<div class="p-8 rounded-3xl" style="background: var(--surface-color); border: 1px solid rgba(255, 255, 255, 0.08);">
|
| 525 |
+
<div class="text-right" dir="rtl">
|
| 526 |
+
<div class="text-sm mb-4 p-4 rounded-xl" style="background: rgba(255, 255, 255, 0.05); color: var(--text-secondary); line-height: 1.8;">
|
| 527 |
+
النص الأصلي: ١٥٠ كلمة...<br>
|
| 528 |
+
مقالة طويلة تتحدث عن أهمية التكنولوجيا في العصر الحديث وتأثيرها على المجتمع...
|
| 529 |
+
</div>
|
| 530 |
+
<div class="flex items-center justify-center my-4">
|
| 531 |
+
<svg class="w-8 h-8" style="color: var(--secondary-color);" fill="none" stroke="currentColor" viewbox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 14l-7 7m0 0l-7-7m7 7V3" />
|
| 532 |
+
</svg>
|
| 533 |
+
</div>
|
| 534 |
+
<div class="text-lg p-4 rounded-xl editor-content" style="background: rgba(139, 92, 246, 0.1); border-right: 4px solid #8b5cf6; line-height: 2;">
|
| 535 |
+
<div class="text-sm font-bold mb-3" style="color: #8b5cf6;">
|
| 536 |
+
الملخص: ٣٠ كلمة
|
| 537 |
+
</div>
|
| 538 |
+
<p style="color: var(--text-color);">التكنولوجيا الحديثة أحدثت ثورة في حياتنا اليومية، حيث سهّلت التواصل والتعلم والعمل، مما أدى إلى تطور المجتمعات وتحسين جودة الحياة.</p>
|
| 539 |
+
</div>
|
| 540 |
+
</div>
|
| 541 |
+
</div>
|
| 542 |
+
</div>
|
| 543 |
+
</div>
|
| 544 |
+
</div>
|
| 545 |
+
</section>
|
| 546 |
+
</div><!-- Editor Page -->
|
| 547 |
+
<div id="page-editor" class="page">
|
| 548 |
+
<section class="pt-20 min-h-screen" style="background: var(--background-color);">
|
| 549 |
+
<div class="max-w-[1800px] mx-auto px-6 py-6">
|
| 550 |
+
<div class="grid lg:grid-cols-12 gap-6"><!-- Main Editor (8 columns) -->
|
| 551 |
+
<div class="lg:col-span-8">
|
| 552 |
+
<div class="rounded-3xl overflow-hidden shadow-2xl" style="background: var(--surface-color); border: 1px solid rgba(255, 255, 255, 0.08);"><!-- Editor Toolbar -->
|
| 553 |
+
<div class="flex items-center justify-between p-4 border-b" style="border-color: rgba(255, 255, 255, 0.08);">
|
| 554 |
+
<div class="flex items-center gap-3"><button id="write-tab" onclick="switchTab('write')" class="px-5 py-2 rounded-xl text-base font-bold transition-all gradient-accent text-white"> كتابة </button> <button id="summarize-tab" onclick="switchTab('summarize')" class="px-5 py-2 rounded-xl text-base font-bold transition-all" style="color: var(--text-secondary); background: transparent;"> تلخيص </button>
|
| 555 |
+
</div>
|
| 556 |
+
<div class="flex items-center gap-4"><span class="text-sm" style="color: var(--text-secondary);"> عدد الكلمات: <span id="word-count" class="font-bold">٠</span> </span>
|
| 557 |
+
</div>
|
| 558 |
+
</div><!-- Editor Area -->
|
| 559 |
+
<div id="write-area" class="p-8"><textarea id="editor-textarea" class="editor-textarea w-full rounded-2xl p-6 text-right text-xl resize-none focus:outline-none focus:ring-2" style="direction: rtl; font-family: 'Tajawal', 'Noto Kufi Arabic', sans-serif; line-height: 2.2;" placeholder="ابدأ الكتابة هنا... اكتب نصك العربي وسنساعدك في تصحيحه وتحسينه بشكل فوري" oninput="analyzeText()"></textarea>
|
| 560 |
+
</div><!-- Summarize Area -->
|
| 561 |
+
<div id="summarize-area" class="p-8" style="display: none;">
|
| 562 |
+
<div class="mb-6"><label class="block text-base font-bold mb-3">طول الملخص</label>
|
| 563 |
+
<div class="flex items-center gap-4"><span class="text-sm" style="color: var(--text-secondary);">قصير</span> <input type="range" id="summary-length" min="1" max="3" value="2" class="flex-1" onchange="updateSummaryLength()"> <span class="text-sm" style="color: var(--text-secondary);">طويل</span>
|
| 564 |
+
</div>
|
| 565 |
+
<div class="text-center mt-2"><span id="summary-length-text" class="text-sm font-bold" style="color: var(--primary-color);">متوسط</span>
|
| 566 |
+
</div>
|
| 567 |
+
</div>
|
| 568 |
+
<div class="mb-6"><label class="flex items-center gap-3 cursor-pointer"> <input type="checkbox" id="full-text-summary" class="w-5 h-5 rounded" style="accent-color: var(--primary-color);"> <span class="text-base font-bold">تلخيص النص كاملاً (وليس فقرة واحدة)</span> </label>
|
| 569 |
+
</div><button id="generate-summary-btn" onclick="generateSummary(event)" class="w-full py-4 rounded-2xl text-lg font-bold text-white gradient-accent transition-all hover:scale-105 mb-6"> توليد الملخص </button>
|
| 570 |
+
<div id="summary-preview" class="summary-preview">
|
| 571 |
+
<div class="p-6 rounded-2xl" style="background: rgba(139, 92, 246, 0.1); border: 2px solid rgba(139, 92, 246, 0.3);">
|
| 572 |
+
<div class="flex items-center justify-between mb-4">
|
| 573 |
+
<h3 class="text-lg font-bold" style="color: #8b5cf6;">الملخص</h3><button onclick="copySummary()" class="px-4 py-2 rounded-xl text-sm font-bold transition-all" style="background: rgba(139, 92, 246, 0.2); color: #8b5cf6;"> نسخ </button>
|
| 574 |
+
</div>
|
| 575 |
+
<div id="summary-text" class="text-right text-lg editor-content" dir="rtl" style="color: var(--text-color); line-height: 2.2;"><!-- Summary will appear here -->
|
| 576 |
+
</div>
|
| 577 |
+
</div>
|
| 578 |
+
</div>
|
| 579 |
+
</div><!-- Editor Footer -->
|
| 580 |
+
<div class="flex items-center justify-between p-4 border-t" style="border-color: rgba(255, 255, 255, 0.08);">
|
| 581 |
+
<div class="flex items-center gap-6">
|
| 582 |
+
<div class="flex items-center gap-2">
|
| 583 |
+
<div class="w-3 h-3 rounded-full" style="background: #ef4444;"></div><span class="text-sm" style="color: var(--text-secondary);"> <span id="spelling-count">٠</span> إملائي </span>
|
| 584 |
+
</div>
|
| 585 |
+
<div class="flex items-center gap-2">
|
| 586 |
+
<div class="w-3 h-3 rounded-full" style="background: #fbbf24;"></div><span class="text-sm" style="color: var(--text-secondary);"> <span id="grammar-count">٠</span> نحوي </span>
|
| 587 |
+
</div>
|
| 588 |
+
<div class="flex items-center gap-2">
|
| 589 |
+
<div class="w-3 h-3 rounded-full" style="background: #22c55e;"></div><span class="text-sm" style="color: var(--text-secondary);"> <span id="punctuation-count">٠</span> ترقيم </span>
|
| 590 |
+
</div>
|
| 591 |
+
</div>
|
| 592 |
+
<div class="flex items-center gap-3"><button onclick="clearEditor()" class="px-5 py-2 rounded-xl text-sm font-bold border transition-all hover:scale-105" style="border-color: rgba(255, 255, 255, 0.2); color: var(--text-secondary);"> مسح الكل </button> <button onclick="copyText()" class="px-5 py-2 rounded-xl text-sm font-bold gradient-accent text-white transition-all hover:scale-105"> نسخ النص </button>
|
| 593 |
+
</div>
|
| 594 |
+
</div>
|
| 595 |
+
</div>
|
| 596 |
+
</div><!-- Sidebar (4 columns) -->
|
| 597 |
+
<div class="lg:col-span-4 space-y-6"><!-- Score Card -->
|
| 598 |
+
<div class="p-6 rounded-3xl" style="background: var(--surface-color); border: 1px solid rgba(255, 255, 255, 0.08);">
|
| 599 |
+
<h3 class="text-xl font-bold mb-4 text-right">تقييم الكتابة</h3>
|
| 600 |
+
<div class="relative w-40 h-40 mx-auto mb-4">
|
| 601 |
+
<svg class="w-full h-full transform -rotate-90"><circle cx="80" cy="80" r="70" fill="none" stroke="rgba(255, 255, 255, 0.08)" stroke-width="10" /> <circle id="score-circle" cx="80" cy="80" r="70" fill="none" stroke="url(#scoreGradient)" stroke-width="10" stroke-linecap="round" stroke-dasharray="440" stroke-dashoffset="440" class="score-circle" /> <defs>
|
| 602 |
+
<lineargradient id="scoreGradient" x1="0%" y1="0%" x2="100%" y2="0%">
|
| 603 |
+
<stop offset="0%" style="stop-color: var(--primary-color);" />
|
| 604 |
+
<stop offset="100%" style="stop-color: var(--secondary-color);" />
|
| 605 |
+
</lineargradient>
|
| 606 |
+
</defs>
|
| 607 |
+
</svg>
|
| 608 |
+
<div class="absolute inset-0 flex items-center justify-center"><span id="score-value" class="text-4xl font-bold">--</span>
|
| 609 |
+
</div>
|
| 610 |
+
</div>
|
| 611 |
+
<p class="text-center text-sm leading-relaxed" style="color: var(--text-secondary); line-height: 1.8;">ابدأ الكتابة لرؤية تقييمك<br><span class="text-xs">تحسين القواعد يرفع التقييم</span></p>
|
| 612 |
+
</div><!-- Suggestions List -->
|
| 613 |
+
<div class="p-6 rounded-3xl" style="background: var(--surface-color); border: 1px solid rgba(255, 255, 255, 0.08);">
|
| 614 |
+
<h3 class="text-xl font-bold mb-4 text-right">الاقتراحات</h3>
|
| 615 |
+
<div id="suggestions-list" class="space-y-3 max-h-[500px] overflow-y-auto">
|
| 616 |
+
<div class="text-center py-12" style="color: var(--text-secondary);">
|
| 617 |
+
<svg class="w-16 h-16 mx-auto mb-4 opacity-30" fill="none" stroke="currentColor" viewbox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
| 618 |
+
</svg>
|
| 619 |
+
<p class="text-base">لا توجد اقتراحات بعد</p>
|
| 620 |
+
<p class="text-sm mt-2">ابدأ الكتابة لتلقي الملاحظات</p>
|
| 621 |
+
</div>
|
| 622 |
+
</div>
|
| 623 |
+
</div>
|
| 624 |
+
</div>
|
| 625 |
+
</div>
|
| 626 |
+
</div>
|
| 627 |
+
</section>
|
| 628 |
+
</div><!-- Pricing Page -->
|
| 629 |
+
<div id="page-pricing" class="page">
|
| 630 |
+
<section class="pt-32 pb-24" style="background: var(--background-color);">
|
| 631 |
+
<div class="max-w-7xl mx-auto px-6">
|
| 632 |
+
<div class="text-center mb-16">
|
| 633 |
+
<h1 class="text-5xl lg:text-6xl font-bold mb-6">خطط <span class="text-gradient">واضحة ومرنة</span></h1>
|
| 634 |
+
<p class="text-xl max-w-3xl mx-auto" style="color: var(--text-secondary); line-height: 1.9;">اختر الخطة المناسبة لك. يمكنك الترقية أو التخفيض في أي وقت.</p>
|
| 635 |
+
</div>
|
| 636 |
+
<div class="grid md:grid-cols-3 gap-8 max-w-6xl mx-auto"><!-- Free Plan -->
|
| 637 |
+
<div class="p-8 rounded-3xl transition-all hover:scale-105" style="background: var(--surface-color); border: 1px solid rgba(255, 255, 255, 0.08);">
|
| 638 |
+
<div class="text-center mb-8">
|
| 639 |
+
<h3 class="text-3xl font-bold mb-2">مجاني</h3>
|
| 640 |
+
<p class="text-base mb-6" style="color: var(--text-secondary);">للبدء والتجربة</p>
|
| 641 |
+
<div class="text-6xl font-bold mb-2">
|
| 642 |
+
٠
|
| 643 |
+
</div>
|
| 644 |
+
<p class="text-base" style="color: var(--text-secondary);">مجاني للأبد</p>
|
| 645 |
+
</div>
|
| 646 |
+
<ul class="space-y-4 mb-8">
|
| 647 |
+
<li class="flex items-center gap-3">
|
| 648 |
+
<svg class="w-5 h-5" style="color: #22c55e;" fill="none" stroke="currentColor" viewbox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
|
| 649 |
+
</svg><span class="text-base">تدقيق إملائي أساسي</span></li>
|
| 650 |
+
<li class="flex items-center gap-3">
|
| 651 |
+
<svg class="w-5 h-5" style="color: #22c55e;" fill="none" stroke="currentColor" viewbox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
|
| 652 |
+
</svg><span class="text-base">٥٠٠ كلمة يوميًا</span></li>
|
| 653 |
+
<li class="flex items-center gap-3">
|
| 654 |
+
<svg class="w-5 h-5" style="color: #22c55e;" fill="none" stroke="currentColor" viewbox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
|
| 655 |
+
</svg><span class="text-base">محرر ويب</span></li>
|
| 656 |
+
<li class="flex items-center gap-3">
|
| 657 |
+
<svg class="w-5 h-5" style="color: rgba(241, 245, 249, 0.2);" fill="none" stroke="currentColor" viewbox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
|
| 658 |
+
</svg><span class="text-base" style="color: var(--text-secondary);">اقتراحات نحوية</span></li>
|
| 659 |
+
<li class="flex items-center gap-3">
|
| 660 |
+
<svg class="w-5 h-5" style="color: rgba(241, 245, 249, 0.2);" fill="none" stroke="currentColor" viewbox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
|
| 661 |
+
</svg><span class="text-base" style="color: var(--text-secondary);">تلخيص النصوص</span></li>
|
| 662 |
+
</ul><button class="w-full py-4 rounded-2xl text-lg font-bold border-2 transition-all hover:scale-105" style="border-color: rgba(255, 255, 255, 0.2); color: var(--text-color);"> ابدأ مجانًا </button>
|
| 663 |
+
</div><!-- Pro Plan (Most Popular) -->
|
| 664 |
+
<div class="p-8 rounded-3xl transition-all hover:scale-105 relative shadow-2xl" style="background: linear-gradient(165deg, var(--surface-color) 0%, rgba(59, 130, 246, 0.1) 100%); border: 2px solid var(--primary-color);">
|
| 665 |
+
<div class="pricing-badge gradient-accent text-white">
|
| 666 |
+
الأكثر استخدامًا
|
| 667 |
+
</div>
|
| 668 |
+
<div class="text-center mb-8">
|
| 669 |
+
<h3 class="text-3xl font-bold mb-2">احترافي</h3>
|
| 670 |
+
<p class="text-base mb-6" style="color: var(--text-secondary);">للكُتّاب الجادين</p>
|
| 671 |
+
<div class="flex items-center justify-center gap-2"><span class="text-6xl font-bold">٩</span>
|
| 672 |
+
<div class="text-right">
|
| 673 |
+
<div class="text-lg font-bold">
|
| 674 |
+
دولار
|
| 675 |
+
</div>
|
| 676 |
+
<div class="text-sm" style="color: var(--text-secondary);">
|
| 677 |
+
شهريًا
|
| 678 |
+
</div>
|
| 679 |
+
</div>
|
| 680 |
+
</div>
|
| 681 |
+
</div>
|
| 682 |
+
<ul class="space-y-4 mb-8">
|
| 683 |
+
<li class="flex items-center gap-3">
|
| 684 |
+
<svg class="w-5 h-5" style="color: #22c55e;" fill="none" stroke="currentColor" viewbox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
|
| 685 |
+
</svg><span class="text-base">تدقيق إملائي ونحوي متقدم</span></li>
|
| 686 |
+
<li class="flex items-center gap-3">
|
| 687 |
+
<svg class="w-5 h-5" style="color: #22c55e;" fill="none" stroke="currentColor" viewbox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
|
| 688 |
+
</svg><span class="text-base">كلمات غير محدودة</span></li>
|
| 689 |
+
<li class="flex items-center gap-3">
|
| 690 |
+
<svg class="w-5 h-5" style="color: #22c55e;" fill="none" stroke="currentColor" viewbox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
|
| 691 |
+
</svg><span class="text-base">تصحيح علامات الترقيم</span></li>
|
| 692 |
+
<li class="flex items-center gap-3">
|
| 693 |
+
<svg class="w-5 h-5" style="color: #22c55e;" fill="none" stroke="currentColor" viewbox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
|
| 694 |
+
</svg><span class="text-base">تلخيص النصوص بالذكاء الاصطناعي</span></li>
|
| 695 |
+
<li class="flex items-center gap-3">
|
| 696 |
+
<svg class="w-5 h-5" style="color: #22c55e;" fill="none" stroke="currentColor" viewbox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
|
| 697 |
+
</svg><span class="text-base">إضافة المتصفح</span></li>
|
| 698 |
+
</ul><button class="w-full py-4 rounded-2xl text-lg font-bold text-white gradient-accent transition-all hover:scale-105 hover:shadow-2xl"> الترقية للاحترافي </button>
|
| 699 |
+
</div><!-- Enterprise Plan -->
|
| 700 |
+
<div class="p-8 rounded-3xl transition-all hover:scale-105" style="background: var(--surface-color); border: 1px solid rgba(255, 255, 255, 0.08);">
|
| 701 |
+
<div class="text-center mb-8">
|
| 702 |
+
<h3 class="text-3xl font-bold mb-2">مؤسسات</h3>
|
| 703 |
+
<p class="text-base mb-6" style="color: var(--text-secondary);">للفرق والمنظمات</p>
|
| 704 |
+
<div class="flex items-center justify-center gap-2"><span class="text-6xl font-bold">٢٩</span>
|
| 705 |
+
<div class="text-right">
|
| 706 |
+
<div class="text-lg font-bold">
|
| 707 |
+
دولار
|
| 708 |
+
</div>
|
| 709 |
+
<div class="text-sm" style="color: var(--text-secondary);">
|
| 710 |
+
لكل مستخدم/شهر
|
| 711 |
+
</div>
|
| 712 |
+
</div>
|
| 713 |
+
</div>
|
| 714 |
+
</div>
|
| 715 |
+
<ul class="space-y-4 mb-8">
|
| 716 |
+
<li class="flex items-center gap-3">
|
| 717 |
+
<svg class="w-5 h-5" style="color: #22c55e;" fill="none" stroke="currentColor" viewbox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
|
| 718 |
+
</svg><span class="text-base">كل ميزات الاحترافي</span></li>
|
| 719 |
+
<li class="flex items-center gap-3">
|
| 720 |
+
<svg class="w-5 h-5" style="color: #22c55e;" fill="none" stroke="currentColor" viewbox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
|
| 721 |
+
</svg><span class="text-base">إدارة الفرق</span></li>
|
| 722 |
+
<li class="flex items-center gap-3">
|
| 723 |
+
<svg class="w-5 h-5" style="color: #22c55e;" fill="none" stroke="currentColor" viewbox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
|
| 724 |
+
</svg><span class="text-base">واجهة برمجية (API)</span></li>
|
| 725 |
+
<li class="flex items-center gap-3">
|
| 726 |
+
<svg class="w-5 h-5" style="color: #22c55e;" fill="none" stroke="currentColor" viewbox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
|
| 727 |
+
</svg><span class="text-base">تكامل مخصص</span></li>
|
| 728 |
+
<li class="flex items-center gap-3">
|
| 729 |
+
<svg class="w-5 h-5" style="color: #22c55e;" fill="none" stroke="currentColor" viewbox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7" />
|
| 730 |
+
</svg><span class="text-base">دعم فني ذو أولوية</span></li>
|
| 731 |
+
</ul><button class="w-full py-4 rounded-2xl text-lg font-bold border-2 transition-all hover:scale-105" style="border-color: rgba(255, 255, 255, 0.2); color: var(--text-color);"> تواصل مع المبيعات </button>
|
| 732 |
+
</div>
|
| 733 |
+
</div>
|
| 734 |
+
</div>
|
| 735 |
+
</section>
|
| 736 |
+
</div><!-- Footer -->
|
| 737 |
+
<footer class="py-12 border-t" style="background: var(--background-color); border-color: rgba(255, 255, 255, 0.08);">
|
| 738 |
+
<div class="max-w-7xl mx-auto px-6">
|
| 739 |
+
<div class="flex flex-col md:flex-row items-center justify-between gap-6">
|
| 740 |
+
<div class="flex items-center gap-3">
|
| 741 |
+
<div class="w-10 h-10 rounded-xl flex items-center justify-center gradient-accent"><span class="text-white text-xl font-bold">ب</span>
|
| 742 |
+
</div><span id="footer-brand" class="text-2xl font-bold text-gradient">بيان</span>
|
| 743 |
+
</div>
|
| 744 |
+
<div class="flex items-center gap-8"><a href="#" class="text-base transition-colors hover:text-white" style="color: var(--text-secondary);">الخصوصية</a> <a href="#" class="text-base transition-colors hover:text-white" style="color: var(--text-secondary);">الشروط</a> <a href="#" class="text-base transition-colors hover:text-white" style="color: var(--text-secondary);">تواصل معنا</a>
|
| 745 |
+
</div>
|
| 746 |
+
<p class="text-base" style="color: var(--text-secondary);">© ٢٠٢٤ بيان. جميع الحقوق محفوظة.</p>
|
| 747 |
+
</div>
|
| 748 |
+
</div>
|
| 749 |
+
</footer>
|
| 750 |
+
</div>
|
| 751 |
+
<script>
|
| 752 |
+
// Default configuration
|
| 753 |
+
const defaultConfig = {
|
| 754 |
+
brand_name: 'بيان',
|
| 755 |
+
hero_headline: 'اكتب العربية بثقة واحتراف',
|
| 756 |
+
hero_subheadline: 'مساعد ذكي يصحح الإملاء والنحو وعلامات الترقيم ويُلخّص النصوص العربية بدقة عالية.',
|
| 757 |
+
cta_primary: 'ابدأ الكتابة الآن',
|
| 758 |
+
primary_color: '#3b82f6',
|
| 759 |
+
secondary_color: '#8b5cf6',
|
| 760 |
+
text_color: '#f1f5f9',
|
| 761 |
+
background_color: '#0f172a',
|
| 762 |
+
surface_color: '#1e293b',
|
| 763 |
+
font_family: 'Tajawal',
|
| 764 |
+
font_size: 16
|
| 765 |
+
};
|
| 766 |
+
|
| 767 |
+
let config = { ...defaultConfig };
|
| 768 |
+
|
| 769 |
+
// Page navigation
|
| 770 |
+
function showPage(pageId) {
|
| 771 |
+
document.querySelectorAll('.page').forEach(page => page.classList.remove('active'));
|
| 772 |
+
document.getElementById('page-' + pageId).classList.add('active');
|
| 773 |
+
|
| 774 |
+
document.querySelectorAll('.nav-link').forEach(link => {
|
| 775 |
+
link.classList.remove('active');
|
| 776 |
+
link.style.color = 'var(--text-secondary)';
|
| 777 |
+
});
|
| 778 |
+
|
| 779 |
+
const activeLink = document.querySelector(`[data-page="${pageId}"]`);
|
| 780 |
+
if (activeLink) {
|
| 781 |
+
activeLink.classList.add('active');
|
| 782 |
+
activeLink.style.color = 'var(--text-color)';
|
| 783 |
+
}
|
| 784 |
+
|
| 785 |
+
window.scrollTo(0, 0);
|
| 786 |
+
}
|
| 787 |
+
|
| 788 |
+
// Tab switching in editor
|
| 789 |
+
function switchTab(tab) {
|
| 790 |
+
const writeTab = document.getElementById('write-tab');
|
| 791 |
+
const summarizeTab = document.getElementById('summarize-tab');
|
| 792 |
+
const writeArea = document.getElementById('write-area');
|
| 793 |
+
const summarizeArea = document.getElementById('summarize-area');
|
| 794 |
+
|
| 795 |
+
if (tab === 'write') {
|
| 796 |
+
writeTab.className = 'px-5 py-2 rounded-xl text-base font-bold transition-all gradient-accent text-white';
|
| 797 |
+
summarizeTab.className = 'px-5 py-2 rounded-xl text-base font-bold transition-all';
|
| 798 |
+
summarizeTab.style.color = 'var(--text-secondary)';
|
| 799 |
+
summarizeTab.style.background = 'transparent';
|
| 800 |
+
writeArea.style.display = 'block';
|
| 801 |
+
summarizeArea.style.display = 'none';
|
| 802 |
+
} else {
|
| 803 |
+
summarizeTab.className = 'px-5 py-2 rounded-xl text-base font-bold transition-all gradient-accent text-white';
|
| 804 |
+
writeTab.className = 'px-5 py-2 rounded-xl text-base font-bold transition-all';
|
| 805 |
+
writeTab.style.color = 'var(--text-secondary)';
|
| 806 |
+
writeTab.style.background = 'transparent';
|
| 807 |
+
writeArea.style.display = 'none';
|
| 808 |
+
summarizeArea.style.display = 'block';
|
| 809 |
+
}
|
| 810 |
+
}
|
| 811 |
+
|
| 812 |
+
// Editor text analysis
|
| 813 |
+
function analyzeText() {
|
| 814 |
+
const textarea = document.getElementById('editor-textarea');
|
| 815 |
+
const text = textarea.value;
|
| 816 |
+
const words = text.trim() ? text.trim().split(/\s+/).length : 0;
|
| 817 |
+
|
| 818 |
+
document.getElementById('word-count').textContent = words.toLocaleString('ar-EG');
|
| 819 |
+
|
| 820 |
+
if (words > 0) {
|
| 821 |
+
const spelling = Math.floor(Math.random() * 3);
|
| 822 |
+
const grammar = Math.floor(Math.random() * 2);
|
| 823 |
+
const punctuation = Math.floor(Math.random() * 2);
|
| 824 |
+
|
| 825 |
+
document.getElementById('spelling-count').textContent = spelling.toLocaleString('ar-EG');
|
| 826 |
+
document.getElementById('grammar-count').textContent = grammar.toLocaleString('ar-EG');
|
| 827 |
+
document.getElementById('punctuation-count').textContent = punctuation.toLocaleString('ar-EG');
|
| 828 |
+
|
| 829 |
+
const score = Math.max(70, 100 - (spelling * 5) - (grammar * 8) - (punctuation * 3));
|
| 830 |
+
const circle = document.getElementById('score-circle');
|
| 831 |
+
const offset = 440 - (440 * score / 100);
|
| 832 |
+
circle.style.strokeDashoffset = offset;
|
| 833 |
+
document.getElementById('score-value').textContent = score.toLocaleString('ar-EG');
|
| 834 |
+
|
| 835 |
+
updateSuggestions(spelling, grammar, punctuation);
|
| 836 |
+
} else {
|
| 837 |
+
document.getElementById('score-circle').style.strokeDashoffset = 440;
|
| 838 |
+
document.getElementById('score-value').textContent = '--';
|
| 839 |
+
document.getElementById('spelling-count').textContent = '٠';
|
| 840 |
+
document.getElementById('grammar-count').textContent = '٠';
|
| 841 |
+
document.getElementById('punctuation-count').textContent = '٠';
|
| 842 |
+
resetSuggestions();
|
| 843 |
+
}
|
| 844 |
+
}
|
| 845 |
+
|
| 846 |
+
function updateSuggestions(spelling, grammar, punctuation) {
|
| 847 |
+
const container = document.getElementById('suggestions-list');
|
| 848 |
+
let html = '';
|
| 849 |
+
|
| 850 |
+
if (spelling > 0) {
|
| 851 |
+
html += `
|
| 852 |
+
<div class="suggestion-item p-4 rounded-xl" style="background: rgba(239, 68, 68, 0.1); border-right: 3px solid #ef4444;">
|
| 853 |
+
<div class="flex items-start gap-3">
|
| 854 |
+
<div class="w-10 h-10 rounded-xl flex items-center justify-center" style="background: rgba(239, 68, 68, 0.2);">
|
| 855 |
+
<span style="color: #ef4444; font-size: 18px;">✎</span>
|
| 856 |
+
</div>
|
| 857 |
+
<div class="flex-1 text-right">
|
| 858 |
+
<div class="text-base font-bold mb-1">خطأ إملائي</div>
|
| 859 |
+
<div class="text-sm" style="color: var(--text-secondary);">انقر للتصحيح</div>
|
| 860 |
+
</div>
|
| 861 |
+
</div>
|
| 862 |
+
</div>
|
| 863 |
+
`;
|
| 864 |
+
}
|
| 865 |
+
|
| 866 |
+
if (grammar > 0) {
|
| 867 |
+
html += `
|
| 868 |
+
<div class="suggestion-item p-4 rounded-xl" style="background: rgba(251, 191, 36, 0.1); border-right: 3px solid #fbbf24;">
|
| 869 |
+
<div class="flex items-start gap-3">
|
| 870 |
+
<div class="w-10 h-10 rounded-xl flex items-center justify-center" style="background: rgba(251, 191, 36, 0.2);">
|
| 871 |
+
<span style="color: #fbbf24; font-size: 18px;">◉</span>
|
| 872 |
+
</div>
|
| 873 |
+
<div class="flex-1 text-right">
|
| 874 |
+
<div class="text-base font-bold mb-1">اقتراح نحوي</div>
|
| 875 |
+
<div class="text-sm" style="color: var(--text-secondary);">يُنصح بالمراجعة</div>
|
| 876 |
+
</div>
|
| 877 |
+
</div>
|
| 878 |
+
</div>
|
| 879 |
+
`;
|
| 880 |
+
}
|
| 881 |
+
|
| 882 |
+
if (punctuation > 0) {
|
| 883 |
+
html += `
|
| 884 |
+
<div class="suggestion-item p-4 rounded-xl" style="background: rgba(34, 197, 94, 0.1); border-right: 3px solid #22c55e;">
|
| 885 |
+
<div class="flex items-start gap-3">
|
| 886 |
+
<div class="w-10 h-10 rounded-xl flex items-center justify-center" style="background: rgba(34, 197, 94, 0.2);">
|
| 887 |
+
<span style="color: #22c55e; font-size: 18px;">⸲</span>
|
| 888 |
+
</div>
|
| 889 |
+
<div class="flex-1 text-right">
|
| 890 |
+
<div class="text-base font-bold mb-1">علامات الترقيم</div>
|
| 891 |
+
<div class="text-sm" style="color: var(--text-secondary);">تصحيح تلقائي متاح</div>
|
| 892 |
+
</div>
|
| 893 |
+
</div>
|
| 894 |
+
</div>
|
| 895 |
+
`;
|
| 896 |
+
}
|
| 897 |
+
|
| 898 |
+
if (!html) {
|
| 899 |
+
html = `
|
| 900 |
+
<div class="text-center py-8">
|
| 901 |
+
<svg class="w-12 h-12 mx-auto mb-3" style="color: #22c55e;" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
| 902 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
|
| 903 |
+
</svg>
|
| 904 |
+
<p class="text-base font-bold" style="color: #22c55e;">ممتاز!</p>
|
| 905 |
+
<p class="text-sm mt-2" style="color: var(--text-secondary);">لم يتم العثور على أخطاء</p>
|
| 906 |
+
</div>
|
| 907 |
+
`;
|
| 908 |
+
}
|
| 909 |
+
|
| 910 |
+
container.innerHTML = html;
|
| 911 |
+
}
|
| 912 |
+
|
| 913 |
+
function resetSuggestions() {
|
| 914 |
+
document.getElementById('suggestions-list').innerHTML = `
|
| 915 |
+
<div class="text-center py-12" style="color: var(--text-secondary);">
|
| 916 |
+
<svg class="w-16 h-16 mx-auto mb-4 opacity-30" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
| 917 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
|
| 918 |
+
</svg>
|
| 919 |
+
<p class="text-base">لا توجد اقتراحات بعد</p>
|
| 920 |
+
<p class="text-sm mt-2">ابدأ الكتابة لتلقي الملاحظات</p>
|
| 921 |
+
</div>
|
| 922 |
+
`;
|
| 923 |
+
}
|
| 924 |
+
|
| 925 |
+
function clearEditor() {
|
| 926 |
+
document.getElementById('editor-textarea').value = '';
|
| 927 |
+
analyzeText();
|
| 928 |
+
}
|
| 929 |
+
|
| 930 |
+
function copyText() {
|
| 931 |
+
const textarea = document.getElementById('editor-textarea');
|
| 932 |
+
textarea.select();
|
| 933 |
+
document.execCommand('copy');
|
| 934 |
+
|
| 935 |
+
const btn = event.target;
|
| 936 |
+
const originalText = btn.textContent;
|
| 937 |
+
btn.textContent = 'تم النسخ!';
|
| 938 |
+
setTimeout(() => btn.textContent = originalText, 2000);
|
| 939 |
+
}
|
| 940 |
+
|
| 941 |
+
// Summarization functions
|
| 942 |
+
function updateSummaryLength() {
|
| 943 |
+
const value = document.getElementById('summary-length').value;
|
| 944 |
+
const text = ['قصير', 'متوسط', 'طويل'][value - 1];
|
| 945 |
+
document.getElementById('summary-length-text').textContent = text;
|
| 946 |
+
}
|
| 947 |
+
|
| 948 |
+
async function generateSummary(event) {
|
| 949 |
+
const textarea = document.getElementById('editor-textarea');
|
| 950 |
+
const text = textarea.value.trim();
|
| 951 |
+
|
| 952 |
+
if (!text) {
|
| 953 |
+
const summaryText = document.getElementById('summary-text');
|
| 954 |
+
summaryText.innerHTML = '<p style="color: var(--text-secondary); text-align: center;">الرجاء كتابة نص في المحرر أولاً</p>';
|
| 955 |
+
document.getElementById('summary-preview').classList.add('show');
|
| 956 |
+
return;
|
| 957 |
+
}
|
| 958 |
+
|
| 959 |
+
const lengthValue = document.getElementById('summary-length').value;
|
| 960 |
+
const isFullText = document.getElementById('full-text-summary').checked;
|
| 961 |
+
const generateButton = event ? event.target : document.getElementById('generate-summary-btn');
|
| 962 |
+
const summaryText = document.getElementById('summary-text');
|
| 963 |
+
const summaryPreview = document.getElementById('summary-preview');
|
| 964 |
+
|
| 965 |
+
// Show loading state
|
| 966 |
+
const originalButtonText = generateButton.textContent;
|
| 967 |
+
generateButton.textContent = 'جاري التوليد...';
|
| 968 |
+
generateButton.disabled = true;
|
| 969 |
+
summaryText.innerHTML = '<div style="text-align: center; padding: 20px;"><div style="display: inline-block; width: 40px; height: 40px; border: 4px solid rgba(139, 92, 246, 0.3); border-top-color: #8b5cf6; border-radius: 50%; animation: spin 1s linear infinite;"></div><p style="margin-top: 16px; color: var(--text-secondary);">جاري توليد الملخص...</p></div>';
|
| 970 |
+
summaryPreview.classList.add('show');
|
| 971 |
+
|
| 972 |
+
// Add spin animation if not exists
|
| 973 |
+
if (!document.getElementById('spin-animation')) {
|
| 974 |
+
const style = document.createElement('style');
|
| 975 |
+
style.id = 'spin-animation';
|
| 976 |
+
style.textContent = '@keyframes spin { to { transform: rotate(360deg); } }';
|
| 977 |
+
document.head.appendChild(style);
|
| 978 |
+
}
|
| 979 |
+
|
| 980 |
+
try {
|
| 981 |
+
// Call API
|
| 982 |
+
const response = await fetch('/api/summarize', {
|
| 983 |
+
method: 'POST',
|
| 984 |
+
headers: {
|
| 985 |
+
'Content-Type': 'application/json',
|
| 986 |
+
},
|
| 987 |
+
body: JSON.stringify({
|
| 988 |
+
text: text,
|
| 989 |
+
length: parseInt(lengthValue),
|
| 990 |
+
full_text: isFullText
|
| 991 |
+
})
|
| 992 |
+
});
|
| 993 |
+
|
| 994 |
+
const data = await response.json();
|
| 995 |
+
|
| 996 |
+
if (!response.ok) {
|
| 997 |
+
throw new Error(data.error || 'حدث خطأ أثناء توليد الملخص');
|
| 998 |
+
}
|
| 999 |
+
|
| 1000 |
+
if (data.status === 'success' && data.summary) {
|
| 1001 |
+
summaryText.innerHTML = `<p>${data.summary}</p>`;
|
| 1002 |
+
} else {
|
| 1003 |
+
throw new Error(data.error || 'لم يتم توليد ملخص');
|
| 1004 |
+
}
|
| 1005 |
+
|
| 1006 |
+
} catch (error) {
|
| 1007 |
+
console.error('Error generating summary:', error);
|
| 1008 |
+
summaryText.innerHTML = `
|
| 1009 |
+
<div style="text-align: center; padding: 20px;">
|
| 1010 |
+
<p style="color: #ef4444; margin-bottom: 12px;">⚠️ حدث خطأ</p>
|
| 1011 |
+
<p style="color: var(--text-secondary); font-size: 14px;">${error.message || 'تعذر توليد الملخص. يرجى المحاولة مرة أخرى.'}</p>
|
| 1012 |
+
<p style="color: var(--text-secondary); font-size: 12px; margin-top: 8px;">تأكد من أن الخادم يعمل وأن النموذج محمّل بشكل صحيح.</p>
|
| 1013 |
+
</div>
|
| 1014 |
+
`;
|
| 1015 |
+
} finally {
|
| 1016 |
+
// Restore button state
|
| 1017 |
+
generateButton.textContent = originalButtonText;
|
| 1018 |
+
generateButton.disabled = false;
|
| 1019 |
+
}
|
| 1020 |
+
}
|
| 1021 |
+
|
| 1022 |
+
function copySummary() {
|
| 1023 |
+
const summaryText = document.getElementById('summary-text').innerText;
|
| 1024 |
+
const tempTextarea = document.createElement('textarea');
|
| 1025 |
+
tempTextarea.value = summaryText;
|
| 1026 |
+
document.body.appendChild(tempTextarea);
|
| 1027 |
+
tempTextarea.select();
|
| 1028 |
+
document.execCommand('copy');
|
| 1029 |
+
document.body.removeChild(tempTextarea);
|
| 1030 |
+
|
| 1031 |
+
const btn = event.target;
|
| 1032 |
+
const originalText = btn.textContent;
|
| 1033 |
+
btn.textContent = 'تم النسخ!';
|
| 1034 |
+
setTimeout(() => btn.textContent = originalText, 2000);
|
| 1035 |
+
}
|
| 1036 |
+
|
| 1037 |
+
// Element SDK Integration
|
| 1038 |
+
async function onConfigChange(cfg) {
|
| 1039 |
+
config = { ...defaultConfig, ...cfg };
|
| 1040 |
+
|
| 1041 |
+
document.documentElement.style.setProperty('--primary-color', config.primary_color || defaultConfig.primary_color);
|
| 1042 |
+
document.documentElement.style.setProperty('--secondary-color', config.secondary_color || defaultConfig.secondary_color);
|
| 1043 |
+
document.documentElement.style.setProperty('--text-color', config.text_color || defaultConfig.text_color);
|
| 1044 |
+
document.documentElement.style.setProperty('--background-color', config.background_color || defaultConfig.background_color);
|
| 1045 |
+
document.documentElement.style.setProperty('--surface-color', config.surface_color || defaultConfig.surface_color);
|
| 1046 |
+
|
| 1047 |
+
const brandName = config.brand_name || defaultConfig.brand_name;
|
| 1048 |
+
const navBrand = document.getElementById('nav-brand');
|
| 1049 |
+
const footerBrand = document.getElementById('footer-brand');
|
| 1050 |
+
if (navBrand) navBrand.textContent = brandName;
|
| 1051 |
+
if (footerBrand) footerBrand.textContent = brandName;
|
| 1052 |
+
|
| 1053 |
+
const heroHeadline = config.hero_headline || defaultConfig.hero_headline;
|
| 1054 |
+
const headlineEl = document.getElementById('hero-headline');
|
| 1055 |
+
if (headlineEl) {
|
| 1056 |
+
const parts = heroHeadline.split('\n');
|
| 1057 |
+
if (parts.length > 1) {
|
| 1058 |
+
headlineEl.innerHTML = parts[0] + '<br/><span class="text-gradient">' + parts[1] + '</span>';
|
| 1059 |
+
} else {
|
| 1060 |
+
headlineEl.innerHTML = heroHeadline.replace('بثقة واحتراف', '<span class="text-gradient">بثقة واحتراف</span>');
|
| 1061 |
+
}
|
| 1062 |
+
}
|
| 1063 |
+
|
| 1064 |
+
const heroSubheadline = document.getElementById('hero-subheadline');
|
| 1065 |
+
if (heroSubheadline) {
|
| 1066 |
+
heroSubheadline.textContent = config.hero_subheadline || defaultConfig.hero_subheadline;
|
| 1067 |
+
}
|
| 1068 |
+
|
| 1069 |
+
const ctaPrimary = config.cta_primary || defaultConfig.cta_primary;
|
| 1070 |
+
const navCta = document.getElementById('nav-cta');
|
| 1071 |
+
const heroCta = document.getElementById('hero-cta-primary');
|
| 1072 |
+
if (navCta) navCta.textContent = ctaPrimary;
|
| 1073 |
+
if (heroCta) heroCta.textContent = ctaPrimary;
|
| 1074 |
+
|
| 1075 |
+
const fontFamily = config.font_family || defaultConfig.font_family;
|
| 1076 |
+
const fontSize = config.font_size || defaultConfig.font_size;
|
| 1077 |
+
document.body.style.fontFamily = `${fontFamily}, 'Noto Kufi Arabic', sans-serif`;
|
| 1078 |
+
document.body.style.fontSize = `${fontSize}px`;
|
| 1079 |
+
}
|
| 1080 |
+
|
| 1081 |
+
function mapToCapabilities(cfg) {
|
| 1082 |
+
return {
|
| 1083 |
+
recolorables: [
|
| 1084 |
+
{
|
| 1085 |
+
get: () => cfg.background_color || defaultConfig.background_color,
|
| 1086 |
+
set: (value) => { cfg.background_color = value; window.elementSdk.setConfig({ background_color: value }); }
|
| 1087 |
+
},
|
| 1088 |
+
{
|
| 1089 |
+
get: () => cfg.surface_color || defaultConfig.surface_color,
|
| 1090 |
+
set: (value) => { cfg.surface_color = value; window.elementSdk.setConfig({ surface_color: value }); }
|
| 1091 |
+
},
|
| 1092 |
+
{
|
| 1093 |
+
get: () => cfg.text_color || defaultConfig.text_color,
|
| 1094 |
+
set: (value) => { cfg.text_color = value; window.elementSdk.setConfig({ text_color: value }); }
|
| 1095 |
+
},
|
| 1096 |
+
{
|
| 1097 |
+
get: () => cfg.primary_color || defaultConfig.primary_color,
|
| 1098 |
+
set: (value) => { cfg.primary_color = value; window.elementSdk.setConfig({ primary_color: value }); }
|
| 1099 |
+
},
|
| 1100 |
+
{
|
| 1101 |
+
get: () => cfg.secondary_color || defaultConfig.secondary_color,
|
| 1102 |
+
set: (value) => { cfg.secondary_color = value; window.elementSdk.setConfig({ secondary_color: value }); }
|
| 1103 |
+
}
|
| 1104 |
+
],
|
| 1105 |
+
borderables: [],
|
| 1106 |
+
fontEditable: {
|
| 1107 |
+
get: () => cfg.font_family || defaultConfig.font_family,
|
| 1108 |
+
set: (value) => { cfg.font_family = value; window.elementSdk.setConfig({ font_family: value }); }
|
| 1109 |
+
},
|
| 1110 |
+
fontSizeable: {
|
| 1111 |
+
get: () => cfg.font_size || defaultConfig.font_size,
|
| 1112 |
+
set: (value) => { cfg.font_size = value; window.elementSdk.setConfig({ font_size: value }); }
|
| 1113 |
+
}
|
| 1114 |
+
};
|
| 1115 |
+
}
|
| 1116 |
+
|
| 1117 |
+
function mapToEditPanelValues(cfg) {
|
| 1118 |
+
return new Map([
|
| 1119 |
+
['brand_name', cfg.brand_name || defaultConfig.brand_name],
|
| 1120 |
+
['hero_headline', cfg.hero_headline || defaultConfig.hero_headline],
|
| 1121 |
+
['hero_subheadline', cfg.hero_subheadline || defaultConfig.hero_subheadline],
|
| 1122 |
+
['cta_primary', cfg.cta_primary || defaultConfig.cta_primary]
|
| 1123 |
+
]);
|
| 1124 |
+
}
|
| 1125 |
+
|
| 1126 |
+
// Initialize SDK
|
| 1127 |
+
if (window.elementSdk) {
|
| 1128 |
+
window.elementSdk.init({
|
| 1129 |
+
defaultConfig,
|
| 1130 |
+
onConfigChange,
|
| 1131 |
+
mapToCapabilities,
|
| 1132 |
+
mapToEditPanelValues
|
| 1133 |
+
});
|
| 1134 |
+
} else {
|
| 1135 |
+
onConfigChange(defaultConfig);
|
| 1136 |
+
}
|
| 1137 |
+
</script>
|
| 1138 |
+
<script>(function(){function c(){var b=a.contentDocument||a.contentWindow.document;if(b){var d=b.createElement('script');d.innerHTML="window.__CF$cv$params={r:'9c279951d0bdd7df',t:'MTc2OTE3NDUzNi4wMDAwMDA='};var a=document.createElement('script');a.nonce='';a.src='/cdn-cgi/challenge-platform/scripts/jsd/main.js';document.getElementsByTagName('head')[0].appendChild(a);";b.getElementsByTagName('head')[0].appendChild(d)}}if(document.body){var a=document.createElement('iframe');a.height=1;a.width=1;a.style.position='absolute';a.style.top=0;a.style.left=0;a.style.border='none';a.style.visibility='hidden';document.body.appendChild(a);if('loading'!==document.readyState)c();else if(window.addEventListener)document.addEventListener('DOMContentLoaded',c);else{var e=document.onreadystatechange||function(){};document.onreadystatechange=function(b){e(b);'loading'!==document.readyState&&(document.onreadystatechange=e,c())}}}})();</script></body>
|
| 1139 |
+
</html>
|
src/model_loader.py
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Model loader for Arabic summarization model.
|
| 3 |
+
Handles loading and inference with error handling.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
import logging
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
import json
|
| 10 |
+
import torch
|
| 11 |
+
from transformers import MBartForConditionalGeneration, AutoTokenizer, AutoConfig
|
| 12 |
+
|
| 13 |
+
logger = logging.getLogger(__name__)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class SummarizationModel:
|
| 17 |
+
"""Wrapper class for the Arabic summarization model."""
|
| 18 |
+
|
| 19 |
+
def __init__(self, model_path):
|
| 20 |
+
"""
|
| 21 |
+
Initialize the model.
|
| 22 |
+
|
| 23 |
+
Args:
|
| 24 |
+
model_path: Path to the model directory
|
| 25 |
+
|
| 26 |
+
Raises:
|
| 27 |
+
FileNotFoundError: If model files are not found
|
| 28 |
+
RuntimeError: If model loading fails
|
| 29 |
+
"""
|
| 30 |
+
self.model_path = Path(model_path)
|
| 31 |
+
self.model = None
|
| 32 |
+
self.tokenizer = None
|
| 33 |
+
self.device = None
|
| 34 |
+
|
| 35 |
+
self._validate_path()
|
| 36 |
+
self._load_model()
|
| 37 |
+
|
| 38 |
+
def _validate_path(self):
|
| 39 |
+
"""Validate that the model path exists and contains required files."""
|
| 40 |
+
if not self.model_path.exists():
|
| 41 |
+
raise FileNotFoundError(f"Model path does not exist: {self.model_path}")
|
| 42 |
+
|
| 43 |
+
required_files = ['config.json', 'tokenizer.json', 'model.safetensors']
|
| 44 |
+
missing_files = []
|
| 45 |
+
|
| 46 |
+
for file in required_files:
|
| 47 |
+
if not (self.model_path / file).exists():
|
| 48 |
+
missing_files.append(file)
|
| 49 |
+
|
| 50 |
+
if missing_files:
|
| 51 |
+
raise FileNotFoundError(
|
| 52 |
+
f"Missing required model files: {', '.join(missing_files)}"
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
logger.info(f"Model path validated: {self.model_path}")
|
| 56 |
+
|
| 57 |
+
def _fix_generation_config(self):
|
| 58 |
+
"""Fix generation_config.json and config.json if early_stopping is None/null."""
|
| 59 |
+
gen_config_path = self.model_path / "generation_config.json"
|
| 60 |
+
config_path = self.model_path / "config.json"
|
| 61 |
+
|
| 62 |
+
try:
|
| 63 |
+
# Fix config.json first (this is the main issue)
|
| 64 |
+
if config_path.exists():
|
| 65 |
+
with open(config_path, 'r', encoding='utf-8') as f:
|
| 66 |
+
config = json.load(f)
|
| 67 |
+
|
| 68 |
+
# Check if early_stopping exists in config and is None
|
| 69 |
+
if 'early_stopping' in config and config['early_stopping'] is None:
|
| 70 |
+
logger.info("Fixing early_stopping in config.json (was None)")
|
| 71 |
+
config['early_stopping'] = True
|
| 72 |
+
with open(config_path, 'w', encoding='utf-8') as f:
|
| 73 |
+
json.dump(config, f, indent=2, ensure_ascii=False)
|
| 74 |
+
logger.info("Fixed config.json - set early_stopping to True")
|
| 75 |
+
|
| 76 |
+
# Fix generation_config.json
|
| 77 |
+
if gen_config_path.exists():
|
| 78 |
+
with open(gen_config_path, 'r', encoding='utf-8') as f:
|
| 79 |
+
gen_config = json.load(f)
|
| 80 |
+
|
| 81 |
+
# Fix early_stopping if it's None/null
|
| 82 |
+
if gen_config.get('early_stopping') is None:
|
| 83 |
+
logger.info("Fixing early_stopping in generation_config.json (was None)")
|
| 84 |
+
gen_config['early_stopping'] = True
|
| 85 |
+
with open(gen_config_path, 'w', encoding='utf-8') as f:
|
| 86 |
+
json.dump(gen_config, f, indent=2, ensure_ascii=False)
|
| 87 |
+
logger.info("Fixed generation_config.json - set early_stopping to True")
|
| 88 |
+
|
| 89 |
+
except Exception as e:
|
| 90 |
+
logger.warning(f"Could not fix generation config files: {str(e)}")
|
| 91 |
+
# Continue anyway, we'll try to load with workaround
|
| 92 |
+
|
| 93 |
+
def _load_model(self):
|
| 94 |
+
"""Load the model and tokenizer."""
|
| 95 |
+
try:
|
| 96 |
+
# Determine device
|
| 97 |
+
if torch.cuda.is_available():
|
| 98 |
+
self.device = torch.device('cuda')
|
| 99 |
+
logger.info(f"Using CUDA device: {torch.cuda.get_device_name(0)}")
|
| 100 |
+
else:
|
| 101 |
+
self.device = torch.device('cpu')
|
| 102 |
+
logger.info("Using CPU device")
|
| 103 |
+
|
| 104 |
+
# Load tokenizer with error handling
|
| 105 |
+
logger.info("Loading tokenizer...")
|
| 106 |
+
try:
|
| 107 |
+
self.tokenizer = AutoTokenizer.from_pretrained(
|
| 108 |
+
str(self.model_path),
|
| 109 |
+
local_files_only=True,
|
| 110 |
+
trust_remote_code=False
|
| 111 |
+
)
|
| 112 |
+
logger.info("Tokenizer loaded successfully")
|
| 113 |
+
except Exception as e:
|
| 114 |
+
logger.error(f"Failed to load tokenizer: {str(e)}")
|
| 115 |
+
# Try without local_files_only as fallback
|
| 116 |
+
logger.info("Retrying tokenizer load without local_files_only...")
|
| 117 |
+
self.tokenizer = AutoTokenizer.from_pretrained(
|
| 118 |
+
str(self.model_path),
|
| 119 |
+
trust_remote_code=False
|
| 120 |
+
)
|
| 121 |
+
logger.info("Tokenizer loaded successfully (fallback method)")
|
| 122 |
+
|
| 123 |
+
# Load model with error handling
|
| 124 |
+
logger.info("Loading model (this may take a while)...")
|
| 125 |
+
|
| 126 |
+
# Fix generation config files if needed
|
| 127 |
+
self._fix_generation_config()
|
| 128 |
+
|
| 129 |
+
# Load config and fix early_stopping if needed
|
| 130 |
+
try:
|
| 131 |
+
config = AutoConfig.from_pretrained(
|
| 132 |
+
str(self.model_path),
|
| 133 |
+
local_files_only=True,
|
| 134 |
+
trust_remote_code=False
|
| 135 |
+
)
|
| 136 |
+
|
| 137 |
+
# Fix early_stopping in config if it's None
|
| 138 |
+
if hasattr(config, 'early_stopping') and config.early_stopping is None:
|
| 139 |
+
logger.info("Fixing early_stopping in loaded config (was None)")
|
| 140 |
+
config.early_stopping = True
|
| 141 |
+
|
| 142 |
+
# Load model with fixed config
|
| 143 |
+
try:
|
| 144 |
+
self.model = MBartForConditionalGeneration.from_pretrained(
|
| 145 |
+
str(self.model_path),
|
| 146 |
+
config=config,
|
| 147 |
+
local_files_only=True,
|
| 148 |
+
trust_remote_code=False,
|
| 149 |
+
torch_dtype=torch.float32
|
| 150 |
+
)
|
| 151 |
+
except Exception as e:
|
| 152 |
+
logger.warning(f"Failed to load with config: {str(e)}")
|
| 153 |
+
# Try without explicit config
|
| 154 |
+
self.model = MBartForConditionalGeneration.from_pretrained(
|
| 155 |
+
str(self.model_path),
|
| 156 |
+
local_files_only=True,
|
| 157 |
+
trust_remote_code=False,
|
| 158 |
+
torch_dtype=torch.float32
|
| 159 |
+
)
|
| 160 |
+
except Exception as e:
|
| 161 |
+
logger.warning(f"Failed to load config: {str(e)}")
|
| 162 |
+
logger.info("Retrying model load without config fix...")
|
| 163 |
+
try:
|
| 164 |
+
self.model = MBartForConditionalGeneration.from_pretrained(
|
| 165 |
+
str(self.model_path),
|
| 166 |
+
local_files_only=True,
|
| 167 |
+
trust_remote_code=False,
|
| 168 |
+
torch_dtype=torch.float32
|
| 169 |
+
)
|
| 170 |
+
except Exception as e2:
|
| 171 |
+
logger.warning(f"Failed to load with local_files_only: {str(e2)}")
|
| 172 |
+
logger.info("Retrying model load without local_files_only...")
|
| 173 |
+
self.model = MBartForConditionalGeneration.from_pretrained(
|
| 174 |
+
str(self.model_path),
|
| 175 |
+
trust_remote_code=False,
|
| 176 |
+
torch_dtype=torch.float32
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
+
# Move model to device
|
| 180 |
+
self.model.to(self.device)
|
| 181 |
+
self.model.eval() # Set to evaluation mode
|
| 182 |
+
|
| 183 |
+
# Clear cache if using CUDA
|
| 184 |
+
if torch.cuda.is_available():
|
| 185 |
+
torch.cuda.empty_cache()
|
| 186 |
+
|
| 187 |
+
logger.info(f"Model loaded successfully on {self.device}")
|
| 188 |
+
|
| 189 |
+
except Exception as e:
|
| 190 |
+
logger.error(f"Error loading model: {str(e)}")
|
| 191 |
+
import traceback
|
| 192 |
+
logger.error(traceback.format_exc())
|
| 193 |
+
raise RuntimeError(f"Failed to load model: {str(e)}")
|
| 194 |
+
|
| 195 |
+
def summarize(self, text, max_length=150, min_length=30, num_beams=4, **kwargs):
|
| 196 |
+
"""
|
| 197 |
+
Summarize Arabic text.
|
| 198 |
+
|
| 199 |
+
Args:
|
| 200 |
+
text: Input Arabic text to summarize
|
| 201 |
+
max_length: Maximum length of the summary
|
| 202 |
+
min_length: Minimum length of the summary
|
| 203 |
+
num_beams: Number of beams for beam search
|
| 204 |
+
**kwargs: Additional generation parameters
|
| 205 |
+
|
| 206 |
+
Returns:
|
| 207 |
+
str: Summarized text
|
| 208 |
+
|
| 209 |
+
Raises:
|
| 210 |
+
RuntimeError: If summarization fails
|
| 211 |
+
"""
|
| 212 |
+
if self.model is None or self.tokenizer is None:
|
| 213 |
+
raise RuntimeError("Model not loaded")
|
| 214 |
+
|
| 215 |
+
try:
|
| 216 |
+
# Tokenize input
|
| 217 |
+
inputs = self.tokenizer(
|
| 218 |
+
text,
|
| 219 |
+
max_length=1024,
|
| 220 |
+
truncation=True,
|
| 221 |
+
padding=True,
|
| 222 |
+
return_tensors="pt"
|
| 223 |
+
)
|
| 224 |
+
|
| 225 |
+
# Move inputs to device
|
| 226 |
+
inputs = {k: v.to(self.device) for k, v in inputs.items()}
|
| 227 |
+
|
| 228 |
+
# Generate summary
|
| 229 |
+
with torch.no_grad():
|
| 230 |
+
outputs = self.model.generate(
|
| 231 |
+
**inputs,
|
| 232 |
+
max_length=max_length,
|
| 233 |
+
min_length=min_length,
|
| 234 |
+
num_beams=num_beams,
|
| 235 |
+
early_stopping=True,
|
| 236 |
+
no_repeat_ngram_size=3,
|
| 237 |
+
**kwargs
|
| 238 |
+
)
|
| 239 |
+
|
| 240 |
+
# Decode output
|
| 241 |
+
summary = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 242 |
+
|
| 243 |
+
return summary.strip()
|
| 244 |
+
|
| 245 |
+
except Exception as e:
|
| 246 |
+
logger.error(f"Error during summarization: {str(e)}")
|
| 247 |
+
raise RuntimeError(f"Summarization failed: {str(e)}")
|
| 248 |
+
|
| 249 |
+
def __del__(self):
|
| 250 |
+
"""Cleanup resources."""
|
| 251 |
+
if self.model is not None:
|
| 252 |
+
del self.model
|
| 253 |
+
if torch.cuda.is_available():
|
| 254 |
+
torch.cuda.empty_cache()
|
| 255 |
+
|
test_model_load.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Test script to verify model loading works correctly."""
|
| 2 |
+
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
# Add src to path
|
| 7 |
+
sys.path.insert(0, str(Path(__file__).parent / 'src'))
|
| 8 |
+
|
| 9 |
+
from model_loader import SummarizationModel
|
| 10 |
+
import logging
|
| 11 |
+
|
| 12 |
+
logging.basicConfig(level=logging.INFO)
|
| 13 |
+
|
| 14 |
+
def test_model_loading():
|
| 15 |
+
"""Test if the model loads correctly."""
|
| 16 |
+
model_path = Path("models/arabic_summarization_model/content/drive/MyDrive/arabic_summarization_model")
|
| 17 |
+
|
| 18 |
+
if not model_path.exists():
|
| 19 |
+
print(f"ERROR: Model path does not exist: {model_path}")
|
| 20 |
+
return False
|
| 21 |
+
|
| 22 |
+
try:
|
| 23 |
+
print("Loading model...")
|
| 24 |
+
model = SummarizationModel(str(model_path))
|
| 25 |
+
print("✓ Model loaded successfully!")
|
| 26 |
+
|
| 27 |
+
# Test summarization
|
| 28 |
+
test_text = "التكنولوجيا الحديثة أحدثت ثورة في حياتنا اليومية. حيث سهّلت التواصل والتعلم والعمل. مما أدى إلى تطور المجتمعات وتحسين جودة الحياة."
|
| 29 |
+
print(f"\nTesting summarization with text: {test_text[:50]}...")
|
| 30 |
+
summary = model.summarize(test_text, max_length=50, min_length=10)
|
| 31 |
+
print(f"✓ Summarization successful!")
|
| 32 |
+
print(f"Summary: {summary}")
|
| 33 |
+
|
| 34 |
+
return True
|
| 35 |
+
except Exception as e:
|
| 36 |
+
print(f"ERROR: {str(e)}")
|
| 37 |
+
import traceback
|
| 38 |
+
traceback.print_exc()
|
| 39 |
+
return False
|
| 40 |
+
|
| 41 |
+
if __name__ == "__main__":
|
| 42 |
+
success = test_model_loading()
|
| 43 |
+
sys.exit(0 if success else 1)
|
| 44 |
+
|