Spaces:
Sleeping
Sleeping
Delete README.md
Browse files
README.md
DELETED
|
@@ -1,362 +0,0 @@
|
|
| 1 |
-
# AI Writing Studio - Production Grade
|
| 2 |
-
|
| 3 |
-
[](https://github.com/yourusername/writing-studio/actions)
|
| 4 |
-
[](https://codecov.io/gh/yourusername/writing-studio)
|
| 5 |
-
[](https://www.python.org/downloads/)
|
| 6 |
-
[](https://opensource.org/licenses/MIT)
|
| 7 |
-
|
| 8 |
-
A production-grade AI-powered writing assistant designed for educational environments. Compare drafts, receive rubric-based feedback, and improve your writing with AI-generated revisions.
|
| 9 |
-
|
| 10 |
-
## 🚀 One-Click Deploy
|
| 11 |
-
|
| 12 |
-
### Deploy to HuggingFace Spaces
|
| 13 |
-
|
| 14 |
-
[](https://huggingface.co/spaces)
|
| 15 |
-
|
| 16 |
-
**Quick Deploy:**
|
| 17 |
-
1. Click "Deploy to Spaces" above (or [create a new Space](https://huggingface.co/new-space))
|
| 18 |
-
2. Choose "Gradio" as the SDK
|
| 19 |
-
3. Upload/clone this repository
|
| 20 |
-
4. Your app will be live in minutes!
|
| 21 |
-
|
| 22 |
-
**No configuration needed** - Works out of the box on HuggingFace Spaces with sensible defaults.
|
| 23 |
-
|
| 24 |
-
## Features
|
| 25 |
-
|
| 26 |
-
- **AI-Powered Revisions**: Generate text improvements using state-of-the-art language models
|
| 27 |
-
- **Rubric-Based Scoring**: Automated analysis across multiple writing criteria:
|
| 28 |
-
- Clarity and sentence structure
|
| 29 |
-
- Conciseness and wordiness detection
|
| 30 |
-
- Organization and flow
|
| 31 |
-
- Evidence and support
|
| 32 |
-
- Grammar and mechanics
|
| 33 |
-
- **Side-by-Side Comparison**: Visual diff highlighting changes between original and revised text
|
| 34 |
-
- **Multiple Prompt Packs**: Specialized templates for different writing contexts:
|
| 35 |
-
- General writing
|
| 36 |
-
- Literature analysis
|
| 37 |
-
- Technical communication
|
| 38 |
-
- Academic writing
|
| 39 |
-
- Creative writing
|
| 40 |
-
- **Production Ready**:
|
| 41 |
-
- Comprehensive error handling
|
| 42 |
-
- Structured logging
|
| 43 |
-
- Prometheus metrics
|
| 44 |
-
- Health checks
|
| 45 |
-
- Rate limiting
|
| 46 |
-
- Docker support
|
| 47 |
-
- CI/CD pipeline
|
| 48 |
-
|
| 49 |
-
## Quick Start
|
| 50 |
-
|
| 51 |
-
### HuggingFace Spaces (Easiest)
|
| 52 |
-
|
| 53 |
-
The simplest way to use Writing Studio is on HuggingFace Spaces:
|
| 54 |
-
|
| 55 |
-
1. **Fork/Clone to Spaces:**
|
| 56 |
-
- Go to [HuggingFace Spaces](https://huggingface.co/spaces)
|
| 57 |
-
- Create a new Space with Gradio SDK
|
| 58 |
-
- Upload this repository or connect via Git
|
| 59 |
-
- Done! The app works immediately
|
| 60 |
-
|
| 61 |
-
2. **Local Run (for HF Spaces compatibility):**
|
| 62 |
-
```bash
|
| 63 |
-
pip install -r requirements.txt
|
| 64 |
-
python app.py
|
| 65 |
-
```
|
| 66 |
-
|
| 67 |
-
### Using Docker (Self-Hosted)
|
| 68 |
-
|
| 69 |
-
```bash
|
| 70 |
-
# Clone the repository
|
| 71 |
-
git clone https://github.com/yourusername/writing-studio.git
|
| 72 |
-
cd writing-studio
|
| 73 |
-
|
| 74 |
-
# Copy environment file
|
| 75 |
-
cp .env.example .env
|
| 76 |
-
|
| 77 |
-
# Start the application
|
| 78 |
-
docker-compose up
|
| 79 |
-
```
|
| 80 |
-
|
| 81 |
-
Visit `http://localhost:7860` for the application and `http://localhost:8000` for metrics.
|
| 82 |
-
|
| 83 |
-
### Local Development
|
| 84 |
-
|
| 85 |
-
```bash
|
| 86 |
-
# Create virtual environment
|
| 87 |
-
python -m venv venv
|
| 88 |
-
source venv/bin/activate # On Windows: venv\Scripts\activate
|
| 89 |
-
|
| 90 |
-
# Install dependencies
|
| 91 |
-
make install-dev
|
| 92 |
-
|
| 93 |
-
# Copy environment file
|
| 94 |
-
cp .env.example .env
|
| 95 |
-
|
| 96 |
-
# Run the application
|
| 97 |
-
make run
|
| 98 |
-
```
|
| 99 |
-
|
| 100 |
-
## Configuration
|
| 101 |
-
|
| 102 |
-
Configuration is managed through environment variables. See `.env.example` for all available options:
|
| 103 |
-
|
| 104 |
-
```bash
|
| 105 |
-
# Key configuration options
|
| 106 |
-
ENVIRONMENT=production # development, staging, production
|
| 107 |
-
DEFAULT_MODEL=distilgpt2 # HuggingFace model ID
|
| 108 |
-
HOST=0.0.0.0 # Server host
|
| 109 |
-
PORT=7860 # Server port
|
| 110 |
-
LOG_LEVEL=INFO # Logging level
|
| 111 |
-
ENABLE_METRICS=true # Enable Prometheus metrics
|
| 112 |
-
RATE_LIMIT_PER_MINUTE=10 # Rate limiting
|
| 113 |
-
```
|
| 114 |
-
|
| 115 |
-
## Project Structure
|
| 116 |
-
|
| 117 |
-
```
|
| 118 |
-
writing-studio/
|
| 119 |
-
├── src/
|
| 120 |
-
│ └── writing_studio/
|
| 121 |
-
│ ├── core/ # Core business logic
|
| 122 |
-
│ │ ├── analyzer.py # Main analysis orchestrator
|
| 123 |
-
│ │ ├── config.py # Configuration management
|
| 124 |
-
│ │ └── exceptions.py # Custom exceptions
|
| 125 |
-
│ ├── services/ # Service layer
|
| 126 |
-
│ │ ├── model_service.py # Model management
|
| 127 |
-
│ │ ├── rubric_service.py # Rubric scoring
|
| 128 |
-
│ │ ├── diff_service.py # Text comparison
|
| 129 |
-
│ │ └── prompt_service.py # Prompt templates
|
| 130 |
-
│ ├── utils/ # Utilities
|
| 131 |
-
│ │ ├── logging.py # Logging configuration
|
| 132 |
-
│ │ ├── validation.py # Input validation
|
| 133 |
-
│ │ ├── metrics.py # Prometheus metrics
|
| 134 |
-
│ │ └── monitoring.py # Health checks
|
| 135 |
-
│ └── main.py # Application entry point
|
| 136 |
-
├── tests/ # Test suite
|
| 137 |
-
│ ├── unit/ # Unit tests
|
| 138 |
-
│ └── integration/ # Integration tests
|
| 139 |
-
├── configs/ # Configuration files
|
| 140 |
-
├── docs/ # Documentation
|
| 141 |
-
├── Dockerfile # Docker image definition
|
| 142 |
-
├── docker-compose.yml # Docker Compose configuration
|
| 143 |
-
├── pyproject.toml # Python project configuration
|
| 144 |
-
└── requirements.txt # Python dependencies
|
| 145 |
-
```
|
| 146 |
-
|
| 147 |
-
## Development
|
| 148 |
-
|
| 149 |
-
### Setup Development Environment
|
| 150 |
-
|
| 151 |
-
```bash
|
| 152 |
-
# Install development dependencies
|
| 153 |
-
make install-dev
|
| 154 |
-
|
| 155 |
-
# Install pre-commit hooks
|
| 156 |
-
pre-commit install
|
| 157 |
-
```
|
| 158 |
-
|
| 159 |
-
### Running Tests
|
| 160 |
-
|
| 161 |
-
```bash
|
| 162 |
-
# Run all tests with coverage
|
| 163 |
-
make test
|
| 164 |
-
|
| 165 |
-
# Run specific test file
|
| 166 |
-
pytest tests/unit/test_validation.py -v
|
| 167 |
-
```
|
| 168 |
-
|
| 169 |
-
### Code Quality
|
| 170 |
-
|
| 171 |
-
```bash
|
| 172 |
-
# Format code
|
| 173 |
-
make format
|
| 174 |
-
|
| 175 |
-
# Run linters
|
| 176 |
-
make lint
|
| 177 |
-
|
| 178 |
-
# Run all checks
|
| 179 |
-
make format lint test
|
| 180 |
-
```
|
| 181 |
-
|
| 182 |
-
### Docker Development
|
| 183 |
-
|
| 184 |
-
```bash
|
| 185 |
-
# Build Docker image
|
| 186 |
-
make docker-build
|
| 187 |
-
|
| 188 |
-
# Run with Docker Compose
|
| 189 |
-
make docker-run
|
| 190 |
-
|
| 191 |
-
# View logs
|
| 192 |
-
docker-compose logs -f app
|
| 193 |
-
```
|
| 194 |
-
|
| 195 |
-
## Monitoring
|
| 196 |
-
|
| 197 |
-
The application exposes Prometheus metrics on port 8000 (configurable):
|
| 198 |
-
|
| 199 |
-
- `writing_studio_requests_total` - Total number of requests
|
| 200 |
-
- `writing_studio_request_duration_seconds` - Request duration
|
| 201 |
-
- `writing_studio_generation_duration_seconds` - Text generation duration
|
| 202 |
-
- `writing_studio_cache_hits_total` - Cache hit count
|
| 203 |
-
- `writing_studio_errors_total` - Error count by type
|
| 204 |
-
|
| 205 |
-
### Health Checks
|
| 206 |
-
|
| 207 |
-
- **Liveness**: `GET /health/live` - Check if application is alive
|
| 208 |
-
- **Readiness**: `GET /health/ready` - Check if ready to serve requests
|
| 209 |
-
- **Health**: `GET /health` - Comprehensive health check
|
| 210 |
-
|
| 211 |
-
## Deployment
|
| 212 |
-
|
| 213 |
-
### Environment Variables for Production
|
| 214 |
-
|
| 215 |
-
```bash
|
| 216 |
-
ENVIRONMENT=production
|
| 217 |
-
DEBUG=false
|
| 218 |
-
LOG_LEVEL=INFO
|
| 219 |
-
ENABLE_AUTH=true
|
| 220 |
-
SECRET_KEY=your-secure-secret-key
|
| 221 |
-
ALLOWED_ORIGINS=https://yourdomain.com
|
| 222 |
-
```
|
| 223 |
-
|
| 224 |
-
### Docker Deployment
|
| 225 |
-
|
| 226 |
-
```bash
|
| 227 |
-
# Build production image
|
| 228 |
-
docker build -t writing-studio:latest .
|
| 229 |
-
|
| 230 |
-
# Run with production settings
|
| 231 |
-
docker run -d \
|
| 232 |
-
--name writing-studio \
|
| 233 |
-
-p 7860:7860 \
|
| 234 |
-
-p 8000:8000 \
|
| 235 |
-
-e ENVIRONMENT=production \
|
| 236 |
-
-v $(pwd)/logs:/app/logs \
|
| 237 |
-
-v $(pwd)/models:/app/models \
|
| 238 |
-
writing-studio:latest
|
| 239 |
-
```
|
| 240 |
-
|
| 241 |
-
### Monitoring Stack (Optional)
|
| 242 |
-
|
| 243 |
-
Start the full monitoring stack with Prometheus and Grafana:
|
| 244 |
-
|
| 245 |
-
```bash
|
| 246 |
-
docker-compose --profile monitoring up
|
| 247 |
-
```
|
| 248 |
-
|
| 249 |
-
Access:
|
| 250 |
-
- Application: http://localhost:7860
|
| 251 |
-
- Metrics: http://localhost:8000
|
| 252 |
-
- Prometheus: http://localhost:9090
|
| 253 |
-
- Grafana: http://localhost:3000 (admin/admin)
|
| 254 |
-
|
| 255 |
-
## API Usage
|
| 256 |
-
|
| 257 |
-
While the primary interface is the Gradio web UI, you can also use the core components programmatically:
|
| 258 |
-
|
| 259 |
-
```python
|
| 260 |
-
from writing_studio.core.analyzer import WritingAnalyzer
|
| 261 |
-
|
| 262 |
-
analyzer = WritingAnalyzer()
|
| 263 |
-
|
| 264 |
-
original, revision, feedback, diff_html, metadata = analyzer.analyze_and_compare(
|
| 265 |
-
user_text="Your text here",
|
| 266 |
-
model_name="distilgpt2",
|
| 267 |
-
prompt_pack="General"
|
| 268 |
-
)
|
| 269 |
-
|
| 270 |
-
print(f"Feedback:\n{feedback}")
|
| 271 |
-
print(f"Duration: {metadata['duration']:.2f}s")
|
| 272 |
-
```
|
| 273 |
-
|
| 274 |
-
## Performance Optimization
|
| 275 |
-
|
| 276 |
-
- **Model Caching**: Models are cached after first load
|
| 277 |
-
- **Generation Caching**: Results are cached based on input hash
|
| 278 |
-
- **Lazy Loading**: Services initialized on first use
|
| 279 |
-
- **Docker Layer Caching**: Multi-stage builds for faster rebuilds
|
| 280 |
-
|
| 281 |
-
## Security Features
|
| 282 |
-
|
| 283 |
-
- Input validation and sanitization
|
| 284 |
-
- Rate limiting (configurable)
|
| 285 |
-
- Path traversal protection
|
| 286 |
-
- Non-root Docker user
|
| 287 |
-
- Security scanning in CI/CD
|
| 288 |
-
- CORS configuration
|
| 289 |
-
- Secret management via environment variables
|
| 290 |
-
|
| 291 |
-
## Troubleshooting
|
| 292 |
-
|
| 293 |
-
### Common Issues
|
| 294 |
-
|
| 295 |
-
**Model Loading Fails**
|
| 296 |
-
```bash
|
| 297 |
-
# Ensure sufficient disk space
|
| 298 |
-
df -h
|
| 299 |
-
|
| 300 |
-
# Check model cache directory permissions
|
| 301 |
-
ls -la ./models/
|
| 302 |
-
```
|
| 303 |
-
|
| 304 |
-
**Port Already in Use**
|
| 305 |
-
```bash
|
| 306 |
-
# Change ports in .env or docker-compose.yml
|
| 307 |
-
PORT=7861
|
| 308 |
-
METRICS_PORT=8001
|
| 309 |
-
```
|
| 310 |
-
|
| 311 |
-
**Memory Issues**
|
| 312 |
-
```bash
|
| 313 |
-
# Use a smaller model
|
| 314 |
-
DEFAULT_MODEL=distilgpt2
|
| 315 |
-
|
| 316 |
-
# Disable caching if needed
|
| 317 |
-
ENABLE_CACHE=false
|
| 318 |
-
```
|
| 319 |
-
|
| 320 |
-
## Contributing
|
| 321 |
-
|
| 322 |
-
1. Fork the repository
|
| 323 |
-
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
| 324 |
-
3. Make your changes
|
| 325 |
-
4. Run tests and linters (`make format lint test`)
|
| 326 |
-
5. Commit your changes (`git commit -m 'Add amazing feature'`)
|
| 327 |
-
6. Push to the branch (`git push origin feature/amazing-feature`)
|
| 328 |
-
7. Open a Pull Request
|
| 329 |
-
|
| 330 |
-
## License
|
| 331 |
-
|
| 332 |
-
This project is licensed under the MIT License - see the LICENSE file for details.
|
| 333 |
-
|
| 334 |
-
## Acknowledgments
|
| 335 |
-
|
| 336 |
-
- Built with [Gradio](https://gradio.app/) for the web interface
|
| 337 |
-
- Powered by [HuggingFace Transformers](https://huggingface.co/transformers/)
|
| 338 |
-
- Monitoring with [Prometheus](https://prometheus.io/)
|
| 339 |
-
|
| 340 |
-
## Documentation
|
| 341 |
-
|
| 342 |
-
- **[User Guide](docs/USER_GUIDE.md)** - How to use the application
|
| 343 |
-
- **[Architecture](docs/ARCHITECTURE.md)** - System design and structure
|
| 344 |
-
- **[Deployment Guide](docs/DEPLOYMENT.md)** - Self-hosted deployment
|
| 345 |
-
- **[HuggingFace Spaces Guide](docs/HUGGINGFACE_SPACES.md)** - Deploy to HF Spaces
|
| 346 |
-
- **[Production Upgrade Summary](PRODUCTION_UPGRADE.md)** - What was improved
|
| 347 |
-
|
| 348 |
-
## Support
|
| 349 |
-
|
| 350 |
-
- Documentation: [docs/](docs/)
|
| 351 |
-
- Issues: [GitHub Issues](https://github.com/yourusername/writing-studio/issues)
|
| 352 |
-
- Discussions: [GitHub Discussions](https://github.com/yourusername/writing-studio/discussions)
|
| 353 |
-
|
| 354 |
-
## Roadmap
|
| 355 |
-
|
| 356 |
-
- [ ] User authentication and session management
|
| 357 |
-
- [ ] Database integration for saving analyses
|
| 358 |
-
- [ ] Support for additional language models
|
| 359 |
-
- [ ] Export functionality (PDF, Word)
|
| 360 |
-
- [ ] Collaborative features
|
| 361 |
-
- [ ] Custom rubric creation
|
| 362 |
-
- [ ] API endpoints for programmatic access
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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