File size: 6,554 Bytes
4e5d359
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
411c845
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# 🧠 Active Reading Demo - Deployment Guide

This directory contains a streamlined version of the Enterprise Active Reading Framework optimized for Hugging Face Spaces deployment.

## πŸ“ Files Overview

```
demo/
β”œβ”€β”€ app.py              # Main Gradio application
β”œβ”€β”€ requirements.txt    # Minimal dependencies for HF Spaces
β”œβ”€β”€ README.md          # HF Space description (will appear on space page)
β”œβ”€β”€ BLOG.md            # Comprehensive blog post about Active Reading
β”œβ”€β”€ SPACE_BLOG.md      # Shorter, HF Space focused blog
└── DEMO_README.md     # This file - deployment instructions
```

## πŸš€ Quick Deploy to Hugging Face Spaces

### Option 1: Automated Script (Recommended)
```bash
# From project root
./scripts/deploy_hf_space.sh YOUR_HF_USERNAME active-reading-demo
```

### Option 2: Manual Deployment
```bash
# 1. Create new space at https://huggingface.co/new-space
#    - Choose: Gradio SDK, Public visibility
#    - Hardware: CPU Basic (free)

# 2. Copy demo files to new directory
cp -r demo/ hf-deploy/
cd hf-deploy/

# 3. Initialize git and push
git init
git add .
git commit -m "Active Reading demo"
git remote add origin https://huggingface.co/spaces/YOUR_USERNAME/SPACE_NAME
git push -u origin main
```

## 🎯 Demo Features

### Interactive Interface
- **Sample Documents**: Financial, Legal, Technical, Medical examples
- **Multiple Strategies**: Fact extraction, summarization, Q&A generation
- **Real-time Processing**: Watch AI analyze documents live
- **Structured Output**: JSON formatted results for integration

### Sample Documents Included
- **πŸ“Š Financial Report**: Quarterly earnings with growth metrics
- **βš–οΈ Legal Contract**: Software licensing agreement  
- **πŸ”§ Technical Manual**: API documentation
- **πŸ₯ Medical Research**: Clinical trial results

### Active Reading Strategies
- **Fact Extraction**: Structured information capture
- **Summarization**: Concise document overviews
- **Question Generation**: Comprehension assessment
- **Complete Analysis**: All strategies combined

## πŸ”§ Technical Details

### Model Configuration
- **Model**: `microsoft/DialoGPT-small` (optimized for HF Spaces)
- **Device**: Auto-detection (CPU/GPU)
- **Memory**: Optimized for free tier limits
- **Processing**: Real-time with progress indicators

### Dependencies
```
torch>=2.0.0
transformers>=4.30.0
gradio>=4.0.0
numpy>=1.24.0
```

### Hardware Requirements
- **Minimum**: CPU Basic (FREE on HF Spaces)
- **Recommended**: CPU Upgrade ($0.05/hour)
- **Optimal**: GPU T4 ($0.60/hour) for faster processing

## πŸ“Š Performance Expectations

### Processing Speed
- **CPU Basic**: 10-30 seconds per document
- **CPU Upgrade**: 5-15 seconds per document  
- **GPU T4**: 2-5 seconds per document

### Document Limits
- **Text Length**: Up to 2000 words (demo limitation)
- **Concurrent Users**: 10-50 depending on hardware
- **Response Time**: 95th percentile under 30 seconds

## 🎨 Customization Options

### Branding
Update in `app.py`:
```python
# Change title and description
gr.Blocks(title="Your Company Active Reading", theme=gr.themes.Soft())

# Update header
gr.Markdown("# 🧠 Your Company Active Reading Demo")
```

### Sample Documents
Add your own samples in `app.py`:
```python
sample_texts = {
    "Your Document Type": """
    Your sample content here...
    """,
    # ... existing samples
}
```

### Strategies
Extend reading strategies:
```python
# In SimpleActiveReader class
def custom_strategy(self, text: str) -> List[str]:
    # Your custom processing logic
    return results
```

## πŸ“ˆ Analytics and Monitoring

### Built-in Metrics
- Document processing counts
- Strategy usage patterns
- Error rates and performance
- User interaction patterns

### HF Spaces Analytics
- View usage stats in HF Spaces dashboard
- Monitor resource consumption
- Track user engagement

## πŸ”’ Security Considerations

### Demo Limitations
- **No data persistence**: Sessions are temporary
- **No user authentication**: Public access
- **Limited PII protection**: Basic patterns only
- **No audit logging**: Demo purposes only

### For Production Use
Upgrade to full enterprise framework for:
- User authentication and authorization
- Comprehensive PII detection
- Audit logging and compliance
- Data encryption and persistence

## πŸ› Troubleshooting

### Common Issues

**Model Loading Errors**:
```bash
# Check if model downloads properly
python -c "from transformers import AutoTokenizer; AutoTokenizer.from_pretrained('microsoft/DialoGPT-small')"
```

**Memory Issues**:
- Reduce max_length in model config
- Use smaller batch sizes
- Upgrade to paid HF Spaces hardware

**Slow Performance**:
- Upgrade to GPU hardware
- Optimize chunk sizes
- Cache model loading

### Error Messages
- **"Model not loaded"**: Model initialization failed
- **"Processing timeout"**: Document too large or complex
- **"Memory error"**: Upgrade hardware or reduce input size

## πŸ“š Documentation Links

### Active Reading Research
- [Original Paper](https://arxiv.org/abs/2508.09494)
- [Meta AI Blog Post](https://ai.meta.com/blog/)
- [Implementation Details](../IMPLEMENTATION_GUIDE.md)

### Enterprise Framework
- [Full Framework](../README.md)
- [Deployment Guide](../DEPLOYMENT_GUIDE.md)
- [Security Features](../src/enterprise/security.py)

### Hugging Face Resources
- [Spaces Documentation](https://huggingface.co/docs/hub/spaces)
- [Gradio Documentation](https://gradio.app/docs/)
- [Model Hub](https://huggingface.co/models)

## 🀝 Contributing

### Improve the Demo
- Add new sample documents
- Implement additional reading strategies
- Enhance UI/UX design
- Optimize performance

### Extend Functionality
- Multi-language support
- Advanced visualization
- Integration examples
- Mobile responsiveness

## πŸ“ž Support

### For Demo Issues
- Check HF Spaces logs
- Review error messages
- Test locally first
- Update dependencies

### For Enterprise Deployment
- Review full framework documentation
- Contact for pilot programs
- Custom implementation support
- Training and consultation

## πŸŽ‰ Success Metrics

### Demo Engagement
- Time spent on demo
- Documents analyzed
- Strategies tested
- Return visitors

### Enterprise Interest
- Contact form submissions
- GitHub stars and forks
- Enterprise inquiries
- Pilot program requests

---

**Ready to deploy?** Use the automated script or follow manual steps above!

```bash
./scripts/deploy_hf_space.sh YOUR_USERNAME active-reading-demo
```

πŸš€ **Your Active Reading demo will be live in minutes!**