jmisak commited on
Commit
2e32647
·
verified ·
1 Parent(s): dbb3036

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +336 -18
README.md CHANGED
@@ -7,39 +7,357 @@ sdk: gradio
7
  sdk_version: "4.0.0"
8
  app_file: app.py
9
  pinned: false
 
 
 
 
 
 
 
 
 
 
 
10
  ---
11
 
12
- # AI Writing Studio
13
 
14
- Production-grade AI writing assistant with real rubric-based scoring for educational use.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  ## Features
17
 
18
- - 🎯 Real rubric scoring (Clarity, Conciseness, Organization, Evidence, Grammar)
19
- - 🔄 AI-powered revision suggestions
20
- - 📊 Visual diff highlighting
21
- - 📝 5 specialized prompt packs (General, Literature, Tech Comm, Academic, Creative)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  ## Usage
24
 
25
- 1. Paste your draft text
26
- 2. Select a model (distilgpt2 recommended for free tier)
27
- 3. Choose a prompt pack
28
- 4. Click "Analyze & Compare"
 
 
 
 
 
 
 
 
 
29
 
30
  ## Models
31
 
32
- - **distilgpt2** (default) - Fast, works on free tier
33
- - **gpt2** - Better quality, slower
34
- - **gpt2-medium/large** - Best quality, requires upgraded hardware
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  ## Performance
37
 
38
- First analysis: ~30-60 seconds (model loading)
39
- Subsequent: ~5-10 seconds (cached)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
- ## Source
 
 
 
 
42
 
43
- GitHub: [AI Writing Studio](https://github.com/yourusername/writing-studio)
44
 
45
- Built with [Gradio](https://gradio.app/) and [HuggingFace Transformers](https://huggingface.co/transformers/)
 
 
 
 
7
  sdk_version: "4.0.0"
8
  app_file: app.py
9
  pinned: false
10
+ license: mit
11
+ short_description: AI writing revision with FLAN-T5 and rubric scoring
12
+ tags:
13
+ - education
14
+ - writing
15
+ - nlp
16
+ - text2text-generation
17
+ - instruction-following
18
+ - analysis
19
+ suggested_hardware: cpu-basic
20
+ suggested_storage: small
21
  ---
22
 
23
+ # Writing Studio - HuggingFace Spaces Edition
24
 
25
+ Production-grade AI Writing Studio powered by **FLAN-T5** for intelligent text revision.
26
+
27
+ ## About
28
+
29
+ AI Writing Studio is a production-grade educational writing assistant that provides **real AI-powered text revision** using instruction-following models:
30
+
31
+ - **🤖 AI-Powered Revision** using FLAN-T5 (instruction-tuned for text revision)
32
+ - **📊 Real Rubric Scoring** across 5 criteria (Clarity, Conciseness, Organization, Evidence, Grammar)
33
+ - **🔍 Visual Diff Highlighting** to see exactly what changed
34
+ - **📝 5 Specialized Modes** (General, Literature, Tech Comm, Academic, Creative)
35
+
36
+ ## 🆕 What's New: FLAN-T5 Integration
37
+
38
+ **Major Update**: Replaced GPT-2 with FLAN-T5 for **real AI-powered text revision**.
39
+
40
+ **What Changed**:
41
+ - ✅ **FLAN-T5** now default model (instruction-following, actually revises text)
42
+ - ❌ **GPT-2 removed** (only continues text, doesn't revise)
43
+ - 🎯 **Instruction-optimized prompts** for better revision quality
44
+ - 🚀 **Automatic model detection** (supports both T5 and GPT-2 pipelines)
45
+
46
+ **Why This Matters**:
47
+ GPT-2 couldn't revise text—it only continued it with unrelated content. FLAN-T5 understands revision instructions and produces genuine improvements to your writing.
48
+
49
+ **Trade-off**: First load is ~60s instead of ~30s, but you get actual AI revision instead of gibberish!
50
+
51
+ ## Quick Start
52
+
53
+ 1. Open the app on HuggingFace Spaces
54
+ 2. Paste text (200-500 words recommended for first try)
55
+ 3. Choose revision mode (try "General" first)
56
+ 4. Click "✨ Revise & Analyze"
57
+ 5. Wait ~60s for first analysis (model loading)
58
+ 6. Compare original vs AI-revised text
59
+ 7. Review rubric scores and highlighted changes
60
 
61
  ## Features
62
 
63
+ ### AI-Powered Revision with FLAN-T5
64
+
65
+ **Why FLAN-T5?**
66
+ FLAN-T5 is an **instruction-tuned model** specifically trained to follow revision instructions. Unlike GPT-2 (which only continues text), FLAN-T5 actually understands and executes revision tasks like:
67
+ - Improving clarity and readability
68
+ - Enhancing academic tone
69
+ - Strengthening evidence and support
70
+ - Refining technical precision
71
+ - Enriching creative imagery
72
+
73
+ **Real Text Revision**: The AI doesn't just continue your text—it genuinely revises it based on the selected mode.
74
+
75
+ ### 📊 Real Rubric Analysis
76
+ Unlike simple prototypes, this version includes actual analysis algorithms:
77
+ - **Clarity**: Analyzes sentence length, complexity, and structure
78
+ - **Conciseness**: Detects wordy phrases and redundancy
79
+ - **Organization**: Checks paragraph structure and transitions
80
+ - **Evidence**: Looks for supporting examples and data
81
+ - **Grammar**: Basic error detection
82
+
83
+ ### 📝 5 Specialized Revision Modes
84
+ Choose from instruction-tuned templates optimized for FLAN-T5:
85
+ - **General**: Improve clarity and readability for everyday writing
86
+ - **Literature**: Strengthen literary analysis with better evidence and terminology
87
+ - **Tech Comm**: Enhance technical precision and professional tone
88
+ - **Academic**: Improve formal tone, organization, and scholarly voice
89
+ - **Creative**: Enhance imagery, voice, and reader engagement
90
+
91
+ ### 🔍 Visual Diff Highlighting
92
+ See exactly what the AI changed with side-by-side comparison and highlighted differences.
93
+
94
+ ### 🏭 Production Quality
95
+ - Comprehensive error handling
96
+ - Input validation and sanitization
97
+ - Structured logging
98
+ - Intelligent caching for faster responses
99
+ - Type-safe configuration with Pydantic
100
+ - Automatic model type detection
101
 
102
  ## Usage
103
 
104
+ 1. **Paste your text** in the input box (up to 10,000 characters)
105
+ 2. **Choose a revision mode** matching your writing context (General, Literature, Tech Comm, Academic, Creative)
106
+ 3. **Click "✨ Revise & Analyze"** to get AI revision + rubric feedback
107
+ 4. **Review results**: Compare original vs revised text, check rubric scores, view highlighted changes
108
+
109
+ ### Tips
110
+
111
+ - **First analysis takes ~60 seconds** (FLAN-T5 model loading) - this is normal!
112
+ - **Subsequent analyses are much faster** (~5-10s) thanks to caching
113
+ - Start with shorter texts (200-500 words) for quicker results
114
+ - Try different revision modes to see how the AI adapts its approach
115
+ - Use the rubric feedback to understand what improved
116
+ - The diff view shows exactly what changed and why
117
 
118
  ## Models
119
 
120
+ ### Default: google/flan-t5-base
121
+
122
+ **Why FLAN-T5?**
123
+ FLAN-T5 (Fine-tuned Language Net) is an **instruction-following model** from Google Research, specifically designed to understand and execute text revision tasks. This is fundamentally different from GPT-2 style models:
124
+
125
+ | Feature | FLAN-T5 (Current) | GPT-2 (Previous) |
126
+ |---------|------------------|------------------|
127
+ | **Task Type** | Instruction following | Text continuation |
128
+ | **Can Revise Text?** | ✅ Yes | ❌ No (only continues) |
129
+ | **Understands Instructions?** | ✅ Yes | ❌ No |
130
+ | **Works with Revision Modes?** | ✅ Yes | ❌ No |
131
+ | **Model Size** | ~250M parameters | ~124M parameters |
132
+ | **First Load Time** | ~60s | ~30s |
133
+ | **Quality** | High (task-specific) | Low (off-task) |
134
+
135
+ **FLAN-T5 Advantages:**
136
+ - ✅ Actually revises text (not just continuation)
137
+ - ✅ Follows mode-specific instructions (General, Academic, etc.)
138
+ - ✅ Produces contextually appropriate output
139
+ - ✅ Understands the task at hand
140
+
141
+ **Why Not GPT-2?**
142
+ GPT-2 and distilgpt2 are **autoregressive text generators** trained only to continue text. When given revision instructions, they ignore them and generate unrelated continuations. FLAN-T5 was explicitly trained on instruction-following tasks, making it ideal for text revision.
143
+
144
+ ### Alternative Models (Advanced)
145
+
146
+ You can change the model in the UI, but these require more resources:
147
+
148
+ **google/flan-t5-large** (780M params)
149
+ - Better revision quality
150
+ - Requires CPU upgrade or GPU
151
+ - ~2-3 minutes first load
152
+
153
+ **google/flan-t5-xl** (3B params)
154
+ - Best quality revisions
155
+ - Requires T4 GPU on HF Spaces
156
+ - ~5 minutes first load
157
 
158
  ## Performance
159
 
160
+ ### Hardware Recommendations
161
+
162
+ **Free Tier (CPU Basic)** ⭐ Recommended
163
+ - Works well with **google/flan-t5-base**
164
+ - First load: ~60 seconds (model download + initialization)
165
+ - Subsequent analyses: ~5-10 seconds
166
+ - Perfect for educational use and demos
167
+
168
+ **CPU Upgrade**
169
+ - Handles **google/flan-t5-large** comfortably
170
+ - First load: ~2-3 minutes
171
+ - Subsequent: ~10-15 seconds
172
+ - Better revision quality
173
+
174
+ **T4 GPU** ⚡ Best Performance
175
+ - Runs **google/flan-t5-xl** smoothly
176
+ - First load: ~5 minutes
177
+ - Subsequent: ~3-5 seconds
178
+ - Highest quality revisions
179
+
180
+ ### FLAN-T5 vs GPT-2 Performance
181
+
182
+ FLAN-T5 is slightly larger than distilgpt2, but the quality difference is dramatic:
183
+ - FLAN-T5: Slower but **actually revises text correctly**
184
+ - GPT-2: Faster but **produces unusable output** (wrong task)
185
+
186
+ **The extra 30 seconds of load time is worth it for functional AI revision!**
187
+
188
+ ### Optimization
189
+
190
+ The app includes production-grade optimizations:
191
+ - **Model caching**: Loaded once, reused for all requests
192
+ - **Result caching**: Same input = instant cached response
193
+ - **Intelligent pipeline selection**: Automatically uses correct pipeline for model type
194
+ - **Lazy loading**: Services initialized only when needed
195
+ - **Efficient text processing**: Minimizes unnecessary operations
196
+
197
+ ## Configuration
198
+
199
+ The app works out-of-the-box with sensible defaults optimized for FLAN-T5. To customize, you can set environment variables in your HuggingFace Space settings.
200
+
201
+ ### Available Environment Variables
202
+
203
+ ```bash
204
+ # Model Configuration
205
+ DEFAULT_MODEL=google/flan-t5-base # HuggingFace model ID (use FLAN-T5 variants)
206
+ MAX_MODEL_LENGTH=512 # Maximum model input/output length
207
+ DEFAULT_MAX_LENGTH=512 # Default generation length
208
+
209
+ # Application Settings
210
+ ENVIRONMENT=production # Runtime environment (development/staging/production)
211
+ LOG_LEVEL=INFO # Logging level (DEBUG/INFO/WARNING/ERROR)
212
+ LOG_FORMAT=text # Log format (json/text) - text is easier on HF Spaces
213
+ MAX_TEXT_LENGTH=10000 # Maximum input text length
214
+
215
+ # Performance
216
+ ENABLE_CACHE=true # Enable result caching
217
+ CACHE_MAX_SIZE=100 # Maximum cache entries
218
+ ENABLE_METRICS=false # Disable metrics server on HF Spaces
219
+
220
+ # Features
221
+ ENABLE_DIFF_HIGHLIGHTING=true # Enable visual diff view
222
+ ENABLE_RUBRIC_SCORING=true # Enable rubric analysis
223
+ ENABLE_PROMPT_PACKS=true # Enable revision mode selection
224
+ ```
225
+
226
+ ## Troubleshooting
227
+
228
+ ### "Out of Memory" Error
229
+ **Problem**: Space crashes or shows OOM error
230
+ **Solutions**:
231
+ - ✅ Stick with `google/flan-t5-base` on free tier (works well)
232
+ - ✅ Reduce input text length (try 200-500 words)
233
+ - ✅ Upgrade to CPU upgrade tier for larger models
234
+ - ❌ Don't try flan-t5-large or flan-t5-xl without GPU
235
+
236
+ ### Slow First Load (~60 seconds)
237
+ **This is normal!** FLAN-T5-base is ~250M parameters.
238
+ - First analysis: ~60s (model download + initialization)
239
+ - Subsequent: ~5-10s (model cached in memory)
240
+ - If it times out: Refresh and try again (HF Spaces issue)
241
+
242
+ ### "Model Loading Failed"
243
+ **Problem**: Error during model initialization
244
+ **Solutions**:
245
+ - Check model name spelling (must be exact HuggingFace ID)
246
+ - Ensure internet connectivity for model download
247
+ - Try default: `google/flan-t5-base`
248
+ - Check HF Spaces logs for specific error
249
+
250
+ ### AI Revision Doesn't Make Sense
251
+ **Problem**: Revision output is garbled or off-topic
252
+ **Solutions**:
253
+ - ✅ Make sure you're using FLAN-T5 (not GPT-2!)
254
+ - ✅ Try a different revision mode (General, Academic, etc.)
255
+ - ✅ Check input text is clear and well-formed
256
+ - ✅ Try shorter input text (model has 512 token limit)
257
+ - Remember: FLAN-T5 base is small; larger models (flan-t5-large) give better results
258
+
259
+ ### "Text Generation Failed"
260
+ **Problem**: Error during AI revision generation
261
+ **Solutions**:
262
+ - Input too long (try shorter text)
263
+ - Model timeout (refresh and retry)
264
+ - Check HF Spaces status (temporary service issue)
265
+
266
+ ## Privacy
267
+
268
+ - Text processed in-memory only
269
+ - Results cached temporarily for speed
270
+ - No long-term storage on HF Spaces
271
+ - No user tracking
272
+
273
+ ## Technical Details
274
+
275
+ ### How FLAN-T5 Integration Works
276
+
277
+ The app automatically detects model type and uses the appropriate pipeline:
278
+
279
+ **For FLAN-T5 models** (text2text-generation):
280
+ ```python
281
+ # Detects 't5' or 'flan' in model name
282
+ pipeline("text2text-generation", model="google/flan-t5-base")
283
+ ```
284
+
285
+ **For GPT-2 models** (text-generation):
286
+ ```python
287
+ # Fallback for text continuation models
288
+ pipeline("text-generation", model="gpt2")
289
+ ```
290
+
291
+ **Instruction-Following Prompts**:
292
+ FLAN-T5 requires structured instruction format:
293
+ ```
294
+ Revise the following text to improve clarity, conciseness, and readability.
295
+ Make it clear and easy to understand while maintaining the original meaning.
296
+
297
+ Text: [user input]
298
+
299
+ Revised text:
300
+ ```
301
+
302
+ This format tells FLAN-T5 exactly what to do, resulting in actual revisions instead of text continuation.
303
+
304
+ ### Architecture
305
+
306
+ **Production-Grade Layered Design**:
307
+ ```
308
+ src/writing_studio/
309
+ ├── core/
310
+ │ ├── analyzer.py # Main orchestrator
311
+ │ ├── config.py # Pydantic settings (FLAN-T5 defaults)
312
+ │ └── exceptions.py # Custom error types
313
+ ├── services/
314
+ │ ├── model_service.py # FLAN-T5 pipeline management
315
+ │ ├── prompt_service.py # Instruction-following prompts
316
+ │ ├── rubric_service.py # Rule-based scoring algorithms
317
+ │ └── diff_service.py # Visual diff generation
318
+ ├── utils/
319
+ │ ├── logging.py # Structured logging
320
+ │ ├── validation.py # Input sanitization
321
+ │ └── metrics.py # Prometheus metrics
322
+ └── app.py # HuggingFace Spaces entry point
323
+ ```
324
+
325
+ ## Source Code
326
+
327
+ Full source code available at: [GitHub Repository](https://github.com/yourusername/writing-studio)
328
+
329
+ ### Local Development
330
+
331
+ ```bash
332
+ git clone https://github.com/yourusername/writing-studio
333
+ cd writing-studio
334
+ pip install -r requirements.txt
335
+ python app.py
336
+ ```
337
+
338
+ ## Contributing
339
+
340
+ Contributions welcome! See [GitHub](https://github.com/yourusername/writing-studio) for:
341
+ - Full documentation
342
+ - Development setup
343
+ - Testing guidelines
344
+ - Code quality standards
345
+
346
+ ## License
347
+
348
+ MIT License - See LICENSE file
349
+
350
+ ## Acknowledgments
351
 
352
+ - **FLAN-T5**: [google/flan-t5-base](https://huggingface.co/google/flan-t5-base) by Google Research
353
+ - Built with [Gradio](https://gradio.app/) - Python web UI for ML
354
+ - Powered by [HuggingFace Transformers](https://huggingface.co/transformers/) - State-of-the-art NLP
355
+ - Hosted on [HuggingFace Spaces](https://huggingface.co/spaces) - Free ML app hosting
356
+ - Instruction-tuning research: [FLAN paper](https://arxiv.org/abs/2210.11416)
357
 
358
+ ## Support
359
 
360
+ Need help?
361
+ - Issues: [GitHub Issues](https://github.com/yourusername/writing-studio/issues)
362
+ - Documentation: [GitHub Docs](https://github.com/yourusername/writing-studio/tree/main/docs)
363
+ - Questions: [GitHub Discussions](https://github.com/yourusername/writing-studio/discussions)