Spaces:
Sleeping
Sleeping
Upload 46 files
Browse files- .space_config.yml +23 -0
- DEPLOY_TO_HF_SPACES.md +148 -0
- HF_SPACES_CHECKLIST.md +254 -0
- HF_SPACES_README.txt +225 -0
- README.md +39 -1
- README_HF_SPACES.md +196 -0
- app.py +241 -56
- docs/HUGGINGFACE_SPACES.md +523 -0
- requirements.txt +19 -20
- src/writing_studio/core/config.py +12 -1
.space_config.yml
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# HuggingFace Spaces Configuration
|
| 2 |
+
# This file is optional but helps optimize deployment on HF Spaces
|
| 3 |
+
|
| 4 |
+
sdk: gradio
|
| 5 |
+
sdk_version: "4.0.0"
|
| 6 |
+
app_file: app.py
|
| 7 |
+
pinned: false
|
| 8 |
+
license: mit
|
| 9 |
+
duplicated_from: ~
|
| 10 |
+
|
| 11 |
+
# Suggested hardware for optimal performance
|
| 12 |
+
# Free tier works but may be slower for larger models
|
| 13 |
+
# suggested_hardware: cpu-basic
|
| 14 |
+
# suggested_hardware: cpu-upgrade
|
| 15 |
+
# suggested_hardware: t4-small
|
| 16 |
+
|
| 17 |
+
# Environment variables (optional - app has sensible defaults)
|
| 18 |
+
# These can also be set in the Space Settings on HuggingFace
|
| 19 |
+
env:
|
| 20 |
+
ENVIRONMENT: production
|
| 21 |
+
LOG_LEVEL: INFO
|
| 22 |
+
DEFAULT_MODEL: distilgpt2
|
| 23 |
+
ENABLE_METRICS: "false"
|
DEPLOY_TO_HF_SPACES.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🚀 Deploy to HuggingFace Spaces - Quick Guide
|
| 2 |
+
|
| 3 |
+
## ✅ Your App is Ready!
|
| 4 |
+
|
| 5 |
+
This application is **fully configured** for HuggingFace Spaces deployment. No additional setup needed!
|
| 6 |
+
|
| 7 |
+
## 📦 What You Need to Upload
|
| 8 |
+
|
| 9 |
+
### Required Files
|
| 10 |
+
```
|
| 11 |
+
✓ app.py (HF Spaces entry point)
|
| 12 |
+
✓ requirements.txt (Python dependencies)
|
| 13 |
+
✓ src/ (Complete source code)
|
| 14 |
+
└── writing_studio/
|
| 15 |
+
├── core/
|
| 16 |
+
├── services/
|
| 17 |
+
└── utils/
|
| 18 |
+
```
|
| 19 |
+
|
| 20 |
+
### Recommended Files
|
| 21 |
+
```
|
| 22 |
+
✓ .space_config.yml (HF configuration)
|
| 23 |
+
✓ README_HF_SPACES.md (Rename to README.md in your Space)
|
| 24 |
+
```
|
| 25 |
+
|
| 26 |
+
## 🎯 Deploy in 3 Steps
|
| 27 |
+
|
| 28 |
+
### 1️⃣ Create Space
|
| 29 |
+
Visit: https://huggingface.co/new-space
|
| 30 |
+
- Name your Space
|
| 31 |
+
- Choose SDK: **Gradio**
|
| 32 |
+
- Select: Public or Private
|
| 33 |
+
- Click "Create Space"
|
| 34 |
+
|
| 35 |
+
### 2️⃣ Upload Files
|
| 36 |
+
Drag and drop or use Git:
|
| 37 |
+
- `app.py`
|
| 38 |
+
- `requirements.txt`
|
| 39 |
+
- `src/` folder (keep structure!)
|
| 40 |
+
- `.space_config.yml`
|
| 41 |
+
- Rename `README_HF_SPACES.md` → `README.md`
|
| 42 |
+
|
| 43 |
+
### 3️⃣ Wait & Test
|
| 44 |
+
- Build takes ~5 minutes
|
| 45 |
+
- App will be live at: `https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE`
|
| 46 |
+
- Test with sample text!
|
| 47 |
+
|
| 48 |
+
## 🎨 Features Included
|
| 49 |
+
|
| 50 |
+
✅ **Real Rubric Scoring** - Clarity, Conciseness, Organization, Evidence, Grammar
|
| 51 |
+
✅ **5 Prompt Packs** - General, Literature, Tech Comm, Academic, Creative
|
| 52 |
+
✅ **Visual Diff** - Highlighted changes between drafts
|
| 53 |
+
✅ **Smart Caching** - Fast repeated analyses
|
| 54 |
+
✅ **Error Handling** - User-friendly error messages
|
| 55 |
+
✅ **Production Ready** - Validation, logging, metrics
|
| 56 |
+
|
| 57 |
+
## ⚙️ Configuration
|
| 58 |
+
|
| 59 |
+
### Default Settings (Perfect for Free Tier)
|
| 60 |
+
- Model: `distilgpt2` (fast & lightweight)
|
| 61 |
+
- Metrics: Disabled (not needed on HF Spaces)
|
| 62 |
+
- Logging: Text format (easy to read)
|
| 63 |
+
- Caching: Enabled (faster responses)
|
| 64 |
+
|
| 65 |
+
### Custom Settings (Optional)
|
| 66 |
+
Edit `.space_config.yml` or add in Space Settings:
|
| 67 |
+
```yaml
|
| 68 |
+
env:
|
| 69 |
+
DEFAULT_MODEL: gpt2 # Use larger model
|
| 70 |
+
MAX_TEXT_LENGTH: "5000" # Limit input size
|
| 71 |
+
LOG_LEVEL: INFO # Logging detail
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
## 💰 Hardware Tiers
|
| 75 |
+
|
| 76 |
+
### Free Tier (Recommended to Start)
|
| 77 |
+
- Works great with distilgpt2
|
| 78 |
+
- First analysis: ~30-60s
|
| 79 |
+
- Subsequent: ~5-10s
|
| 80 |
+
- Perfect for demos!
|
| 81 |
+
|
| 82 |
+
### CPU Upgrade ($0.10/hr)
|
| 83 |
+
- Better for gpt2
|
| 84 |
+
- Faster processing
|
| 85 |
+
|
| 86 |
+
### T4 GPU ($0.60/hr)
|
| 87 |
+
- Best performance
|
| 88 |
+
- Large models supported
|
| 89 |
+
|
| 90 |
+
## 📚 Documentation
|
| 91 |
+
|
| 92 |
+
- **[HF_SPACES_CHECKLIST.md](HF_SPACES_CHECKLIST.md)** - Deployment checklist
|
| 93 |
+
- **[docs/HUGGINGFACE_SPACES.md](docs/HUGGINGFACE_SPACES.md)** - Complete guide
|
| 94 |
+
- **[README_HF_SPACES.md](README_HF_SPACES.md)** - User documentation
|
| 95 |
+
- **[HF_SPACES_README.txt](HF_SPACES_README.txt)** - Quick reference
|
| 96 |
+
|
| 97 |
+
## 🧪 Test Locally First
|
| 98 |
+
|
| 99 |
+
```bash
|
| 100 |
+
pip install -r requirements.txt
|
| 101 |
+
python app.py
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
Visit http://localhost:7860 and test!
|
| 105 |
+
|
| 106 |
+
## 🆘 Troubleshooting
|
| 107 |
+
|
| 108 |
+
**Build fails?**
|
| 109 |
+
- Check all `src/` files uploaded
|
| 110 |
+
- Verify `requirements.txt` syntax
|
| 111 |
+
|
| 112 |
+
**Out of memory?**
|
| 113 |
+
- Use distilgpt2 (default)
|
| 114 |
+
- Upgrade hardware tier
|
| 115 |
+
|
| 116 |
+
**Slow?**
|
| 117 |
+
- First load always slow (model download)
|
| 118 |
+
- Use distilgpt2 for speed
|
| 119 |
+
- Upgrade hardware
|
| 120 |
+
|
| 121 |
+
**Full troubleshooting:** See [docs/HUGGINGFACE_SPACES.md](docs/HUGGINGFACE_SPACES.md)
|
| 122 |
+
|
| 123 |
+
## ⏱️ Timeline
|
| 124 |
+
|
| 125 |
+
- Setup: 5-10 minutes
|
| 126 |
+
- Build: 3-5 minutes
|
| 127 |
+
- **Total: ~15 minutes to live app!**
|
| 128 |
+
|
| 129 |
+
## 🎉 Success Checklist
|
| 130 |
+
|
| 131 |
+
After deployment, verify:
|
| 132 |
+
- [ ] Space builds successfully
|
| 133 |
+
- [ ] App loads in browser
|
| 134 |
+
- [ ] Text analysis works
|
| 135 |
+
- [ ] All 5 prompt packs available
|
| 136 |
+
- [ ] Rubric scores display
|
| 137 |
+
- [ ] Diff highlighting works
|
| 138 |
+
- [ ] Error handling tested
|
| 139 |
+
|
| 140 |
+
## 🔗 Resources
|
| 141 |
+
|
| 142 |
+
- [HuggingFace Spaces Docs](https://huggingface.co/docs/hub/spaces)
|
| 143 |
+
- [Gradio Documentation](https://gradio.app/docs/)
|
| 144 |
+
- [GitHub Repository](https://github.com/yourusername/writing-studio)
|
| 145 |
+
|
| 146 |
+
---
|
| 147 |
+
|
| 148 |
+
**Ready to deploy?** Follow the 3 steps above and you'll be live in minutes! 🚀
|
HF_SPACES_CHECKLIST.md
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# HuggingFace Spaces Deployment Checklist
|
| 2 |
+
|
| 3 |
+
Quick checklist for deploying Writing Studio to HuggingFace Spaces.
|
| 4 |
+
|
| 5 |
+
## Pre-Deployment
|
| 6 |
+
|
| 7 |
+
- [ ] HuggingFace account created
|
| 8 |
+
- [ ] Reviewed [HF Spaces documentation](https://huggingface.co/docs/hub/spaces)
|
| 9 |
+
- [ ] Decided on Space name
|
| 10 |
+
- [ ] Chosen visibility (Public or Private)
|
| 11 |
+
|
| 12 |
+
## Required Files
|
| 13 |
+
|
| 14 |
+
Ensure these files are ready to upload:
|
| 15 |
+
|
| 16 |
+
- [ ] `app.py` - HF Spaces entry point
|
| 17 |
+
- [ ] `requirements.txt` - Python dependencies
|
| 18 |
+
- [ ] `src/writing_studio/` - Complete source directory
|
| 19 |
+
- [ ] `core/` - Core modules
|
| 20 |
+
- [ ] `services/` - Service layer
|
| 21 |
+
- [ ] `utils/` - Utilities
|
| 22 |
+
|
| 23 |
+
## Optional Files
|
| 24 |
+
|
| 25 |
+
Recommended for better UX:
|
| 26 |
+
|
| 27 |
+
- [ ] `.space_config.yml` - HF Spaces configuration
|
| 28 |
+
- [ ] `README_HF_SPACES.md` - User documentation (rename to README.md)
|
| 29 |
+
- [ ] `LICENSE` - License file
|
| 30 |
+
|
| 31 |
+
## Configuration
|
| 32 |
+
|
| 33 |
+
- [ ] Review default settings in `app.py`
|
| 34 |
+
- [ ] Choose model (default: distilgpt2)
|
| 35 |
+
- [ ] Set hardware tier (default: CPU Basic - Free)
|
| 36 |
+
- [ ] Configure environment variables (if needed)
|
| 37 |
+
|
| 38 |
+
### Recommended Settings for Free Tier
|
| 39 |
+
|
| 40 |
+
```yaml
|
| 41 |
+
# .space_config.yml
|
| 42 |
+
env:
|
| 43 |
+
DEFAULT_MODEL: distilgpt2
|
| 44 |
+
ENABLE_METRICS: "false"
|
| 45 |
+
LOG_LEVEL: INFO
|
| 46 |
+
ENABLE_CACHE: "true"
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
## Deployment Steps
|
| 50 |
+
|
| 51 |
+
### Method 1: Direct Upload
|
| 52 |
+
|
| 53 |
+
- [ ] Go to [huggingface.co/new-space](https://huggingface.co/new-space)
|
| 54 |
+
- [ ] Fill in Space details:
|
| 55 |
+
- [ ] Space name
|
| 56 |
+
- [ ] License: MIT
|
| 57 |
+
- [ ] SDK: Gradio
|
| 58 |
+
- [ ] Visibility: Public/Private
|
| 59 |
+
- [ ] Click "Create Space"
|
| 60 |
+
- [ ] Upload files:
|
| 61 |
+
- [ ] `app.py`
|
| 62 |
+
- [ ] `requirements.txt`
|
| 63 |
+
- [ ] `src/` folder (entire directory)
|
| 64 |
+
- [ ] `.space_config.yml`
|
| 65 |
+
- [ ] README.md (from README_HF_SPACES.md)
|
| 66 |
+
- [ ] Wait for build to complete
|
| 67 |
+
- [ ] Test the Space
|
| 68 |
+
|
| 69 |
+
### Method 2: Git Clone
|
| 70 |
+
|
| 71 |
+
- [ ] Create Space on HuggingFace
|
| 72 |
+
- [ ] Clone repository:
|
| 73 |
+
```bash
|
| 74 |
+
git clone https://huggingface.co/spaces/USERNAME/SPACE_NAME
|
| 75 |
+
```
|
| 76 |
+
- [ ] Copy files to repository
|
| 77 |
+
- [ ] Commit and push:
|
| 78 |
+
```bash
|
| 79 |
+
git add .
|
| 80 |
+
git commit -m "Initial deployment"
|
| 81 |
+
git push
|
| 82 |
+
```
|
| 83 |
+
- [ ] Monitor build in Logs tab
|
| 84 |
+
- [ ] Test the Space
|
| 85 |
+
|
| 86 |
+
## Post-Deployment Testing
|
| 87 |
+
|
| 88 |
+
- [ ] Space builds successfully
|
| 89 |
+
- [ ] App loads without errors
|
| 90 |
+
- [ ] Model loads correctly
|
| 91 |
+
- [ ] Test with sample text:
|
| 92 |
+
```
|
| 93 |
+
The quick brown fox jumps over the lazy dog. This is a sample
|
| 94 |
+
text to test the writing analysis features.
|
| 95 |
+
```
|
| 96 |
+
- [ ] Check all prompt packs work:
|
| 97 |
+
- [ ] General
|
| 98 |
+
- [ ] Literature
|
| 99 |
+
- [ ] Tech Comm
|
| 100 |
+
- [ ] Academic
|
| 101 |
+
- [ ] Creative
|
| 102 |
+
- [ ] Verify rubric scoring displays:
|
| 103 |
+
- [ ] Clarity score
|
| 104 |
+
- [ ] Conciseness score
|
| 105 |
+
- [ ] Organization score
|
| 106 |
+
- [ ] Evidence score
|
| 107 |
+
- [ ] Grammar score
|
| 108 |
+
- [ ] Check diff highlighting works
|
| 109 |
+
- [ ] Test error handling (submit empty text)
|
| 110 |
+
- [ ] Verify caching (same input twice should be instant)
|
| 111 |
+
|
| 112 |
+
## Performance Testing
|
| 113 |
+
|
| 114 |
+
- [ ] First load time acceptable (~30-60s)
|
| 115 |
+
- [ ] Subsequent loads faster (~5-10s)
|
| 116 |
+
- [ ] No memory errors
|
| 117 |
+
- [ ] No timeouts
|
| 118 |
+
- [ ] Cache working (check logs)
|
| 119 |
+
|
| 120 |
+
## Documentation
|
| 121 |
+
|
| 122 |
+
- [ ] README.md clear and helpful
|
| 123 |
+
- [ ] Examples provided
|
| 124 |
+
- [ ] Usage instructions included
|
| 125 |
+
- [ ] Troubleshooting section added
|
| 126 |
+
- [ ] Links to GitHub repo included
|
| 127 |
+
|
| 128 |
+
## Settings & Configuration
|
| 129 |
+
|
| 130 |
+
- [ ] Hardware tier selected (if not free)
|
| 131 |
+
- [ ] Environment variables set (if customizing)
|
| 132 |
+
- [ ] Sleep mode settings configured (for paid tiers)
|
| 133 |
+
- [ ] Analytics enabled (optional)
|
| 134 |
+
- [ ] Custom domain configured (optional)
|
| 135 |
+
|
| 136 |
+
## Optional Enhancements
|
| 137 |
+
|
| 138 |
+
- [ ] Add authentication (if needed)
|
| 139 |
+
- [ ] Set up custom domain
|
| 140 |
+
- [ ] Add usage examples in README
|
| 141 |
+
- [ ] Create demo video/GIF
|
| 142 |
+
- [ ] Add to HuggingFace Papers
|
| 143 |
+
- [ ] Share on social media
|
| 144 |
+
|
| 145 |
+
## Monitoring
|
| 146 |
+
|
| 147 |
+
- [ ] Check Logs tab regularly
|
| 148 |
+
- [ ] Monitor usage statistics
|
| 149 |
+
- [ ] Set up alerts (for paid tiers)
|
| 150 |
+
- [ ] Review error logs
|
| 151 |
+
- [ ] Track performance metrics
|
| 152 |
+
|
| 153 |
+
## Maintenance
|
| 154 |
+
|
| 155 |
+
- [ ] Schedule regular updates
|
| 156 |
+
- [ ] Monitor for new model releases
|
| 157 |
+
- [ ] Update dependencies periodically
|
| 158 |
+
- [ ] Review and respond to user feedback
|
| 159 |
+
- [ ] Check for security updates
|
| 160 |
+
|
| 161 |
+
## Troubleshooting Checklist
|
| 162 |
+
|
| 163 |
+
If Space doesn't work:
|
| 164 |
+
|
| 165 |
+
- [ ] Check Logs tab for errors
|
| 166 |
+
- [ ] Verify all files uploaded correctly
|
| 167 |
+
- [ ] Confirm file structure:
|
| 168 |
+
```
|
| 169 |
+
SPACE_NAME/
|
| 170 |
+
├── app.py
|
| 171 |
+
├── requirements.txt
|
| 172 |
+
└── src/
|
| 173 |
+
└── writing_studio/
|
| 174 |
+
├── core/
|
| 175 |
+
├── services/
|
| 176 |
+
└── utils/
|
| 177 |
+
```
|
| 178 |
+
- [ ] Review requirements.txt syntax
|
| 179 |
+
- [ ] Try factory reboot (Settings)
|
| 180 |
+
- [ ] Check model name spelling
|
| 181 |
+
- [ ] Verify hardware tier sufficient
|
| 182 |
+
|
| 183 |
+
## Common Issues
|
| 184 |
+
|
| 185 |
+
### Build Fails
|
| 186 |
+
- [ ] Check requirements.txt syntax
|
| 187 |
+
- [ ] Ensure app.py exists
|
| 188 |
+
- [ ] Verify Python version compatibility
|
| 189 |
+
- [ ] Check for missing dependencies
|
| 190 |
+
|
| 191 |
+
### Out of Memory
|
| 192 |
+
- [ ] Switch to smaller model (distilgpt2)
|
| 193 |
+
- [ ] Reduce cache size
|
| 194 |
+
- [ ] Upgrade hardware tier
|
| 195 |
+
- [ ] Limit text length
|
| 196 |
+
|
| 197 |
+
### Slow Performance
|
| 198 |
+
- [ ] Use distilgpt2 instead of larger models
|
| 199 |
+
- [ ] Ensure caching enabled
|
| 200 |
+
- [ ] Upgrade hardware tier
|
| 201 |
+
- [ ] Reduce generation length
|
| 202 |
+
|
| 203 |
+
### Model Not Found
|
| 204 |
+
- [ ] Check model name spelling
|
| 205 |
+
- [ ] Verify model exists on HuggingFace
|
| 206 |
+
- [ ] Check internet connectivity
|
| 207 |
+
- [ ] Try default model
|
| 208 |
+
|
| 209 |
+
## Success Criteria
|
| 210 |
+
|
| 211 |
+
Your deployment is successful when:
|
| 212 |
+
|
| 213 |
+
- [x] Space builds without errors
|
| 214 |
+
- [x] App loads in browser
|
| 215 |
+
- [x] Text analysis works correctly
|
| 216 |
+
- [x] All rubric scores display
|
| 217 |
+
- [x] Diff highlighting appears
|
| 218 |
+
- [x] Error handling works
|
| 219 |
+
- [x] Performance acceptable
|
| 220 |
+
- [x] Documentation clear
|
| 221 |
+
- [x] No critical errors in logs
|
| 222 |
+
|
| 223 |
+
## Next Steps
|
| 224 |
+
|
| 225 |
+
After successful deployment:
|
| 226 |
+
|
| 227 |
+
1. [ ] Share Space URL
|
| 228 |
+
2. [ ] Gather user feedback
|
| 229 |
+
3. [ ] Monitor performance
|
| 230 |
+
4. [ ] Plan improvements
|
| 231 |
+
5. [ ] Update documentation
|
| 232 |
+
6. [ ] Consider upgrading hardware (if needed)
|
| 233 |
+
|
| 234 |
+
## Resources
|
| 235 |
+
|
| 236 |
+
- [HuggingFace Spaces Docs](https://huggingface.co/docs/hub/spaces)
|
| 237 |
+
- [Writing Studio HF Guide](docs/HUGGINGFACE_SPACES.md)
|
| 238 |
+
- [GitHub Repository](https://github.com/yourusername/writing-studio)
|
| 239 |
+
- [User Guide](docs/USER_GUIDE.md)
|
| 240 |
+
|
| 241 |
+
## Support
|
| 242 |
+
|
| 243 |
+
Need help?
|
| 244 |
+
- Check [Troubleshooting Guide](docs/HUGGINGFACE_SPACES.md#troubleshooting)
|
| 245 |
+
- Review [HF Community Forums](https://discuss.huggingface.co/)
|
| 246 |
+
- Open [GitHub Issue](https://github.com/yourusername/writing-studio/issues)
|
| 247 |
+
|
| 248 |
+
---
|
| 249 |
+
|
| 250 |
+
**Estimated Time:** 10-15 minutes for first deployment
|
| 251 |
+
**Difficulty:** Easy
|
| 252 |
+
**Cost:** Free (with optional paid upgrades)
|
| 253 |
+
|
| 254 |
+
Good luck with your deployment! 🚀
|
HF_SPACES_README.txt
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
================================================================================
|
| 2 |
+
AI WRITING STUDIO - HUGGINGFACE SPACES READY
|
| 3 |
+
================================================================================
|
| 4 |
+
|
| 5 |
+
Your application is now fully configured for HuggingFace Spaces deployment!
|
| 6 |
+
|
| 7 |
+
QUICK START FOR HF SPACES
|
| 8 |
+
================================================================================
|
| 9 |
+
|
| 10 |
+
METHOD 1: Direct Upload (Easiest)
|
| 11 |
+
----------------------------------
|
| 12 |
+
1. Go to: https://huggingface.co/new-space
|
| 13 |
+
2. Create a Space (choose Gradio SDK)
|
| 14 |
+
3. Upload these files:
|
| 15 |
+
- app.py
|
| 16 |
+
- requirements.txt
|
| 17 |
+
- src/ (entire folder)
|
| 18 |
+
- .space_config.yml (optional)
|
| 19 |
+
- README_HF_SPACES.md → rename to README.md
|
| 20 |
+
4. Wait for build (~5 min)
|
| 21 |
+
5. Your app is live!
|
| 22 |
+
|
| 23 |
+
METHOD 2: Git (For Updates)
|
| 24 |
+
---------------------------
|
| 25 |
+
1. Create Space on HuggingFace
|
| 26 |
+
2. Clone: git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE
|
| 27 |
+
3. Copy files to cloned directory
|
| 28 |
+
4. git add . && git commit -m "Deploy" && git push
|
| 29 |
+
5. Monitor build in Logs tab
|
| 30 |
+
|
| 31 |
+
WHAT WAS ADDED FOR HF SPACES
|
| 32 |
+
================================================================================
|
| 33 |
+
|
| 34 |
+
✓ app.py - HF Spaces entry point (241 lines)
|
| 35 |
+
✓ Updated requirements.txt - HF Spaces compatible deps
|
| 36 |
+
✓ .space_config.yml - HF Spaces configuration
|
| 37 |
+
✓ README_HF_SPACES.md - User documentation for Spaces
|
| 38 |
+
✓ Config updates - Works without .env file
|
| 39 |
+
✓ HF_SPACES_CHECKLIST.md - Deployment checklist
|
| 40 |
+
✓ docs/HUGGINGFACE_SPACES.md - Complete deployment guide
|
| 41 |
+
|
| 42 |
+
KEY FEATURES FOR HF SPACES
|
| 43 |
+
================================================================================
|
| 44 |
+
|
| 45 |
+
✓ Zero configuration needed - Works out of the box
|
| 46 |
+
✓ No .env file required - Sensible defaults
|
| 47 |
+
✓ Metrics disabled by default - Not needed on HF Spaces
|
| 48 |
+
✓ Text logging - Easier to read in HF Spaces
|
| 49 |
+
✓ Fallback mode - Graceful degradation if imports fail
|
| 50 |
+
✓ Production features - All rubric scoring works
|
| 51 |
+
✓ Caching enabled - Fast repeated analyses
|
| 52 |
+
✓ Error handling - User-friendly error messages
|
| 53 |
+
|
| 54 |
+
TESTING LOCALLY (BEFORE HF SPACES)
|
| 55 |
+
================================================================================
|
| 56 |
+
|
| 57 |
+
# Install dependencies
|
| 58 |
+
pip install -r requirements.txt
|
| 59 |
+
|
| 60 |
+
# Run the app
|
| 61 |
+
python app.py
|
| 62 |
+
|
| 63 |
+
# Visit http://localhost:7860
|
| 64 |
+
|
| 65 |
+
# Test with sample text:
|
| 66 |
+
"The quick brown fox jumps over the lazy dog. This text demonstrates
|
| 67 |
+
good clarity and conciseness while maintaining proper organization."
|
| 68 |
+
|
| 69 |
+
FILES REQUIRED FOR HF SPACES
|
| 70 |
+
================================================================================
|
| 71 |
+
|
| 72 |
+
ESSENTIAL (Must upload):
|
| 73 |
+
✓ app.py
|
| 74 |
+
✓ requirements.txt
|
| 75 |
+
✓ src/writing_studio/ (entire directory with all subdirectories)
|
| 76 |
+
|
| 77 |
+
RECOMMENDED:
|
| 78 |
+
✓ .space_config.yml
|
| 79 |
+
✓ README_HF_SPACES.md (rename to README.md)
|
| 80 |
+
|
| 81 |
+
OPTIONAL:
|
| 82 |
+
- LICENSE
|
| 83 |
+
- configs/ (not needed on HF Spaces)
|
| 84 |
+
- docs/ (helpful for links)
|
| 85 |
+
|
| 86 |
+
HARDWARE RECOMMENDATIONS
|
| 87 |
+
================================================================================
|
| 88 |
+
|
| 89 |
+
FREE TIER (CPU Basic):
|
| 90 |
+
- Works with distilgpt2 (default)
|
| 91 |
+
- First load: 30-60 seconds
|
| 92 |
+
- Subsequent: 5-10 seconds
|
| 93 |
+
- Perfect for demos and testing
|
| 94 |
+
|
| 95 |
+
CPU UPGRADE ($0.10/hr):
|
| 96 |
+
- Better for gpt2
|
| 97 |
+
- Faster processing
|
| 98 |
+
- More memory
|
| 99 |
+
|
| 100 |
+
T4 GPU ($0.60/hr):
|
| 101 |
+
- Best performance
|
| 102 |
+
- Large models (gpt2-medium, gpt2-large)
|
| 103 |
+
- 2-3 second analyses
|
| 104 |
+
|
| 105 |
+
CONFIGURATION OPTIONS
|
| 106 |
+
================================================================================
|
| 107 |
+
|
| 108 |
+
Default settings (no changes needed):
|
| 109 |
+
- Model: distilgpt2
|
| 110 |
+
- Caching: Enabled
|
| 111 |
+
- Metrics: Disabled (for HF Spaces)
|
| 112 |
+
- Log Format: Text
|
| 113 |
+
- Environment: Production
|
| 114 |
+
|
| 115 |
+
To customize, add in .space_config.yml:
|
| 116 |
+
```
|
| 117 |
+
env:
|
| 118 |
+
DEFAULT_MODEL: gpt2
|
| 119 |
+
MAX_TEXT_LENGTH: "5000"
|
| 120 |
+
LOG_LEVEL: INFO
|
| 121 |
+
```
|
| 122 |
+
|
| 123 |
+
Or set in HF Spaces Settings → Variables
|
| 124 |
+
|
| 125 |
+
TROUBLESHOOTING
|
| 126 |
+
================================================================================
|
| 127 |
+
|
| 128 |
+
Build fails?
|
| 129 |
+
→ Check requirements.txt syntax
|
| 130 |
+
→ Ensure all src/ files uploaded
|
| 131 |
+
→ Review Logs tab
|
| 132 |
+
|
| 133 |
+
Out of memory?
|
| 134 |
+
→ Use distilgpt2 (smaller model)
|
| 135 |
+
→ Upgrade hardware tier
|
| 136 |
+
→ Reduce CACHE_MAX_SIZE
|
| 137 |
+
|
| 138 |
+
Slow performance?
|
| 139 |
+
→ First load is always slow (normal)
|
| 140 |
+
→ Use distilgpt2 for speed
|
| 141 |
+
→ Enable caching (default)
|
| 142 |
+
→ Upgrade hardware
|
| 143 |
+
|
| 144 |
+
Model not found?
|
| 145 |
+
→ Check spelling (distilgpt2)
|
| 146 |
+
→ Use default model
|
| 147 |
+
→ Check HuggingFace Hub
|
| 148 |
+
|
| 149 |
+
DOCUMENTATION
|
| 150 |
+
================================================================================
|
| 151 |
+
|
| 152 |
+
📄 HF_SPACES_CHECKLIST.md - Quick deployment checklist
|
| 153 |
+
📄 docs/HUGGINGFACE_SPACES.md - Complete guide (523 lines)
|
| 154 |
+
📄 README_HF_SPACES.md - For users of your Space
|
| 155 |
+
📄 README.md - Full project documentation
|
| 156 |
+
📄 docs/USER_GUIDE.md - How to use the app
|
| 157 |
+
📄 docs/ARCHITECTURE.md - Technical details
|
| 158 |
+
|
| 159 |
+
SUPPORT
|
| 160 |
+
================================================================================
|
| 161 |
+
|
| 162 |
+
Need help?
|
| 163 |
+
- Full guide: docs/HUGGINGFACE_SPACES.md
|
| 164 |
+
- Checklist: HF_SPACES_CHECKLIST.md
|
| 165 |
+
- GitHub: https://github.com/yourusername/writing-studio
|
| 166 |
+
- HF Forums: https://discuss.huggingface.co/
|
| 167 |
+
|
| 168 |
+
WHAT'S DIFFERENT FROM SELF-HOSTED
|
| 169 |
+
================================================================================
|
| 170 |
+
|
| 171 |
+
HuggingFace Spaces:
|
| 172 |
+
✓ No Docker needed
|
| 173 |
+
✓ No server setup
|
| 174 |
+
✓ Free tier available
|
| 175 |
+
✓ Auto-scaling
|
| 176 |
+
✓ SSL included
|
| 177 |
+
✓ 5 min deployment
|
| 178 |
+
✓ Automatic updates
|
| 179 |
+
|
| 180 |
+
Self-Hosted:
|
| 181 |
+
✓ Full control
|
| 182 |
+
✓ Custom domains
|
| 183 |
+
✓ Private data
|
| 184 |
+
✓ Monitoring stack
|
| 185 |
+
✓ Multiple instances
|
| 186 |
+
|
| 187 |
+
Both options fully supported!
|
| 188 |
+
|
| 189 |
+
NEXT STEPS
|
| 190 |
+
================================================================================
|
| 191 |
+
|
| 192 |
+
1. Review HF_SPACES_CHECKLIST.md
|
| 193 |
+
2. Test locally: python app.py
|
| 194 |
+
3. Create HuggingFace Space
|
| 195 |
+
4. Upload files (or git push)
|
| 196 |
+
5. Wait for build
|
| 197 |
+
6. Test your Space
|
| 198 |
+
7. Share with the world!
|
| 199 |
+
|
| 200 |
+
ESTIMATED TIME
|
| 201 |
+
================================================================================
|
| 202 |
+
|
| 203 |
+
- First-time setup: 10-15 minutes
|
| 204 |
+
- Subsequent deploys: 2-3 minutes
|
| 205 |
+
- Build time: 3-5 minutes
|
| 206 |
+
|
| 207 |
+
Total: ~20 minutes from zero to live app!
|
| 208 |
+
|
| 209 |
+
SUCCESS!
|
| 210 |
+
================================================================================
|
| 211 |
+
|
| 212 |
+
Your AI Writing Studio is ready for HuggingFace Spaces!
|
| 213 |
+
|
| 214 |
+
All production features included:
|
| 215 |
+
✓ Real rubric scoring (not mocked!)
|
| 216 |
+
✓ 5 specialized prompt packs
|
| 217 |
+
✓ Visual diff highlighting
|
| 218 |
+
✓ Comprehensive error handling
|
| 219 |
+
✓ Input validation
|
| 220 |
+
✓ Caching for performance
|
| 221 |
+
✓ Structured logging
|
| 222 |
+
|
| 223 |
+
Good luck with your deployment! 🚀
|
| 224 |
+
|
| 225 |
+
================================================================================
|
README.md
CHANGED
|
@@ -7,6 +7,20 @@
|
|
| 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 |
## Features
|
| 11 |
|
| 12 |
- **AI-Powered Revisions**: Generate text improvements using state-of-the-art language models
|
|
@@ -34,7 +48,23 @@ A production-grade AI-powered writing assistant designed for educational environ
|
|
| 34 |
|
| 35 |
## Quick Start
|
| 36 |
|
| 37 |
-
###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
```bash
|
| 40 |
# Clone the repository
|
|
@@ -307,6 +337,14 @@ This project is licensed under the MIT License - see the LICENSE file for detail
|
|
| 307 |
- Powered by [HuggingFace Transformers](https://huggingface.co/transformers/)
|
| 308 |
- Monitoring with [Prometheus](https://prometheus.io/)
|
| 309 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
## Support
|
| 311 |
|
| 312 |
- Documentation: [docs/](docs/)
|
|
|
|
| 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
|
|
|
|
| 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
|
|
|
|
| 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/)
|
README_HF_SPACES.md
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Writing Studio - HuggingFace Spaces Edition
|
| 2 |
+
|
| 3 |
+
This is the HuggingFace Spaces configuration for the AI Writing Studio.
|
| 4 |
+
|
| 5 |
+
## About
|
| 6 |
+
|
| 7 |
+
AI Writing Studio is a production-grade educational writing assistant that provides:
|
| 8 |
+
- AI-powered text revision suggestions
|
| 9 |
+
- Real rubric-based scoring (Clarity, Conciseness, Organization, Evidence, Grammar)
|
| 10 |
+
- Visual diff highlighting
|
| 11 |
+
- 5 specialized prompt packs (General, Literature, Tech Comm, Academic, Creative)
|
| 12 |
+
|
| 13 |
+
## Features
|
| 14 |
+
|
| 15 |
+
### Real Rubric Analysis
|
| 16 |
+
Unlike simple prototypes, this version includes actual analysis algorithms:
|
| 17 |
+
- **Clarity**: Analyzes sentence length, complexity, and structure
|
| 18 |
+
- **Conciseness**: Detects wordy phrases and redundancy
|
| 19 |
+
- **Organization**: Checks paragraph structure and transitions
|
| 20 |
+
- **Evidence**: Looks for supporting examples and data
|
| 21 |
+
- **Grammar**: Basic error detection
|
| 22 |
+
|
| 23 |
+
### Multiple Prompt Packs
|
| 24 |
+
Choose from specialized templates:
|
| 25 |
+
- **General**: Everyday writing
|
| 26 |
+
- **Literature**: Literary analysis
|
| 27 |
+
- **Tech Comm**: Technical documentation
|
| 28 |
+
- **Academic**: Research papers
|
| 29 |
+
- **Creative**: Stories and creative writing
|
| 30 |
+
|
| 31 |
+
### Production Quality
|
| 32 |
+
- Comprehensive error handling
|
| 33 |
+
- Input validation and sanitization
|
| 34 |
+
- Structured logging
|
| 35 |
+
- Caching for faster responses
|
| 36 |
+
- Type-safe configuration
|
| 37 |
+
|
| 38 |
+
## Usage
|
| 39 |
+
|
| 40 |
+
1. **Paste your text** in the input box
|
| 41 |
+
2. **Select a model** (distilgpt2 is fastest, gpt2 has better quality)
|
| 42 |
+
3. **Choose a prompt pack** matching your writing context
|
| 43 |
+
4. **Click "Analyze & Compare"** to get feedback
|
| 44 |
+
|
| 45 |
+
### Tips
|
| 46 |
+
|
| 47 |
+
- First analysis may take 30-60 seconds (model loading)
|
| 48 |
+
- Subsequent analyses are much faster (caching)
|
| 49 |
+
- Start with shorter texts for quicker results
|
| 50 |
+
- Try different prompt packs for varied perspectives
|
| 51 |
+
- Use the rubric feedback to learn and improve
|
| 52 |
+
|
| 53 |
+
## Models
|
| 54 |
+
|
| 55 |
+
**Default: distilgpt2**
|
| 56 |
+
- Fast and efficient
|
| 57 |
+
- Works well on free tier
|
| 58 |
+
- Good for most use cases
|
| 59 |
+
|
| 60 |
+
**Alternative: gpt2**
|
| 61 |
+
- Better quality revisions
|
| 62 |
+
- Slower processing
|
| 63 |
+
- May need upgraded hardware on HF Spaces
|
| 64 |
+
|
| 65 |
+
**Advanced: gpt2-medium, gpt2-large**
|
| 66 |
+
- Best quality
|
| 67 |
+
- Significantly slower
|
| 68 |
+
- Requires upgraded HF Spaces hardware
|
| 69 |
+
|
| 70 |
+
## Performance
|
| 71 |
+
|
| 72 |
+
### Hardware Recommendations
|
| 73 |
+
|
| 74 |
+
**Free Tier (CPU Basic)**
|
| 75 |
+
- Works with distilgpt2
|
| 76 |
+
- First load: ~30-60s
|
| 77 |
+
- Subsequent: ~5-10s per analysis
|
| 78 |
+
|
| 79 |
+
**CPU Upgrade**
|
| 80 |
+
- Handles gpt2 well
|
| 81 |
+
- First load: ~45s
|
| 82 |
+
- Subsequent: ~8-15s
|
| 83 |
+
|
| 84 |
+
**T4 GPU**
|
| 85 |
+
- Best performance
|
| 86 |
+
- First load: ~20s
|
| 87 |
+
- Subsequent: ~2-5s
|
| 88 |
+
|
| 89 |
+
### Optimization
|
| 90 |
+
|
| 91 |
+
The app includes several optimizations:
|
| 92 |
+
- Model caching (loaded once, reused)
|
| 93 |
+
- Result caching (same input = instant response)
|
| 94 |
+
- Lazy loading of services
|
| 95 |
+
- Efficient text processing
|
| 96 |
+
|
| 97 |
+
## Configuration
|
| 98 |
+
|
| 99 |
+
The app works out-of-the-box with sensible defaults. To customize:
|
| 100 |
+
|
| 101 |
+
### Via HuggingFace Spaces Settings
|
| 102 |
+
|
| 103 |
+
Go to Settings → Variables and add:
|
| 104 |
+
|
| 105 |
+
```
|
| 106 |
+
DEFAULT_MODEL=gpt2
|
| 107 |
+
LOG_LEVEL=DEBUG
|
| 108 |
+
MAX_TEXT_LENGTH=5000
|
| 109 |
+
ENABLE_CACHE=true
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
### Via .space_config.yml
|
| 113 |
+
|
| 114 |
+
Edit `.space_config.yml`:
|
| 115 |
+
|
| 116 |
+
```yaml
|
| 117 |
+
env:
|
| 118 |
+
DEFAULT_MODEL: gpt2
|
| 119 |
+
LOG_LEVEL: INFO
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
## Troubleshooting
|
| 123 |
+
|
| 124 |
+
### "Out of Memory" Error
|
| 125 |
+
- Use a smaller model (distilgpt2)
|
| 126 |
+
- Upgrade to better hardware
|
| 127 |
+
- Reduce text length
|
| 128 |
+
|
| 129 |
+
### Slow First Load
|
| 130 |
+
- Normal behavior (model downloading)
|
| 131 |
+
- Subsequent loads are much faster
|
| 132 |
+
- Consider upgrading hardware tier
|
| 133 |
+
|
| 134 |
+
### "Model Loading Failed"
|
| 135 |
+
- Check model name spelling
|
| 136 |
+
- Ensure internet connectivity
|
| 137 |
+
- Try default model (distilgpt2)
|
| 138 |
+
|
| 139 |
+
### Unexpected Results
|
| 140 |
+
- Try different prompt pack
|
| 141 |
+
- Check input text quality
|
| 142 |
+
- Remember: AI suggestions aren't perfect
|
| 143 |
+
|
| 144 |
+
## Privacy
|
| 145 |
+
|
| 146 |
+
- Text processed in-memory only
|
| 147 |
+
- Results cached temporarily for speed
|
| 148 |
+
- No long-term storage on HF Spaces
|
| 149 |
+
- No user tracking
|
| 150 |
+
|
| 151 |
+
## Source Code
|
| 152 |
+
|
| 153 |
+
Full source code available at: [GitHub Repository](https://github.com/yourusername/writing-studio)
|
| 154 |
+
|
| 155 |
+
### Architecture
|
| 156 |
+
|
| 157 |
+
```
|
| 158 |
+
src/writing_studio/
|
| 159 |
+
├── core/ # Business logic
|
| 160 |
+
├── services/ # AI, Rubric, Diff, Prompt services
|
| 161 |
+
├── utils/ # Logging, validation, metrics
|
| 162 |
+
└── main.py # Production entry point
|
| 163 |
+
```
|
| 164 |
+
|
| 165 |
+
### Local Development
|
| 166 |
+
|
| 167 |
+
```bash
|
| 168 |
+
git clone https://github.com/yourusername/writing-studio
|
| 169 |
+
cd writing-studio
|
| 170 |
+
pip install -r requirements.txt
|
| 171 |
+
python app.py
|
| 172 |
+
```
|
| 173 |
+
|
| 174 |
+
## Contributing
|
| 175 |
+
|
| 176 |
+
Contributions welcome! See [GitHub](https://github.com/yourusername/writing-studio) for:
|
| 177 |
+
- Full documentation
|
| 178 |
+
- Development setup
|
| 179 |
+
- Testing guidelines
|
| 180 |
+
- Code quality standards
|
| 181 |
+
|
| 182 |
+
## License
|
| 183 |
+
|
| 184 |
+
MIT License - See LICENSE file
|
| 185 |
+
|
| 186 |
+
## Acknowledgments
|
| 187 |
+
|
| 188 |
+
- Built with [Gradio](https://gradio.app/)
|
| 189 |
+
- Powered by [HuggingFace Transformers](https://huggingface.co/transformers/)
|
| 190 |
+
- Hosted on [HuggingFace Spaces](https://huggingface.co/spaces)
|
| 191 |
+
|
| 192 |
+
## Support
|
| 193 |
+
|
| 194 |
+
- Issues: [GitHub Issues](https://github.com/yourusername/writing-studio/issues)
|
| 195 |
+
- Documentation: [GitHub Docs](https://github.com/yourusername/writing-studio/tree/main/docs)
|
| 196 |
+
- Questions: [GitHub Discussions](https://github.com/yourusername/writing-studio/discussions)
|
app.py
CHANGED
|
@@ -1,56 +1,241 @@
|
|
| 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 |
-
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
HuggingFace Spaces Entry Point
|
| 3 |
+
|
| 4 |
+
This file is the entry point for HuggingFace Spaces deployment.
|
| 5 |
+
It imports and launches the production-grade Writing Studio application.
|
| 6 |
+
|
| 7 |
+
For local development or self-hosted deployment, you can also use:
|
| 8 |
+
python -m writing_studio.main
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import os
|
| 12 |
+
import sys
|
| 13 |
+
|
| 14 |
+
# Add src to path for imports
|
| 15 |
+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src"))
|
| 16 |
+
|
| 17 |
+
# Set HuggingFace Spaces friendly defaults
|
| 18 |
+
os.environ.setdefault("ENVIRONMENT", "production")
|
| 19 |
+
os.environ.setdefault("DEBUG", "false")
|
| 20 |
+
os.environ.setdefault("LOG_LEVEL", "INFO")
|
| 21 |
+
os.environ.setdefault("ENABLE_METRICS", "false") # Disable metrics server on HF Spaces
|
| 22 |
+
os.environ.setdefault("LOG_FORMAT", "text") # Text logs are easier to read on HF Spaces
|
| 23 |
+
|
| 24 |
+
try:
|
| 25 |
+
# Try to import the production application
|
| 26 |
+
from writing_studio.core.analyzer import WritingAnalyzer
|
| 27 |
+
from writing_studio.core.config import settings
|
| 28 |
+
from writing_studio.core.exceptions import WritingStudioException
|
| 29 |
+
from writing_studio.utils.logging import logger
|
| 30 |
+
import gradio as gr
|
| 31 |
+
|
| 32 |
+
logger.info(f"Starting {settings.app_name} v{settings.app_version}")
|
| 33 |
+
logger.info(f"Environment: {settings.environment}")
|
| 34 |
+
|
| 35 |
+
def create_interface() -> gr.Blocks:
|
| 36 |
+
"""Create production-grade Gradio interface for HuggingFace Spaces."""
|
| 37 |
+
analyzer = WritingAnalyzer()
|
| 38 |
+
|
| 39 |
+
def analyze_wrapper(user_input: str, model_name: str, prompt_pack: str) -> tuple:
|
| 40 |
+
"""Wrapper for analysis with error handling."""
|
| 41 |
+
try:
|
| 42 |
+
if not user_input or not user_input.strip():
|
| 43 |
+
return (
|
| 44 |
+
"",
|
| 45 |
+
"",
|
| 46 |
+
"⚠️ Please provide some text to analyze.",
|
| 47 |
+
"",
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
original, revision, feedback, diff_html, metadata = analyzer.analyze_and_compare(
|
| 51 |
+
user_input, model_name, prompt_pack
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
# Format feedback with metadata
|
| 55 |
+
feedback_with_meta = f"{feedback}\n\n---\n⏱️ Processing time: {metadata['duration']:.2f}s\n🤖 Model: {metadata['model']}"
|
| 56 |
+
|
| 57 |
+
return original, revision, feedback_with_meta, diff_html
|
| 58 |
+
|
| 59 |
+
except WritingStudioException as e:
|
| 60 |
+
error_msg = f"❌ Error: {e.message}"
|
| 61 |
+
if e.details:
|
| 62 |
+
error_msg += f"\n\nℹ️ Details: {e.details}"
|
| 63 |
+
logger.error(f"Analysis failed: {error_msg}")
|
| 64 |
+
return "", "", error_msg, ""
|
| 65 |
+
|
| 66 |
+
except Exception as e:
|
| 67 |
+
error_msg = f"❌ Unexpected error: {str(e)}"
|
| 68 |
+
logger.error(f"Unexpected error in analysis: {e}", exc_info=True)
|
| 69 |
+
return "", "", error_msg, ""
|
| 70 |
+
|
| 71 |
+
# Create Gradio interface
|
| 72 |
+
with gr.Blocks(
|
| 73 |
+
title=settings.app_name,
|
| 74 |
+
theme=gr.themes.Soft(),
|
| 75 |
+
) as demo:
|
| 76 |
+
gr.Markdown(
|
| 77 |
+
f"""
|
| 78 |
+
# ✍️ {settings.app_name}
|
| 79 |
+
|
| 80 |
+
Compare drafts, get rubric-based feedback, and reflect on revisions.
|
| 81 |
+
|
| 82 |
+
**Features:**
|
| 83 |
+
- 🎯 Real rubric scoring (Clarity, Conciseness, Organization, Evidence, Grammar)
|
| 84 |
+
- 🔄 AI-powered revision suggestions
|
| 85 |
+
- 📊 Visual diff highlighting
|
| 86 |
+
- 📝 5 specialized prompt packs
|
| 87 |
+
|
| 88 |
+
**Version:** {settings.app_version} | **Environment:** {settings.environment}
|
| 89 |
+
"""
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
with gr.Row():
|
| 93 |
+
with gr.Column(scale=2):
|
| 94 |
+
user_input = gr.Textbox(
|
| 95 |
+
lines=10,
|
| 96 |
+
placeholder="Paste your draft here...",
|
| 97 |
+
label="Your Draft",
|
| 98 |
+
info=f"Maximum {settings.max_text_length:,} characters",
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
with gr.Column(scale=1):
|
| 102 |
+
model_name = gr.Textbox(
|
| 103 |
+
value=settings.default_model,
|
| 104 |
+
label="Model (HuggingFace ID)",
|
| 105 |
+
info="e.g., distilgpt2, gpt2",
|
| 106 |
+
)
|
| 107 |
+
prompt_pack = gr.Dropdown(
|
| 108 |
+
choices=analyzer.get_available_prompt_packs(),
|
| 109 |
+
value="General",
|
| 110 |
+
label="Prompt Pack",
|
| 111 |
+
info="Select the writing context",
|
| 112 |
+
)
|
| 113 |
+
run_btn = gr.Button("✨ Analyze & Compare", variant="primary", size="lg")
|
| 114 |
+
|
| 115 |
+
gr.Markdown("## 📊 Results")
|
| 116 |
+
|
| 117 |
+
with gr.Row():
|
| 118 |
+
original = gr.Textbox(
|
| 119 |
+
lines=12,
|
| 120 |
+
label="📄 Original Draft",
|
| 121 |
+
interactive=False,
|
| 122 |
+
)
|
| 123 |
+
revision = gr.Textbox(
|
| 124 |
+
lines=12,
|
| 125 |
+
label="🤖 AI Suggested Revision",
|
| 126 |
+
interactive=False,
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
feedback = gr.Textbox(
|
| 130 |
+
lines=10,
|
| 131 |
+
label="📝 Rubric Feedback",
|
| 132 |
+
info="Detailed analysis based on writing criteria",
|
| 133 |
+
interactive=False,
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
if settings.enable_diff_highlighting:
|
| 137 |
+
diff_html = gr.HTML(label="🔍 Highlighted Differences")
|
| 138 |
+
else:
|
| 139 |
+
diff_html = gr.HTML(visible=False)
|
| 140 |
+
|
| 141 |
+
# Wire up the button
|
| 142 |
+
run_btn.click(
|
| 143 |
+
fn=analyze_wrapper,
|
| 144 |
+
inputs=[user_input, model_name, prompt_pack],
|
| 145 |
+
outputs=[original, revision, feedback, diff_html],
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
# Add footer
|
| 149 |
+
gr.Markdown(
|
| 150 |
+
"""
|
| 151 |
+
---
|
| 152 |
+
|
| 153 |
+
### 💡 Tips
|
| 154 |
+
|
| 155 |
+
- Start with shorter texts for faster results
|
| 156 |
+
- Try different prompt packs for specialized feedback
|
| 157 |
+
- Review the rubric feedback to understand strengths and areas for improvement
|
| 158 |
+
- The first analysis may take 30-60s as the model loads (subsequent analyses are faster)
|
| 159 |
+
|
| 160 |
+
### 📚 Documentation
|
| 161 |
+
|
| 162 |
+
- [User Guide](https://github.com/yourusername/writing-studio/blob/main/docs/USER_GUIDE.md)
|
| 163 |
+
- [Architecture](https://github.com/yourusername/writing-studio/blob/main/docs/ARCHITECTURE.md)
|
| 164 |
+
- [GitHub Repository](https://github.com/yourusername/writing-studio)
|
| 165 |
+
|
| 166 |
+
---
|
| 167 |
+
|
| 168 |
+
Built with ❤️ using [Gradio](https://gradio.app/) and [HuggingFace Transformers](https://huggingface.co/transformers/)
|
| 169 |
+
"""
|
| 170 |
+
)
|
| 171 |
+
|
| 172 |
+
return demo
|
| 173 |
+
|
| 174 |
+
# Create and launch the interface
|
| 175 |
+
demo = create_interface()
|
| 176 |
+
|
| 177 |
+
# Launch with HuggingFace Spaces friendly settings
|
| 178 |
+
if __name__ == "__main__":
|
| 179 |
+
demo.launch(
|
| 180 |
+
server_name="0.0.0.0",
|
| 181 |
+
server_port=7860,
|
| 182 |
+
share=False,
|
| 183 |
+
show_error=True,
|
| 184 |
+
)
|
| 185 |
+
|
| 186 |
+
except ImportError as e:
|
| 187 |
+
# Fallback to simple version if production code not available
|
| 188 |
+
print(f"Warning: Could not import production code: {e}")
|
| 189 |
+
print("Falling back to simple version...")
|
| 190 |
+
|
| 191 |
+
import gradio as gr
|
| 192 |
+
from transformers import pipeline
|
| 193 |
+
import difflib
|
| 194 |
+
|
| 195 |
+
# Simple version for emergency fallback
|
| 196 |
+
generator = pipeline("text-generation", model="distilgpt2")
|
| 197 |
+
|
| 198 |
+
def simple_analyze(user_text, model_name="distilgpt2"):
|
| 199 |
+
"""Simple analysis function."""
|
| 200 |
+
if not user_text:
|
| 201 |
+
return "", "", "Please provide some text.", ""
|
| 202 |
+
|
| 203 |
+
try:
|
| 204 |
+
prompt = f"Revise this text for clarity:\n{user_text}"
|
| 205 |
+
revision = generator(prompt, max_length=300, num_return_sequences=1, do_sample=True)[0]["generated_text"]
|
| 206 |
+
|
| 207 |
+
feedback = "⚠️ Running in fallback mode. Install full version for rubric scoring."
|
| 208 |
+
|
| 209 |
+
diff = difflib.HtmlDiff().make_table(
|
| 210 |
+
user_text.splitlines(), revision.splitlines(),
|
| 211 |
+
fromdesc="Original", todesc="AI Revision"
|
| 212 |
+
)
|
| 213 |
+
|
| 214 |
+
return user_text, revision, feedback, diff
|
| 215 |
+
except Exception as e:
|
| 216 |
+
return "", "", f"Error: {str(e)}", ""
|
| 217 |
+
|
| 218 |
+
with gr.Blocks() as demo:
|
| 219 |
+
gr.Markdown("# ✍️ AI Writing Studio (Simplified)")
|
| 220 |
+
gr.Markdown("⚠️ Running in fallback mode. Some features may be limited.")
|
| 221 |
+
|
| 222 |
+
with gr.Row():
|
| 223 |
+
user_input = gr.Textbox(lines=10, placeholder="Paste your draft here...")
|
| 224 |
+
model_name = gr.Textbox(value="distilgpt2", label="Model")
|
| 225 |
+
|
| 226 |
+
with gr.Row():
|
| 227 |
+
original = gr.Textbox(lines=12, label="Original")
|
| 228 |
+
revision = gr.Textbox(lines=12, label="Revision")
|
| 229 |
+
|
| 230 |
+
feedback = gr.Textbox(lines=8, label="Feedback")
|
| 231 |
+
diff_html = gr.HTML(label="Diff")
|
| 232 |
+
|
| 233 |
+
run_btn = gr.Button("Analyze")
|
| 234 |
+
run_btn.click(
|
| 235 |
+
fn=simple_analyze,
|
| 236 |
+
inputs=[user_input, model_name],
|
| 237 |
+
outputs=[original, revision, feedback, diff_html]
|
| 238 |
+
)
|
| 239 |
+
|
| 240 |
+
if __name__ == "__main__":
|
| 241 |
+
demo.launch()
|
docs/HUGGINGFACE_SPACES.md
ADDED
|
@@ -0,0 +1,523 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# HuggingFace Spaces Deployment Guide
|
| 2 |
+
|
| 3 |
+
## Overview
|
| 4 |
+
|
| 5 |
+
This guide explains how to deploy Writing Studio on HuggingFace Spaces for free, public access to your AI writing assistant.
|
| 6 |
+
|
| 7 |
+
## Prerequisites
|
| 8 |
+
|
| 9 |
+
- HuggingFace account ([sign up free](https://huggingface.co/join))
|
| 10 |
+
- Basic familiarity with Git (optional for direct upload)
|
| 11 |
+
|
| 12 |
+
## Quick Deploy
|
| 13 |
+
|
| 14 |
+
### Method 1: Direct Upload (Easiest)
|
| 15 |
+
|
| 16 |
+
1. **Create a Space**
|
| 17 |
+
- Go to [huggingface.co/new-space](https://huggingface.co/new-space)
|
| 18 |
+
- Name your Space (e.g., "writing-studio")
|
| 19 |
+
- Choose **Gradio** as SDK
|
| 20 |
+
- Select visibility (Public or Private)
|
| 21 |
+
- Click "Create Space"
|
| 22 |
+
|
| 23 |
+
2. **Upload Files**
|
| 24 |
+
- Click "Files" tab
|
| 25 |
+
- Upload these essential files:
|
| 26 |
+
- `app.py`
|
| 27 |
+
- `requirements.txt`
|
| 28 |
+
- `src/` folder (entire directory)
|
| 29 |
+
- `.space_config.yml` (optional)
|
| 30 |
+
- `README_HF_SPACES.md` (rename to README.md)
|
| 31 |
+
|
| 32 |
+
3. **Wait for Build**
|
| 33 |
+
- HuggingFace automatically detects `app.py` and `requirements.txt`
|
| 34 |
+
- First build takes 3-5 minutes (installing dependencies)
|
| 35 |
+
- Your Space will be live at: `https://huggingface.co/spaces/USERNAME/SPACE_NAME`
|
| 36 |
+
|
| 37 |
+
### Method 2: Git Clone (Recommended for Updates)
|
| 38 |
+
|
| 39 |
+
1. **Create a Space** (as above)
|
| 40 |
+
|
| 41 |
+
2. **Clone Locally**
|
| 42 |
+
```bash
|
| 43 |
+
git clone https://huggingface.co/spaces/USERNAME/SPACE_NAME
|
| 44 |
+
cd SPACE_NAME
|
| 45 |
+
```
|
| 46 |
+
|
| 47 |
+
3. **Copy Files**
|
| 48 |
+
```bash
|
| 49 |
+
# From your WritingStudio directory
|
| 50 |
+
cp -r src/ app.py requirements.txt .space_config.yml /path/to/SPACE_NAME/
|
| 51 |
+
cp README_HF_SPACES.md /path/to/SPACE_NAME/README.md
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
4. **Push to Space**
|
| 55 |
+
```bash
|
| 56 |
+
cd /path/to/SPACE_NAME
|
| 57 |
+
git add .
|
| 58 |
+
git commit -m "Initial deployment"
|
| 59 |
+
git push
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
5. **Monitor Build**
|
| 63 |
+
- Go to your Space URL
|
| 64 |
+
- Check "Logs" tab for build progress
|
| 65 |
+
- App will be live when build completes
|
| 66 |
+
|
| 67 |
+
### Method 3: Duplicate an Existing Space
|
| 68 |
+
|
| 69 |
+
If someone has already deployed Writing Studio:
|
| 70 |
+
|
| 71 |
+
1. Go to their Space
|
| 72 |
+
2. Click "⋯" menu → "Duplicate this Space"
|
| 73 |
+
3. Choose your username and Space name
|
| 74 |
+
4. Click "Duplicate Space"
|
| 75 |
+
5. Done! Your own copy is live
|
| 76 |
+
|
| 77 |
+
## Configuration
|
| 78 |
+
|
| 79 |
+
### Default Settings
|
| 80 |
+
|
| 81 |
+
Works out-of-the-box with:
|
| 82 |
+
- Model: `distilgpt2` (fast, lightweight)
|
| 83 |
+
- Log Level: `INFO`
|
| 84 |
+
- Metrics: Disabled (not needed on HF Spaces)
|
| 85 |
+
- Caching: Enabled
|
| 86 |
+
- All rubric features: Enabled
|
| 87 |
+
|
| 88 |
+
### Custom Configuration
|
| 89 |
+
|
| 90 |
+
#### Option A: Environment Variables
|
| 91 |
+
|
| 92 |
+
In your Space:
|
| 93 |
+
1. Go to Settings
|
| 94 |
+
2. Scroll to "Repository secrets"
|
| 95 |
+
3. Add variables:
|
| 96 |
+
|
| 97 |
+
```
|
| 98 |
+
DEFAULT_MODEL=gpt2
|
| 99 |
+
LOG_LEVEL=DEBUG
|
| 100 |
+
MAX_TEXT_LENGTH=5000
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
#### Option B: Edit .space_config.yml
|
| 104 |
+
|
| 105 |
+
```yaml
|
| 106 |
+
env:
|
| 107 |
+
DEFAULT_MODEL: gpt2
|
| 108 |
+
LOG_LEVEL: INFO
|
| 109 |
+
ENABLE_CACHE: "true"
|
| 110 |
+
MAX_TEXT_LENGTH: "5000"
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
Commit and push changes.
|
| 114 |
+
|
| 115 |
+
## Hardware Selection
|
| 116 |
+
|
| 117 |
+
### Free Tier (CPU Basic)
|
| 118 |
+
|
| 119 |
+
**Best for:**
|
| 120 |
+
- Testing and demos
|
| 121 |
+
- Small models (distilgpt2)
|
| 122 |
+
- Light usage
|
| 123 |
+
|
| 124 |
+
**Performance:**
|
| 125 |
+
- First load: ~30-60s
|
| 126 |
+
- Subsequent: ~5-10s per analysis
|
| 127 |
+
- Memory: 16GB RAM
|
| 128 |
+
- Storage: Unlimited
|
| 129 |
+
|
| 130 |
+
**Limitations:**
|
| 131 |
+
- Slower processing
|
| 132 |
+
- May timeout on large models
|
| 133 |
+
|
| 134 |
+
### CPU Upgrade (Paid)
|
| 135 |
+
|
| 136 |
+
**Best for:**
|
| 137 |
+
- Production use
|
| 138 |
+
- Medium models (gpt2)
|
| 139 |
+
- Regular users
|
| 140 |
+
|
| 141 |
+
**Performance:**
|
| 142 |
+
- First load: ~20-45s
|
| 143 |
+
- Subsequent: ~3-8s
|
| 144 |
+
- More CPU cores
|
| 145 |
+
- Better throughput
|
| 146 |
+
|
| 147 |
+
**Cost:** ~$0.10/hour
|
| 148 |
+
|
| 149 |
+
### T4 Small GPU (Paid)
|
| 150 |
+
|
| 151 |
+
**Best for:**
|
| 152 |
+
- Best performance
|
| 153 |
+
- Large models (gpt2-medium, gpt2-large)
|
| 154 |
+
- High traffic
|
| 155 |
+
|
| 156 |
+
**Performance:**
|
| 157 |
+
- First load: ~15-30s
|
| 158 |
+
- Subsequent: ~1-3s
|
| 159 |
+
- GPU acceleration
|
| 160 |
+
- Fastest generation
|
| 161 |
+
|
| 162 |
+
**Cost:** ~$0.60/hour
|
| 163 |
+
|
| 164 |
+
### Recommendation
|
| 165 |
+
|
| 166 |
+
Start with **Free Tier + distilgpt2**:
|
| 167 |
+
- Works well for most use cases
|
| 168 |
+
- Zero cost
|
| 169 |
+
- Upgrade only if needed
|
| 170 |
+
|
| 171 |
+
## Model Selection
|
| 172 |
+
|
| 173 |
+
### distilgpt2 (Default)
|
| 174 |
+
- **Size:** 82M parameters
|
| 175 |
+
- **Speed:** Fast
|
| 176 |
+
- **Quality:** Good
|
| 177 |
+
- **Free Tier:** ✅ Works great
|
| 178 |
+
- **Recommended for:** Most users
|
| 179 |
+
|
| 180 |
+
### gpt2
|
| 181 |
+
- **Size:** 124M parameters
|
| 182 |
+
- **Speed:** Medium
|
| 183 |
+
- **Quality:** Better
|
| 184 |
+
- **Free Tier:** ✅ Works (slower)
|
| 185 |
+
- **Recommended for:** CPU Upgrade tier
|
| 186 |
+
|
| 187 |
+
### gpt2-medium
|
| 188 |
+
- **Size:** 355M parameters
|
| 189 |
+
- **Speed:** Slower
|
| 190 |
+
- **Quality:** Great
|
| 191 |
+
- **Free Tier:** ⚠️ May timeout
|
| 192 |
+
- **Recommended for:** T4 GPU tier
|
| 193 |
+
|
| 194 |
+
### gpt2-large
|
| 195 |
+
- **Size:** 774M parameters
|
| 196 |
+
- **Speed:** Slowest
|
| 197 |
+
- **Quality:** Best
|
| 198 |
+
- **Free Tier:** ❌ Not recommended
|
| 199 |
+
- **Recommended for:** T4 GPU tier
|
| 200 |
+
|
| 201 |
+
## Optimization Tips
|
| 202 |
+
|
| 203 |
+
### 1. Enable Caching (Default)
|
| 204 |
+
Results are cached automatically:
|
| 205 |
+
- Same input = instant result
|
| 206 |
+
- Reduces compute time
|
| 207 |
+
- Saves hardware costs
|
| 208 |
+
|
| 209 |
+
### 2. Use Smaller Models
|
| 210 |
+
For free tier:
|
| 211 |
+
```yaml
|
| 212 |
+
env:
|
| 213 |
+
DEFAULT_MODEL: distilgpt2
|
| 214 |
+
```
|
| 215 |
+
|
| 216 |
+
### 3. Limit Text Length
|
| 217 |
+
Prevent timeouts:
|
| 218 |
+
```yaml
|
| 219 |
+
env:
|
| 220 |
+
MAX_TEXT_LENGTH: "3000" # Shorter = faster
|
| 221 |
+
```
|
| 222 |
+
|
| 223 |
+
### 4. Adjust Generation Length
|
| 224 |
+
Faster processing:
|
| 225 |
+
```yaml
|
| 226 |
+
env:
|
| 227 |
+
DEFAULT_MAX_LENGTH: "200" # Instead of 300
|
| 228 |
+
```
|
| 229 |
+
|
| 230 |
+
## Monitoring
|
| 231 |
+
|
| 232 |
+
### Check Logs
|
| 233 |
+
|
| 234 |
+
1. Go to your Space
|
| 235 |
+
2. Click "Logs" tab
|
| 236 |
+
3. View real-time logs
|
| 237 |
+
|
| 238 |
+
Look for:
|
| 239 |
+
- `INFO` - Normal operations
|
| 240 |
+
- `WARNING` - Potential issues
|
| 241 |
+
- `ERROR` - Problems to fix
|
| 242 |
+
|
| 243 |
+
### Usage Stats
|
| 244 |
+
|
| 245 |
+
HuggingFace provides:
|
| 246 |
+
- View count
|
| 247 |
+
- Unique visitors
|
| 248 |
+
- Uptime status
|
| 249 |
+
|
| 250 |
+
Available in Space settings.
|
| 251 |
+
|
| 252 |
+
## Troubleshooting
|
| 253 |
+
|
| 254 |
+
### Build Fails
|
| 255 |
+
|
| 256 |
+
**Problem:** Space doesn't build
|
| 257 |
+
|
| 258 |
+
**Solutions:**
|
| 259 |
+
1. Check `requirements.txt` syntax
|
| 260 |
+
2. Ensure `app.py` exists
|
| 261 |
+
3. Check Logs tab for errors
|
| 262 |
+
4. Verify file structure:
|
| 263 |
+
```
|
| 264 |
+
SPACE_NAME/
|
| 265 |
+
├── app.py
|
| 266 |
+
├── requirements.txt
|
| 267 |
+
├── src/
|
| 268 |
+
│ └── writing_studio/
|
| 269 |
+
│ ├── core/
|
| 270 |
+
│ ├── services/
|
| 271 |
+
│ └── utils/
|
| 272 |
+
```
|
| 273 |
+
|
| 274 |
+
### Out of Memory
|
| 275 |
+
|
| 276 |
+
**Problem:** "CUDA out of memory" or crashes
|
| 277 |
+
|
| 278 |
+
**Solutions:**
|
| 279 |
+
1. Use smaller model:
|
| 280 |
+
```python
|
| 281 |
+
DEFAULT_MODEL=distilgpt2
|
| 282 |
+
```
|
| 283 |
+
2. Reduce cache size:
|
| 284 |
+
```python
|
| 285 |
+
CACHE_MAX_SIZE=50
|
| 286 |
+
```
|
| 287 |
+
3. Upgrade to larger hardware tier
|
| 288 |
+
|
| 289 |
+
### Slow Performance
|
| 290 |
+
|
| 291 |
+
**Problem:** Analysis takes too long
|
| 292 |
+
|
| 293 |
+
**Solutions:**
|
| 294 |
+
1. First load is always slow (model download)
|
| 295 |
+
2. Use distilgpt2 for faster results
|
| 296 |
+
3. Upgrade hardware tier
|
| 297 |
+
4. Reduce text length
|
| 298 |
+
5. Check cache is enabled
|
| 299 |
+
|
| 300 |
+
### Model Not Found
|
| 301 |
+
|
| 302 |
+
**Problem:** "Model ... not found"
|
| 303 |
+
|
| 304 |
+
**Solutions:**
|
| 305 |
+
1. Check model name spelling
|
| 306 |
+
2. Verify model exists on HuggingFace Hub
|
| 307 |
+
3. Try default: `distilgpt2`
|
| 308 |
+
4. Check internet connectivity
|
| 309 |
+
|
| 310 |
+
### Import Errors
|
| 311 |
+
|
| 312 |
+
**Problem:** "ModuleNotFoundError"
|
| 313 |
+
|
| 314 |
+
**Solutions:**
|
| 315 |
+
1. Ensure all files uploaded
|
| 316 |
+
2. Check `src/` directory structure
|
| 317 |
+
3. Verify `requirements.txt` has all dependencies
|
| 318 |
+
4. Rebuild Space (Settings → Factory reboot)
|
| 319 |
+
|
| 320 |
+
## Best Practices
|
| 321 |
+
|
| 322 |
+
### 1. Use README_HF_SPACES.md
|
| 323 |
+
|
| 324 |
+
Rename to `README.md` in your Space:
|
| 325 |
+
```bash
|
| 326 |
+
cp README_HF_SPACES.md README.md
|
| 327 |
+
```
|
| 328 |
+
|
| 329 |
+
This provides users with:
|
| 330 |
+
- Usage instructions
|
| 331 |
+
- Model selection guide
|
| 332 |
+
- Troubleshooting help
|
| 333 |
+
|
| 334 |
+
### 2. Add Examples
|
| 335 |
+
|
| 336 |
+
In your Space README, add example texts:
|
| 337 |
+
|
| 338 |
+
````markdown
|
| 339 |
+
## Example Usage
|
| 340 |
+
|
| 341 |
+
Try analyzing this text:
|
| 342 |
+
|
| 343 |
+
```
|
| 344 |
+
The quick brown fox jumps over the lazy dog. This sentence
|
| 345 |
+
demonstrates pangram characteristics while maintaining
|
| 346 |
+
grammatical coherence.
|
| 347 |
+
```
|
| 348 |
+
````
|
| 349 |
+
|
| 350 |
+
### 3. Set Visibility
|
| 351 |
+
|
| 352 |
+
**Public Spaces:**
|
| 353 |
+
- Visible to everyone
|
| 354 |
+
- Searchable
|
| 355 |
+
- Can be featured
|
| 356 |
+
- Free community tier
|
| 357 |
+
|
| 358 |
+
**Private Spaces:**
|
| 359 |
+
- Only visible to you
|
| 360 |
+
- Not searchable
|
| 361 |
+
- Requires paid tier
|
| 362 |
+
|
| 363 |
+
### 4. Monitor Costs
|
| 364 |
+
|
| 365 |
+
If using paid tiers:
|
| 366 |
+
1. Go to Settings → Billing
|
| 367 |
+
2. Set spending limits
|
| 368 |
+
3. Monitor usage
|
| 369 |
+
4. Downgrade when not in use
|
| 370 |
+
|
| 371 |
+
### 5. Update Regularly
|
| 372 |
+
|
| 373 |
+
Keep your Space updated:
|
| 374 |
+
```bash
|
| 375 |
+
git pull origin main # From main repo
|
| 376 |
+
git push # To your Space
|
| 377 |
+
```
|
| 378 |
+
|
| 379 |
+
## Advanced Configuration
|
| 380 |
+
|
| 381 |
+
### Custom Domain
|
| 382 |
+
|
| 383 |
+
Point your domain to your Space:
|
| 384 |
+
1. Go to Settings
|
| 385 |
+
2. Under "Custom domain"
|
| 386 |
+
3. Enter your domain
|
| 387 |
+
4. Follow DNS instructions
|
| 388 |
+
|
| 389 |
+
### Gradio Auth
|
| 390 |
+
|
| 391 |
+
Add simple authentication:
|
| 392 |
+
|
| 393 |
+
Edit `app.py`:
|
| 394 |
+
```python
|
| 395 |
+
demo.launch(
|
| 396 |
+
auth=("username", "password"),
|
| 397 |
+
server_name="0.0.0.0",
|
| 398 |
+
)
|
| 399 |
+
```
|
| 400 |
+
|
| 401 |
+
### Analytics
|
| 402 |
+
|
| 403 |
+
Track usage with Gradio analytics:
|
| 404 |
+
|
| 405 |
+
```python
|
| 406 |
+
demo.launch(
|
| 407 |
+
server_name="0.0.0.0",
|
| 408 |
+
analytics_enabled=True, # HF Spaces analytics
|
| 409 |
+
)
|
| 410 |
+
```
|
| 411 |
+
|
| 412 |
+
### Sleep Mode
|
| 413 |
+
|
| 414 |
+
Free Spaces sleep after 48h inactivity:
|
| 415 |
+
- First request wakes it up (~30s)
|
| 416 |
+
- Paid tiers can disable sleep
|
| 417 |
+
|
| 418 |
+
## Comparison: HF Spaces vs Self-Hosted
|
| 419 |
+
|
| 420 |
+
| Feature | HF Spaces | Self-Hosted |
|
| 421 |
+
|---------|-----------|-------------|
|
| 422 |
+
| Cost | Free tier available | Server costs |
|
| 423 |
+
| Setup | 5 minutes | 30-60 minutes |
|
| 424 |
+
| Maintenance | Automatic | Manual |
|
| 425 |
+
| Scaling | Auto-scales | Manual |
|
| 426 |
+
| SSL/HTTPS | Included | Configure yourself |
|
| 427 |
+
| Domain | *.hf.space | Your domain |
|
| 428 |
+
| GPU Access | Paid tiers | Need GPU server |
|
| 429 |
+
| Monitoring | Built-in | Setup required |
|
| 430 |
+
| Uptime | 99.9% | Depends |
|
| 431 |
+
|
| 432 |
+
## FAQ
|
| 433 |
+
|
| 434 |
+
### Is HF Spaces free?
|
| 435 |
+
|
| 436 |
+
Yes, free tier with:
|
| 437 |
+
- CPU Basic hardware
|
| 438 |
+
- Unlimited builds
|
| 439 |
+
- Unlimited users
|
| 440 |
+
- Auto-sleep after 48h inactivity
|
| 441 |
+
|
| 442 |
+
### Can I use private models?
|
| 443 |
+
|
| 444 |
+
Yes, with HuggingFace Pro:
|
| 445 |
+
- Private Spaces
|
| 446 |
+
- Private model access
|
| 447 |
+
- Gated model support
|
| 448 |
+
|
| 449 |
+
### How do I update my Space?
|
| 450 |
+
|
| 451 |
+
```bash
|
| 452 |
+
git pull # Get latest changes
|
| 453 |
+
git push # Deploy to Space
|
| 454 |
+
```
|
| 455 |
+
|
| 456 |
+
Or upload files via web interface.
|
| 457 |
+
|
| 458 |
+
### Can I monetize my Space?
|
| 459 |
+
|
| 460 |
+
Yes, with HF Pro:
|
| 461 |
+
- Set usage fees
|
| 462 |
+
- Subscription model
|
| 463 |
+
- Pay-per-use
|
| 464 |
+
|
| 465 |
+
### What about data privacy?
|
| 466 |
+
|
| 467 |
+
- Data processed in-memory
|
| 468 |
+
- Not stored permanently
|
| 469 |
+
- See HF privacy policy
|
| 470 |
+
- Use private Spaces for sensitive data
|
| 471 |
+
|
| 472 |
+
## Resources
|
| 473 |
+
|
| 474 |
+
- [HuggingFace Spaces Docs](https://huggingface.co/docs/hub/spaces)
|
| 475 |
+
- [Gradio Documentation](https://gradio.app/docs/)
|
| 476 |
+
- [Writing Studio GitHub](https://github.com/yourusername/writing-studio)
|
| 477 |
+
- [HuggingFace Community](https://discuss.huggingface.co/)
|
| 478 |
+
|
| 479 |
+
## Support
|
| 480 |
+
|
| 481 |
+
Need help?
|
| 482 |
+
- [GitHub Issues](https://github.com/yourusername/writing-studio/issues)
|
| 483 |
+
- [HF Community Forums](https://discuss.huggingface.co/)
|
| 484 |
+
- [Discord](https://discord.gg/huggingface)
|
| 485 |
+
|
| 486 |
+
## Success Stories
|
| 487 |
+
|
| 488 |
+
After deploying:
|
| 489 |
+
1. Share your Space on social media
|
| 490 |
+
2. Add to HuggingFace Papers
|
| 491 |
+
3. List in model cards
|
| 492 |
+
4. Submit to community showcase
|
| 493 |
+
|
| 494 |
+
## Next Steps
|
| 495 |
+
|
| 496 |
+
After successful deployment:
|
| 497 |
+
|
| 498 |
+
1. **Test Thoroughly**
|
| 499 |
+
- Try all prompt packs
|
| 500 |
+
- Test different models
|
| 501 |
+
- Check error handling
|
| 502 |
+
|
| 503 |
+
2. **Customize**
|
| 504 |
+
- Update README
|
| 505 |
+
- Add examples
|
| 506 |
+
- Configure settings
|
| 507 |
+
|
| 508 |
+
3. **Share**
|
| 509 |
+
- Post on social media
|
| 510 |
+
- Add to your website
|
| 511 |
+
- Share with students/colleagues
|
| 512 |
+
|
| 513 |
+
4. **Monitor**
|
| 514 |
+
- Check logs regularly
|
| 515 |
+
- Monitor usage
|
| 516 |
+
- Gather feedback
|
| 517 |
+
|
| 518 |
+
5. **Iterate**
|
| 519 |
+
- Fix issues
|
| 520 |
+
- Add features
|
| 521 |
+
- Improve performance
|
| 522 |
+
|
| 523 |
+
Happy deploying! 🚀
|
requirements.txt
CHANGED
|
@@ -1,36 +1,35 @@
|
|
| 1 |
-
# Core dependencies
|
| 2 |
gradio>=4.0.0
|
| 3 |
transformers>=4.35.0
|
| 4 |
torch>=2.0.0
|
| 5 |
-
difflib-patched>=0.1.0
|
| 6 |
|
| 7 |
-
# Configuration
|
| 8 |
pydantic>=2.0.0
|
| 9 |
pydantic-settings>=2.0.0
|
| 10 |
python-dotenv>=1.0.0
|
| 11 |
|
| 12 |
-
# Logging and monitoring
|
| 13 |
python-json-logger>=2.0.7
|
| 14 |
prometheus-client>=0.19.0
|
| 15 |
|
| 16 |
-
# Security
|
| 17 |
slowapi>=0.1.9
|
| 18 |
python-multipart>=0.0.6
|
| 19 |
|
| 20 |
-
# Testing
|
| 21 |
-
pytest>=7.4.0
|
| 22 |
-
pytest-cov>=4.1.0
|
| 23 |
-
pytest-asyncio>=0.21.0
|
| 24 |
-
pytest-mock>=3.12.0
|
| 25 |
-
httpx>=0.25.0
|
| 26 |
|
| 27 |
-
# Code quality
|
| 28 |
-
black>=23.0.0
|
| 29 |
-
flake8>=6.1.0
|
| 30 |
-
mypy>=1.7.0
|
| 31 |
-
isort>=5.12.0
|
| 32 |
-
pre-commit>=3.5.0
|
| 33 |
|
| 34 |
-
# Development
|
| 35 |
-
ipython>=8.17.0
|
| 36 |
-
ipdb>=0.13.13
|
|
|
|
| 1 |
+
# Core dependencies - Required for all deployments
|
| 2 |
gradio>=4.0.0
|
| 3 |
transformers>=4.35.0
|
| 4 |
torch>=2.0.0
|
|
|
|
| 5 |
|
| 6 |
+
# Configuration - Required
|
| 7 |
pydantic>=2.0.0
|
| 8 |
pydantic-settings>=2.0.0
|
| 9 |
python-dotenv>=1.0.0
|
| 10 |
|
| 11 |
+
# Logging and monitoring - Required for production features
|
| 12 |
python-json-logger>=2.0.7
|
| 13 |
prometheus-client>=0.19.0
|
| 14 |
|
| 15 |
+
# Security - Optional but recommended
|
| 16 |
slowapi>=0.1.9
|
| 17 |
python-multipart>=0.0.6
|
| 18 |
|
| 19 |
+
# Testing - Only needed for development
|
| 20 |
+
pytest>=7.4.0; extra == "dev"
|
| 21 |
+
pytest-cov>=4.1.0; extra == "dev"
|
| 22 |
+
pytest-asyncio>=0.21.0; extra == "dev"
|
| 23 |
+
pytest-mock>=3.12.0; extra == "dev"
|
| 24 |
+
httpx>=0.25.0; extra == "dev"
|
| 25 |
|
| 26 |
+
# Code quality - Only needed for development
|
| 27 |
+
black>=23.0.0; extra == "dev"
|
| 28 |
+
flake8>=6.1.0; extra == "dev"
|
| 29 |
+
mypy>=1.7.0; extra == "dev"
|
| 30 |
+
isort>=5.12.0; extra == "dev"
|
| 31 |
+
pre-commit>=3.5.0; extra == "dev"
|
| 32 |
|
| 33 |
+
# Development tools
|
| 34 |
+
ipython>=8.17.0; extra == "dev"
|
| 35 |
+
ipdb>=0.13.13; extra == "dev"
|
src/writing_studio/core/config.py
CHANGED
|
@@ -8,13 +8,24 @@ from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
| 8 |
|
| 9 |
|
| 10 |
class Settings(BaseSettings):
|
| 11 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
model_config = SettingsConfigDict(
|
| 14 |
env_file=".env",
|
| 15 |
env_file_encoding="utf-8",
|
| 16 |
case_sensitive=False,
|
| 17 |
extra="ignore",
|
|
|
|
|
|
|
| 18 |
)
|
| 19 |
|
| 20 |
# Application Settings
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
class Settings(BaseSettings):
|
| 11 |
+
"""
|
| 12 |
+
Application settings with environment variable support.
|
| 13 |
+
|
| 14 |
+
Settings are loaded from (in order of precedence):
|
| 15 |
+
1. Environment variables
|
| 16 |
+
2. .env file (if present)
|
| 17 |
+
3. Default values
|
| 18 |
+
|
| 19 |
+
Works without .env file for HuggingFace Spaces and containerized deployments.
|
| 20 |
+
"""
|
| 21 |
|
| 22 |
model_config = SettingsConfigDict(
|
| 23 |
env_file=".env",
|
| 24 |
env_file_encoding="utf-8",
|
| 25 |
case_sensitive=False,
|
| 26 |
extra="ignore",
|
| 27 |
+
# Don't error if .env file is missing (for HF Spaces, Docker, etc.)
|
| 28 |
+
env_ignore_empty=True,
|
| 29 |
)
|
| 30 |
|
| 31 |
# Application Settings
|