File size: 3,941 Bytes
fe1e225
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# Bayan - Arabic Text Summarization Setup Guide

## Overview
Bayan is an Arabic text summarization application with a web interface. This guide will help you set up and run the application.

## Prerequisites
- Python 3.8 or higher
- pip (Python package manager)
- At least 4GB RAM (8GB+ recommended for better performance)
- Model files in the correct location (see below)

## Installation Steps

### 1. Install Dependencies
```bash
pip install -r requirements.txt
```

**Note:** If you encounter issues installing PyTorch, you may need to install it separately:
- For CPU: `pip install torch --index-url https://download.pytorch.org/whl/cpu`
- For CUDA: Visit https://pytorch.org/get-started/locally/ for the appropriate command

### 2. Verify Model Location
The model should be located at:
```
models/arabic_summarization_model/content/drive/MyDrive/arabic_summarization_model/
```

Required files:
- `config.json`
- `tokenizer.json`
- `model.safetensors`
- `sentencepiece.bpe.model`
- Other tokenizer/model files

### 3. Run the Application

#### Option A: Using the run script (Recommended)
```bash
python run_app.py
```

#### Option B: Direct Flask run
```bash
cd src
python app.py
```

#### Option C: Using Flask CLI
```bash
cd src
export FLASK_APP=app.py
flask run
```

### 4. Access the Application
Open your browser and navigate to:
```
http://localhost:5000
```

## Configuration

### Environment Variables
- `PORT`: Server port (default: 5000)
- `DEBUG`: Enable debug mode (default: False)
  ```bash
  export DEBUG=True
  export PORT=8080
  ```

### Supabase Authentication (Phase 5)

See `.env.example` and `PHASE_5_IMPLEMENTATION_PLAN.md`.

1. Create a Supabase project and enable **Anonymous** + **Google** auth.
2. Run `supabase/migrations/001_profiles.sql` in the SQL Editor.
3. Set meta tags in `src/index.html`:
   ```html
   <meta name="supabase-url" content="https://YOUR_PROJECT.supabase.co">
   <meta name="supabase-anon-key" content="YOUR_ANON_KEY">
   ```
4. Add redirect URL: `http://localhost:5000/**`

If Supabase is not configured, the editor still works in offline auth mode.


### Model Not Found Error
If you see "Model not found" error:
1. Verify the model path exists
2. Check that all required files are present
3. The application will search multiple possible paths automatically

### Out of Memory Error
If you encounter memory issues:
1. Close other applications
2. Use CPU mode (it will automatically use CPU if CUDA is not available)
3. Reduce the `MAX_TEXT_LENGTH` in `src/app.py` if needed

### Port Already in Use
If port 5000 is already in use:
```bash
export PORT=5001
python run_app.py
```

### Slow Performance
- First run will be slower as the model loads
- Subsequent requests will be faster
- Using GPU (CUDA) significantly improves performance

## API Endpoints

### Health Check
```
GET /api/health
```
Returns server status and model loading state.

### Summarize Text
```
POST /api/summarize
Content-Type: application/json

{
  "text": "النص العربي المراد تلخيصه...",
  "length": 2,  // 1=short, 2=medium, 3=long
  "full_text": true
}
```

Response:
```json
{
  "status": "success",
  "summary": "الملخص المولد...",
  "original_length": 500,
  "summary_length": 150
}
```

## Security Features

- Input validation (text length limits)
- CORS enabled for web interface
- Error handling and logging
- Path validation for model files
- Safe model loading with fallbacks

## Development

### Running in Debug Mode
```bash
export DEBUG=True
python run_app.py
```

### Testing the API
```bash
curl -X POST http://localhost:5000/api/summarize \
  -H "Content-Type: application/json" \
  -d '{"text": "نص تجريبي للاختبار", "length": 2, "full_text": true}'
```

## Support

For issues or questions:
1. Check the logs in the terminal
2. Verify model files are correct
3. Ensure all dependencies are installed
4. Check Python version compatibility