Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- CHANGELOG.md +7 -5
- README.md +170 -170
- llm_backend.py +4 -4
- survey_generator.py +34 -17
CHANGELOG.md
CHANGED
|
@@ -10,8 +10,9 @@ All notable changes to ConversAI will be documented in this file.
|
|
| 10 |
- **No API endpoint issues** - everything runs on your Space
|
| 11 |
- **Faster after first load** - models cached in memory
|
| 12 |
- **100% private** - all processing happens locally
|
| 13 |
-
- Default model: **google/flan-t5-
|
| 14 |
- Supports all Flan-T5 variants (base, large, xl, xxl)
|
|
|
|
| 15 |
|
| 16 |
### Added
|
| 17 |
- **New dependencies**: transformers, torch, accelerate, sentencepiece
|
|
@@ -43,11 +44,12 @@ All notable changes to ConversAI will be documented in this file.
|
|
| 43 |
- Added model caching to keep models in memory
|
| 44 |
- Auto-detects CUDA/CPU and optimizes accordingly
|
| 45 |
|
| 46 |
-
- **Default model**: `google/flan-t5-
|
| 47 |
- Changed from API-based to local transformers
|
| 48 |
-
-
|
| 49 |
-
-
|
| 50 |
-
-
|
|
|
|
| 51 |
|
| 52 |
- **Complete rewrite of survey generation** in `survey_generator.py`:
|
| 53 |
- **Changed approach**: No longer asks model to generate JSON (T5 models struggle with structured output)
|
|
|
|
| 10 |
- **No API endpoint issues** - everything runs on your Space
|
| 11 |
- **Faster after first load** - models cached in memory
|
| 12 |
- **100% private** - all processing happens locally
|
| 13 |
+
- Default model: **google/flan-t5-xl** (3GB, excellent quality)
|
| 14 |
- Supports all Flan-T5 variants (base, large, xl, xxl)
|
| 15 |
+
- **Important**: XL or larger required for quality results; smaller models produce poor output
|
| 16 |
|
| 17 |
### Added
|
| 18 |
- **New dependencies**: transformers, torch, accelerate, sentencepiece
|
|
|
|
| 44 |
- Added model caching to keep models in memory
|
| 45 |
- Auto-detects CUDA/CPU and optimizes accordingly
|
| 46 |
|
| 47 |
+
- **Default model**: `google/flan-t5-xl` (line 84)
|
| 48 |
- Changed from API-based to local transformers
|
| 49 |
+
- 3GB model required for acceptable quality
|
| 50 |
+
- Testing showed base/large models produce generic, irrelevant questions
|
| 51 |
+
- XL provides good balance of quality and resource usage
|
| 52 |
+
- User can upgrade to xxl or downgrade to large/base via LLM_MODEL env var (not recommended)
|
| 53 |
|
| 54 |
- **Complete rewrite of survey generation** in `survey_generator.py`:
|
| 55 |
- **Changed approach**: No longer asks model to generate JSON (T5 models struggle with structured output)
|
README.md
CHANGED
|
@@ -1,170 +1,170 @@
|
|
| 1 |
-
---
|
| 2 |
-
title:
|
| 3 |
-
emoji: π¬
|
| 4 |
-
colorFrom: blue
|
| 5 |
-
colorTo: purple
|
| 6 |
-
sdk: gradio
|
| 7 |
-
sdk_version: 5.
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
-
license: mit
|
| 11 |
-
---
|
| 12 |
-
|
| 13 |
-
# ConversAI - AI-Powered Qualitative Research Assistant
|
| 14 |
-
|
| 15 |
-
Battle the blank page, reach global audiences, and uncover insights with AI assistance.
|
| 16 |
-
|
| 17 |
-
---
|
| 18 |
-
|
| 19 |
-
> **β¨ UPDATED (Nov 2025):** Now uses **local transformers** with **Google Flan-T5** models - Fast, reliable, and **completely FREE**! No API dependencies, runs directly on HuggingFace Spaces.
|
| 20 |
-
|
| 21 |
-
---
|
| 22 |
-
|
| 23 |
-
## π Features
|
| 24 |
-
|
| 25 |
-
### π Survey Generation
|
| 26 |
-
- Generate professional surveys from simple outlines
|
| 27 |
-
- Follow industry best practices automatically
|
| 28 |
-
- Choose from qualitative, quantitative, or mixed methods
|
| 29 |
-
- Customize number of questions and target audience
|
| 30 |
-
|
| 31 |
-
### π Survey Translation
|
| 32 |
-
- Translate surveys to 18+ languages
|
| 33 |
-
- Maintain cultural appropriateness and meaning
|
| 34 |
-
- Reach global audiences effortlessly
|
| 35 |
-
- Batch translation support
|
| 36 |
-
|
| 37 |
-
### π Data Analysis
|
| 38 |
-
- AI-assisted thematic analysis
|
| 39 |
-
- Sentiment analysis and emotional insights
|
| 40 |
-
- Automatic pattern and trend detection
|
| 41 |
-
- Generate actionable insights and recommendations
|
| 42 |
-
- Export detailed analysis reports
|
| 43 |
-
|
| 44 |
-
## π Quick Start
|
| 45 |
-
|
| 46 |
-
**On HuggingFace Spaces:** Works immediately with zero configuration! Uses the free HF Inference API.
|
| 47 |
-
|
| 48 |
-
**Workflow:**
|
| 49 |
-
1. **Generate a Survey**: Start with an outline or topic description
|
| 50 |
-
2. **Translate**: Select target languages to reach global audiences
|
| 51 |
-
3. **Collect Responses**: Use the generated survey with your participants
|
| 52 |
-
4. **Analyze**: Upload responses to uncover key findings and trends
|
| 53 |
-
|
| 54 |
-
## π§ Configuration
|
| 55 |
-
|
| 56 |
-
### Default: Local Transformers (Completely FREE!)
|
| 57 |
-
|
| 58 |
-
**β¨ Zero configuration needed!** ConversAI works out-of-the-box on HuggingFace Spaces using local model loading.
|
| 59 |
-
|
| 60 |
-
**Default Model:** google/flan-t5-
|
| 61 |
-
- β
**100% Free** - No API keys, no costs, ever
|
| 62 |
-
- β
**
|
| 63 |
-
- β
**
|
| 64 |
-
- β
**No API dependencies** - Runs entirely on your Space's compute
|
| 65 |
-
- β
**Private** - All processing happens locally, nothing sent to external APIs
|
| 66 |
-
- β
**Reliable** - Google's instruction-tuned model, battle-tested
|
| 67 |
-
|
| 68 |
-
**Setup for HuggingFace Spaces:**
|
| 69 |
-
- Just deploy - models download automatically on first run
|
| 70 |
-
- **No API keys or tokens required!**
|
| 71 |
-
- Models are cached after first download for faster subsequent loads
|
| 72 |
-
|
| 73 |
-
### Alternative Free Models
|
| 74 |
-
|
| 75 |
-
You can try different free models by setting the `LLM_MODEL` environment variable:
|
| 76 |
-
|
| 77 |
-
**Recommended Free Models (Local Transformers):**
|
| 78 |
-
|
| 79 |
-
| Model | Best For | Speed | Quality | Model Size |
|
| 80 |
-
|-------|----------|-------|---------|------------|
|
| 81 |
-
| **google/flan-t5-base** |
|
| 82 |
-
| **google/flan-t5-large**
|
| 83 |
-
| **google/flan-t5-xl** |
|
| 84 |
-
| **google/flan-t5-xxl** | Maximum quality | β‘ Slower | βββββ Best | 11GB |
|
| 85 |
-
|
| 86 |
-
**Note:** Flan-T5 models are Google's instruction-tuned models, specifically designed for following instructions. They run locally with transformers library.
|
| 87 |
-
|
| 88 |
-
**To change model:**
|
| 89 |
-
```bash
|
| 90 |
-
# In Space Settings β Variables
|
| 91 |
-
LLM_MODEL=google/flan-t5-large # Better quality
|
| 92 |
-
|
| 93 |
-
# Or for maximum quality (requires more memory)
|
| 94 |
-
LLM_MODEL=google/flan-t5-xl
|
| 95 |
-
```
|
| 96 |
-
|
| 97 |
-
**Why Local Transformers?**
|
| 98 |
-
- β
**No API dependencies** - runs entirely on your Space
|
| 99 |
-
- β
**No 404 errors** - no network issues
|
| 100 |
-
- β
**Fast after loading** - models cached in memory
|
| 101 |
-
- β
**Instruction-tuned** - designed for following prompts
|
| 102 |
-
- β
**Privacy** - all processing happens locally
|
| 103 |
-
|
| 104 |
-
### Tips for Best Performance with Local Models
|
| 105 |
-
|
| 106 |
-
1. **
|
| 107 |
-
2. **First load takes time** - Model downloads and loads (~
|
| 108 |
-
3. **Subsequent requests are fast** - Model stays in memory (
|
| 109 |
-
4. **For
|
| 110 |
-
5. **
|
| 111 |
-
6. **
|
| 112 |
-
|
| 113 |
-
## π¦ Installation
|
| 114 |
-
|
| 115 |
-
```bash
|
| 116 |
-
# Install dependencies
|
| 117 |
-
pip install -r requirements.txt
|
| 118 |
-
|
| 119 |
-
# Check environment setup (optional but recommended)
|
| 120 |
-
python check_env.py
|
| 121 |
-
|
| 122 |
-
# Run the app
|
| 123 |
-
python app.py
|
| 124 |
-
```
|
| 125 |
-
|
| 126 |
-
## ποΈ Architecture
|
| 127 |
-
|
| 128 |
-
ConversAI is built with a modular architecture:
|
| 129 |
-
|
| 130 |
-
- **llm_backend.py** - Unified LLM interface supporting multiple providers
|
| 131 |
-
- **survey_generator.py** - AI-powered survey generation
|
| 132 |
-
- **survey_translator.py** - Multi-language translation engine
|
| 133 |
-
- **data_analyzer.py** - Qualitative data analysis and insights
|
| 134 |
-
- **app.py** - Gradio-based web interface
|
| 135 |
-
- **export_utils.py** - Export to JSON, CSV, Markdown
|
| 136 |
-
|
| 137 |
-
## π Data Privacy
|
| 138 |
-
|
| 139 |
-
- All processing is done through your configured LLM provider
|
| 140 |
-
- No data is stored permanently by this application
|
| 141 |
-
- Survey data and responses remain in your control
|
| 142 |
-
- Suitable for sensitive research projects
|
| 143 |
-
|
| 144 |
-
## π€ Contributing
|
| 145 |
-
|
| 146 |
-
Contributions are welcome! This is a production-grade application designed for real-world qualitative research.
|
| 147 |
-
|
| 148 |
-
## π License
|
| 149 |
-
|
| 150 |
-
MIT License - Feel free to use for research and commercial purposes.
|
| 151 |
-
|
| 152 |
-
---
|
| 153 |
-
|
| 154 |
-
## π Documentation
|
| 155 |
-
|
| 156 |
-
**New to ConversAI?** Start with **[USER_GUIDE.md](USER_GUIDE.md)** for a complete walkthrough.
|
| 157 |
-
|
| 158 |
-
**Quick Links:**
|
| 159 |
-
- π [Complete User Guide](USER_GUIDE.md) - How to use ConversAI (START HERE)
|
| 160 |
-
- β‘ [Quick Start for HF Spaces](QUICK_START_HF_SPACES.md) - 5-minute deployment
|
| 161 |
-
- π§ [Troubleshooting](TROUBLESHOOTING.md) - Common issues and solutions
|
| 162 |
-
- π [Free Models Guide](FREE_MODELS.md) - Best free models to use
|
| 163 |
-
|
| 164 |
-
**Diagnostic Tools:**
|
| 165 |
-
- Run `python check_env.py` - Check your environment setup
|
| 166 |
-
- Run `python test_hf_backend.py` - Test HuggingFace connection
|
| 167 |
-
|
| 168 |
-
---
|
| 169 |
-
|
| 170 |
-
Built with β€οΈ using Gradio and state-of-the-art open-source LLMs
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: ConversAI - Qualitative Research Assistant
|
| 3 |
+
emoji: π¬
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 5.45.0
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# ConversAI - AI-Powered Qualitative Research Assistant
|
| 14 |
+
|
| 15 |
+
Battle the blank page, reach global audiences, and uncover insights with AI assistance.
|
| 16 |
+
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
> **β¨ UPDATED (Nov 2025):** Now uses **local transformers** with **Google Flan-T5** models - Fast, reliable, and **completely FREE**! No API dependencies, runs directly on HuggingFace Spaces.
|
| 20 |
+
|
| 21 |
+
---
|
| 22 |
+
|
| 23 |
+
## π Features
|
| 24 |
+
|
| 25 |
+
### π Survey Generation
|
| 26 |
+
- Generate professional surveys from simple outlines
|
| 27 |
+
- Follow industry best practices automatically
|
| 28 |
+
- Choose from qualitative, quantitative, or mixed methods
|
| 29 |
+
- Customize number of questions and target audience
|
| 30 |
+
|
| 31 |
+
### π Survey Translation
|
| 32 |
+
- Translate surveys to 18+ languages
|
| 33 |
+
- Maintain cultural appropriateness and meaning
|
| 34 |
+
- Reach global audiences effortlessly
|
| 35 |
+
- Batch translation support
|
| 36 |
+
|
| 37 |
+
### π Data Analysis
|
| 38 |
+
- AI-assisted thematic analysis
|
| 39 |
+
- Sentiment analysis and emotional insights
|
| 40 |
+
- Automatic pattern and trend detection
|
| 41 |
+
- Generate actionable insights and recommendations
|
| 42 |
+
- Export detailed analysis reports
|
| 43 |
+
|
| 44 |
+
## π Quick Start
|
| 45 |
+
|
| 46 |
+
**On HuggingFace Spaces:** Works immediately with zero configuration! Uses the free HF Inference API.
|
| 47 |
+
|
| 48 |
+
**Workflow:**
|
| 49 |
+
1. **Generate a Survey**: Start with an outline or topic description
|
| 50 |
+
2. **Translate**: Select target languages to reach global audiences
|
| 51 |
+
3. **Collect Responses**: Use the generated survey with your participants
|
| 52 |
+
4. **Analyze**: Upload responses to uncover key findings and trends
|
| 53 |
+
|
| 54 |
+
## π§ Configuration
|
| 55 |
+
|
| 56 |
+
### Default: Local Transformers (Completely FREE!)
|
| 57 |
+
|
| 58 |
+
**β¨ Zero configuration needed!** ConversAI works out-of-the-box on HuggingFace Spaces using local model loading.
|
| 59 |
+
|
| 60 |
+
**Default Model:** google/flan-t5-xl
|
| 61 |
+
- β
**100% Free** - No API keys, no costs, ever
|
| 62 |
+
- β
**High quality** - 3GB model, excellent at following complex instructions
|
| 63 |
+
- β
**Good speed** - Typically 5-10 seconds per request after initial load
|
| 64 |
+
- β
**No API dependencies** - Runs entirely on your Space's compute
|
| 65 |
+
- β
**Private** - All processing happens locally, nothing sent to external APIs
|
| 66 |
+
- β
**Reliable** - Google's instruction-tuned model, battle-tested
|
| 67 |
+
|
| 68 |
+
**Setup for HuggingFace Spaces:**
|
| 69 |
+
- Just deploy - models download automatically on first run
|
| 70 |
+
- **No API keys or tokens required!**
|
| 71 |
+
- Models are cached after first download for faster subsequent loads
|
| 72 |
+
|
| 73 |
+
### Alternative Free Models
|
| 74 |
+
|
| 75 |
+
You can try different free models by setting the `LLM_MODEL` environment variable:
|
| 76 |
+
|
| 77 |
+
**Recommended Free Models (Local Transformers):**
|
| 78 |
+
|
| 79 |
+
| Model | Best For | Speed | Quality | Model Size |
|
| 80 |
+
|-------|----------|-------|---------|------------|
|
| 81 |
+
| **google/flan-t5-base** | Quick testing only | β‘β‘β‘ Very Fast | β Poor | 250MB |
|
| 82 |
+
| **google/flan-t5-large** | Faster loading | β‘β‘ Fast | ββ Fair | 1.2GB |
|
| 83 |
+
| **google/flan-t5-xl** (default) | **Recommended** - best balance | β‘ Good | ββββ Excellent | 3GB |
|
| 84 |
+
| **google/flan-t5-xxl** | Maximum quality | β‘ Slower | βββββ Best | 11GB |
|
| 85 |
+
|
| 86 |
+
**Note:** Flan-T5 models are Google's instruction-tuned models, specifically designed for following instructions. They run locally with transformers library.
|
| 87 |
+
|
| 88 |
+
**To change model:**
|
| 89 |
+
```bash
|
| 90 |
+
# In Space Settings β Variables
|
| 91 |
+
LLM_MODEL=google/flan-t5-large # Better quality
|
| 92 |
+
|
| 93 |
+
# Or for maximum quality (requires more memory)
|
| 94 |
+
LLM_MODEL=google/flan-t5-xl
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
**Why Local Transformers?**
|
| 98 |
+
- β
**No API dependencies** - runs entirely on your Space
|
| 99 |
+
- β
**No 404 errors** - no network issues
|
| 100 |
+
- β
**Fast after loading** - models cached in memory
|
| 101 |
+
- β
**Instruction-tuned** - designed for following prompts
|
| 102 |
+
- β
**Privacy** - all processing happens locally
|
| 103 |
+
|
| 104 |
+
### Tips for Best Performance with Local Models
|
| 105 |
+
|
| 106 |
+
1. **Use flan-t5-xl (default)** - XL provides good quality, smaller models produce poor results
|
| 107 |
+
2. **First load takes time** - Model downloads and loads (~3-5 minutes for XL)
|
| 108 |
+
3. **Subsequent requests are fast** - Model stays in memory (5-10 seconds)
|
| 109 |
+
4. **For maximum quality** - Use flan-t5-xxl (requires 16GB+ RAM)
|
| 110 |
+
5. **Avoid smaller models** - Base and Large often produce generic or irrelevant questions
|
| 111 |
+
6. **Be specific in outlines** - More detail helps model generate better questions
|
| 112 |
+
|
| 113 |
+
## π¦ Installation
|
| 114 |
+
|
| 115 |
+
```bash
|
| 116 |
+
# Install dependencies
|
| 117 |
+
pip install -r requirements.txt
|
| 118 |
+
|
| 119 |
+
# Check environment setup (optional but recommended)
|
| 120 |
+
python check_env.py
|
| 121 |
+
|
| 122 |
+
# Run the app
|
| 123 |
+
python app.py
|
| 124 |
+
```
|
| 125 |
+
|
| 126 |
+
## ποΈ Architecture
|
| 127 |
+
|
| 128 |
+
ConversAI is built with a modular architecture:
|
| 129 |
+
|
| 130 |
+
- **llm_backend.py** - Unified LLM interface supporting multiple providers
|
| 131 |
+
- **survey_generator.py** - AI-powered survey generation
|
| 132 |
+
- **survey_translator.py** - Multi-language translation engine
|
| 133 |
+
- **data_analyzer.py** - Qualitative data analysis and insights
|
| 134 |
+
- **app.py** - Gradio-based web interface
|
| 135 |
+
- **export_utils.py** - Export to JSON, CSV, Markdown
|
| 136 |
+
|
| 137 |
+
## π Data Privacy
|
| 138 |
+
|
| 139 |
+
- All processing is done through your configured LLM provider
|
| 140 |
+
- No data is stored permanently by this application
|
| 141 |
+
- Survey data and responses remain in your control
|
| 142 |
+
- Suitable for sensitive research projects
|
| 143 |
+
|
| 144 |
+
## π€ Contributing
|
| 145 |
+
|
| 146 |
+
Contributions are welcome! This is a production-grade application designed for real-world qualitative research.
|
| 147 |
+
|
| 148 |
+
## π License
|
| 149 |
+
|
| 150 |
+
MIT License - Feel free to use for research and commercial purposes.
|
| 151 |
+
|
| 152 |
+
---
|
| 153 |
+
|
| 154 |
+
## π Documentation
|
| 155 |
+
|
| 156 |
+
**New to ConversAI?** Start with **[USER_GUIDE.md](USER_GUIDE.md)** for a complete walkthrough.
|
| 157 |
+
|
| 158 |
+
**Quick Links:**
|
| 159 |
+
- π [Complete User Guide](USER_GUIDE.md) - How to use ConversAI (START HERE)
|
| 160 |
+
- β‘ [Quick Start for HF Spaces](QUICK_START_HF_SPACES.md) - 5-minute deployment
|
| 161 |
+
- π§ [Troubleshooting](TROUBLESHOOTING.md) - Common issues and solutions
|
| 162 |
+
- π [Free Models Guide](FREE_MODELS.md) - Best free models to use
|
| 163 |
+
|
| 164 |
+
**Diagnostic Tools:**
|
| 165 |
+
- Run `python check_env.py` - Check your environment setup
|
| 166 |
+
- Run `python test_hf_backend.py` - Test HuggingFace connection
|
| 167 |
+
|
| 168 |
+
---
|
| 169 |
+
|
| 170 |
+
Built with β€οΈ using Gradio and state-of-the-art open-source LLMs
|
llm_backend.py
CHANGED
|
@@ -78,10 +78,10 @@ class LLMBackend:
|
|
| 78 |
defaults = {
|
| 79 |
LLMProvider.OPENAI: "gpt-4o-mini",
|
| 80 |
LLMProvider.ANTHROPIC: "claude-3-5-sonnet-20241022",
|
| 81 |
-
# Using Flan-T5-
|
| 82 |
-
# For
|
| 83 |
-
# For
|
| 84 |
-
LLMProvider.HUGGINGFACE: "google/flan-t5-
|
| 85 |
LLMProvider.LM_STUDIO: "google/gemma-3-27b"
|
| 86 |
}
|
| 87 |
return os.getenv("LLM_MODEL", defaults[self.provider])
|
|
|
|
| 78 |
defaults = {
|
| 79 |
LLMProvider.OPENAI: "gpt-4o-mini",
|
| 80 |
LLMProvider.ANTHROPIC: "claude-3-5-sonnet-20241022",
|
| 81 |
+
# Using Flan-T5-XL - best balance for quality survey generation (3GB)
|
| 82 |
+
# For faster loading: google/flan-t5-large (1.2GB) - may have lower quality
|
| 83 |
+
# For maximum quality: google/flan-t5-xxl (11GB) - requires more memory
|
| 84 |
+
LLMProvider.HUGGINGFACE: "google/flan-t5-xl",
|
| 85 |
LLMProvider.LM_STUDIO: "google/gemma-3-27b"
|
| 86 |
}
|
| 87 |
return os.getenv("LLM_MODEL", defaults[self.provider])
|
survey_generator.py
CHANGED
|
@@ -83,20 +83,21 @@ class SurveyGenerator:
|
|
| 83 |
|
| 84 |
def _build_generation_prompt(self, outline, survey_type, num_questions, target_audience) -> str:
|
| 85 |
"""Build the user prompt for survey generation"""
|
| 86 |
-
# For T5 models,
|
| 87 |
-
return f"""
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
| 91 |
|
| 92 |
-
|
| 93 |
|
| 94 |
-
|
| 95 |
-
1. What is your
|
| 96 |
-
2. How would you rate
|
| 97 |
-
3. What
|
| 98 |
|
| 99 |
-
|
|
|
|
| 100 |
|
| 101 |
def _parse_survey_response(self, response: str) -> Dict:
|
| 102 |
"""Parse LLM response into survey structure"""
|
|
@@ -105,20 +106,36 @@ Now generate {num_questions} questions:"""
|
|
| 105 |
|
| 106 |
def _parse_numbered_list(self, response: str) -> Dict:
|
| 107 |
"""Parse numbered list of questions into survey structure"""
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
questions = []
|
| 111 |
question_id = 1
|
| 112 |
|
| 113 |
-
for
|
| 114 |
-
# Skip
|
| 115 |
-
if len(
|
| 116 |
continue
|
| 117 |
|
| 118 |
-
#
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
-
# Skip
|
| 122 |
if len(clean_line) < 10:
|
| 123 |
continue
|
| 124 |
|
|
|
|
| 83 |
|
| 84 |
def _build_generation_prompt(self, outline, survey_type, num_questions, target_audience) -> str:
|
| 85 |
"""Build the user prompt for survey generation"""
|
| 86 |
+
# For T5 models, be very specific and direct
|
| 87 |
+
return f"""Create {num_questions} professional survey questions.
|
| 88 |
|
| 89 |
+
Topic: {outline}
|
| 90 |
+
Audience: {target_audience}
|
| 91 |
|
| 92 |
+
Write {num_questions} questions numbered 1-{num_questions}. Each question must be specific to the topic above.
|
| 93 |
|
| 94 |
+
Examples:
|
| 95 |
+
1. What is your experience with X?
|
| 96 |
+
2. How would you rate Y?
|
| 97 |
+
3. What challenges do you face with Z?
|
| 98 |
|
| 99 |
+
Your {num_questions} questions:
|
| 100 |
+
1."""
|
| 101 |
|
| 102 |
def _parse_survey_response(self, response: str) -> Dict:
|
| 103 |
"""Parse LLM response into survey structure"""
|
|
|
|
| 106 |
|
| 107 |
def _parse_numbered_list(self, response: str) -> Dict:
|
| 108 |
"""Parse numbered list of questions into survey structure"""
|
| 109 |
+
# First, try to split by numbered patterns (1., 2., etc.)
|
| 110 |
+
import re
|
| 111 |
+
|
| 112 |
+
# Pattern to match numbered questions: "1. Question" or "1) Question"
|
| 113 |
+
pattern = r'\d+[\.\)]\s+'
|
| 114 |
+
|
| 115 |
+
# Split by the pattern but keep what comes after each number
|
| 116 |
+
parts = re.split(pattern, response)
|
| 117 |
+
|
| 118 |
+
# Remove empty first element if exists
|
| 119 |
+
parts = [p.strip() for p in parts if p.strip()]
|
| 120 |
|
| 121 |
questions = []
|
| 122 |
question_id = 1
|
| 123 |
|
| 124 |
+
for part in parts:
|
| 125 |
+
# Skip if too short
|
| 126 |
+
if len(part) < 10:
|
| 127 |
continue
|
| 128 |
|
| 129 |
+
# Take only the first sentence/question if there are multiple
|
| 130 |
+
# Split by question mark or period
|
| 131 |
+
sentences = re.split(r'[?.!]\s+(?=\d+[\.\)]|\Z)', part)
|
| 132 |
+
clean_line = sentences[0].strip()
|
| 133 |
+
|
| 134 |
+
# Add question mark if missing
|
| 135 |
+
if not clean_line.endswith('?'):
|
| 136 |
+
clean_line += '?'
|
| 137 |
|
| 138 |
+
# Skip if still too short
|
| 139 |
if len(clean_line) < 10:
|
| 140 |
continue
|
| 141 |
|