Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	File size: 3,425 Bytes
			
			bd3417a  | 
								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  | 
								---
title: Text Summarizer API
emoji: π
colorFrom: blue
colorTo: purple
sdk: docker
pinned: false
license: mit
app_port: 7860
---
# Text Summarizer API
A FastAPI-based text summarization service powered by Ollama and Mistral 7B model.
## π Features
- **Fast text summarization** using local LLM inference
- **RESTful API** with FastAPI
- **Health monitoring** and logging
- **Docker containerized** for easy deployment
- **Free deployment** on Hugging Face Spaces
## π‘ API Endpoints
### Health Check
```
GET /health
```
### Summarize Text
```
POST /api/v1/summarize
Content-Type: application/json
{
  "text": "Your long text to summarize here...",
  "max_tokens": 256,
  "temperature": 0.7
}
```
### API Documentation
- **Swagger UI**: `/docs`
- **ReDoc**: `/redoc`
## π§ Configuration
The service uses the following environment variables:
- `OLLAMA_MODEL`: Model to use (default: `mistral:7b`)
- `OLLAMA_HOST`: Ollama service host (default: `http://localhost:11434`)
- `OLLAMA_TIMEOUT`: Request timeout in seconds (default: `30`)
- `SERVER_HOST`: Server host (default: `0.0.0.0`)
- `SERVER_PORT`: Server port (default: `7860`)
- `LOG_LEVEL`: Logging level (default: `INFO`)
## π³ Docker Deployment
### Local Development
```bash
# Build and run with docker-compose
docker-compose up --build
# Or run directly
docker build -f Dockerfile.hf -t summarizer-app .
docker run -p 7860:7860 summarizer-app
```
### Hugging Face Spaces
This app is configured for deployment on Hugging Face Spaces using Docker SDK.
## π Performance
- **Model**: Mistral 7B (7GB RAM requirement)
- **Startup time**: ~2-3 minutes (includes model download)
- **Inference speed**: ~2-5 seconds per request
- **Memory usage**: ~8GB RAM
## π οΈ Development
### Setup
```bash
# Install dependencies
pip install -r requirements.txt
# Run locally
uvicorn app.main:app --host 0.0.0.0 --port 7860
```
### Testing
```bash
# Run tests
pytest
# Run with coverage
pytest --cov=app
```
## π Usage Examples
### Python
```python
import requests
# Summarize text
response = requests.post(
    "https://your-space.hf.space/api/v1/summarize",
    json={
        "text": "Your long article or text here...",
        "max_tokens": 256
    }
)
result = response.json()
print(result["summary"])
```
### cURL
```bash
curl -X POST "https://your-space.hf.space/api/v1/summarize" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Your text to summarize...",
    "max_tokens": 256
  }'
```
## π Security
- Non-root user execution
- Input validation and sanitization
- Rate limiting (configurable)
- API key authentication (optional)
## π Monitoring
The service includes:
- Health check endpoint
- Request logging
- Error tracking
- Performance metrics
## π Troubleshooting
### Common Issues
1. **Model not loading**: Check if Ollama is running and model is pulled
2. **Out of memory**: Ensure sufficient RAM (8GB+) for Mistral 7B
3. **Slow startup**: Normal on first run due to model download
4. **API errors**: Check logs via `/docs` endpoint
### Logs
View application logs in the Hugging Face Spaces interface or check the health endpoint for service status.
## π License
MIT License - see LICENSE file for details.
## π€ Contributing
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests
5. Submit a pull request
---
**Deployed on Hugging Face Spaces** π
 |