jmisak commited on
Commit
56fed0f
Β·
verified Β·
1 Parent(s): 1424dcc

Upload 4 files

Browse files
Files changed (4) hide show
  1. CHANGELOG.md +7 -5
  2. README.md +170 -170
  3. llm_backend.py +4 -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-large** (1.2GB, good quality)
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-large` (line 84)
47
  - Changed from API-based to local transformers
48
- - 1.2GB model provides good balance of quality and speed
49
- - Better at JSON generation than smaller models
50
- - User can upgrade to xl/xxl or downgrade to base via LLM_MODEL env var
 
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: ProjectEcho - Qualitative Research Assistant
3
- emoji: πŸ”¬
4
- colorFrom: blue
5
- colorTo: purple
6
- sdk: gradio
7
- sdk_version: 5.49.1
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-large
61
- - βœ… **100% Free** - No API keys, no costs, ever
62
- - βœ… **Good quality** - 1.2GB model, excellent at following instructions
63
- - βœ… **Fast after loading** - Typically 3-8 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** | Testing - fastest | ⚑⚑⚑ Very Fast | ⭐⭐ Basic | 250MB |
82
- | **google/flan-t5-large** (default) | **Recommended** - balanced | ⚑⚑ Fast | ⭐⭐⭐ Good | 1.2GB |
83
- | **google/flan-t5-xl** | Better quality | ⚑ Medium | ⭐⭐⭐⭐ 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. **Default model (flan-t5-large) is recommended** - Good balance of quality and speed
107
- 2. **First load takes time** - Model downloads and loads (~2-3 minutes for large)
108
- 3. **Subsequent requests are fast** - Model stays in memory (3-8 seconds)
109
- 4. **For simple testing** - Use flan-t5-base (faster loading)
110
- 5. **For best quality** - Use flan-t5-xl or xxl (requires more memory)
111
- 6. **Keep prompts clear** - Simpler outlines work better with smaller models
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-Large - good balance of size (1.2GB) and quality
82
- # For smaller/faster: google/flan-t5-base (250MB)
83
- # For better quality: google/flan-t5-xl (3GB) or google/flan-t5-xxl (11GB)
84
- LLMProvider.HUGGINGFACE: "google/flan-t5-large",
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, ask for simple numbered list instead of JSON
87
- return f"""Generate {num_questions} survey questions about: {outline}
88
 
89
- Target audience: {target_audience}
90
- Survey type: {survey_type}
91
 
92
- Create {num_questions} clear, professional questions. Write each question on a new line starting with a number.
93
 
94
- Example format:
95
- 1. What is your overall experience with [topic]?
96
- 2. How would you rate [specific aspect]?
97
- 3. What improvements would you suggest?
98
 
99
- Now generate {num_questions} questions:"""
 
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
- lines = [line.strip() for line in response.split('\n') if line.strip()]
 
 
 
 
 
 
 
 
 
 
109
 
110
  questions = []
111
  question_id = 1
112
 
113
- for line in lines:
114
- # Skip empty lines or lines that are too short
115
- if len(line) < 5:
116
  continue
117
 
118
- # Remove leading numbers, bullets, dashes, etc.
119
- clean_line = line.lstrip('0123456789.-) \t')
 
 
 
 
 
 
120
 
121
- # Skip lines that don't look like questions
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