Spaces:
Sleeping
Sleeping
File size: 12,618 Bytes
5b6c4b8 34a4f9e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 |
---
title: ResearchAI
emoji: ποΈ
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: "4.44.0"
app_file: app.py
pinned: false
---
# ποΈ Multi-Model Hierarchical Research System
A sophisticated **hierarchical multi-agent research system** with real-time progress tracking and live dashboard. Powered by multiple AI models (Qwen, Llama, Mistral) for comprehensive market research, competitive analysis, and strategic insights.
## β¨ Features
### π― Hierarchical Multi-Agent Architecture
```
Supervisor (Strategy)
β
βββ Researcher Agent π (Industry Leaders)
βββ Analyzer Agent β (Best Practices)
βββ Critic Agent π (Quality Review)
β
Synthesizer Agent π‘ (Recommendations)
```
### π Real-Time Progress Tracking
- **Live Dashboard** - Watch research progress in real-time
- **Phase-by-phase updates** - See each agent's status
- **Execution metrics** - Track timing and performance
- **Error handling** - Graceful degradation with retry logic
### π€ Multi-Model Support
- **Qwen 2.5 7B** - Fast & efficient analysis
- **Qwen 2.5 72B** - Most capable Qwen model
- **Meta Llama 3.1 70B** - Strong reasoning capabilities
- **Mistral Large** - Excellent analysis and synthesis
### π Comprehensive Research
- **Industry Leaders** - Top 5 companies setting standards
- **Best Practices** - Proven methods and innovations
- **Quality Review** - Independent assessment and validation
- **Strategic Recommendations** - Actionable roadmap
### π Rich Output
- Executive summaries with infographics
- Execution timelines and performance metrics
- Model assignment verification
- Search history and metadata
## π Quick Start
### 1. **Get HuggingFace API Token**
Visit [HuggingFace Settings](https://huggingface.co/settings/tokens):
1. Click "New token"
2. Select "Read" permission
3. Copy the token (starts with `hf_...`)
### 2. **Set Environment Variable**
```bash
# On Linux/Mac
export HF_TOKEN=hf_your_token_here
# On Windows (PowerShell)
$env:HF_TOKEN="hf_your_token_here"
# Or create .env file
echo "HF_TOKEN=hf_your_token_here" > .env
```
### 3. **Install Dependencies**
```bash
pip install -r requirements.txt
```
### 4. **Run the Application**
```bash
python app.py
```
The application will start on `http://localhost:7860`
## π Usage Guide
### Basic Research
1. **Enter Research Topic**
- Example: "AI project management tools"
- Example: "Sustainable fashion brands"
- Example: "Electric vehicle charging infrastructure"
2. **Click "Start Research"**
- Watch the Live Dashboard tab for real-time progress
- Each agent will execute in sequence
3. **Review Results**
- **Summary**: Executive overview and metadata
- **Industry Leaders**: Top 5 companies/products
- **Best Practices**: Proven strategies and innovations
- **Quality Review**: Independent assessment
- **Recommendations**: Strategic action plan
### Advanced: Configure Models
1. Open "Configure AI Models" accordion
2. Select different models for each phase:
- Query Understanding
- Industry Leaders Research
- Best Practices Analysis
- Quality Review
- Recommendations Generation
3. Click "Start Research" with custom configuration
## π Understanding the Output
### Live Dashboard
Shows real-time progress as research happens:
```
π Research started!
π Topic: AI project management tools
π€ Models configured: 4 unique models
π PHASE 1: RESEARCHER AGENT - Industry Leaders
Model: Qwen/Qwen2.5-72B-Instruct
Status: β³ Running...
Status: β
Complete (24.5s)
β PHASE 2: ANALYZER AGENT - Best Practices
Model: Qwen/Qwen2.5-72B-Instruct
Status: β³ Running...
Status: β
Complete (25.2s)
[... more phases ...]
π RESEARCH COMPLETE!
π EXECUTION SUMMARY:
π Researcher: 24.5s [ββββββββββββββββββββββββββββ]
β Analyzer: 25.2s [ββββββββββββββββββββββββββββ]
π Critic: 14.8s [ββββββββββββββββββββββββββββ]
π‘ Synthesizer: 19.5s [ββββββββββββββββββββββββββββ]
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π TOTAL TIME: 84.0s [ββββββββββββββββββββββββββββ]
```
### Summary Tab
- Research overview with hierarchy diagram
- Agent execution status and timing
- Performance metrics
- Model assignment verification
- Research metadata
### Industry Leaders Tab
- Top 5 companies/products
- Market positioning
- Key strengths
- Notable features
- Market metrics
### Best Practices Tab
- Industry standards and frameworks
- Success stories and case studies
- Innovation patterns
- Implementation guidelines
- Key takeaways
### Quality Review Tab
- Research completeness assessment
- Source quality evaluation
- Recency and relevance check
- Clarity and usefulness rating
- Improvement recommendations
- Overall quality scores
### Recommendations Tab
- Executive summary
- Immediate actions (0-30 days)
- Short-term strategy (1-3 months)
- Long-term vision (3-12 months)
- Success metrics
- Risk mitigation strategies
- Resource requirements
- Next steps
## ποΈ Architecture
### Research Engine
- **MultiModelResearchEngine**: Orchestrates agent execution
- **Model Caching**: Efficient model instance management
- **Retry Logic**: Automatic fallback for API errors
- **Web Search Integration**: Real-time information gathering
### Agent System
1. **Researcher Agent** π
- Identifies top industry leaders
- Analyzes market positioning
- Gathers competitive intelligence
2. **Analyzer Agent** β
- Researches best practices
- Identifies success patterns
- Documents innovations
3. **Critic Agent** π
- Quality assurance review
- Source validation
- Gap identification
4. **Synthesizer Agent** π‘
- Synthesizes all inputs
- Generates recommendations
- Creates action roadmap
### State Management
- **ResearchState**: Tracks search history, model usage, dashboard updates
- **Live Updates**: Real-time progress tracking
- **Caching**: Results and model instances
## π§ Configuration
### Environment Variables
```bash
# Required
HF_TOKEN=hf_your_token_here
# Optional (for future extensions)
ANTHROPIC_API_KEY=your_anthropic_key
OPENAI_API_KEY=your_openai_key
```
### Model Selection
Edit `DEFAULT_PHASE_MODELS` in `app.py`:
```python
DEFAULT_PHASE_MODELS = {
"query_understanding": "qwen-2.5-7b",
"industry_leaders": "qwen-2.5-72b",
"best_practices": "qwen-2.5-72b",
"quality_review": "qwen-2.5-72b",
"recommendations": "qwen-2.5-72b"
}
```
### Available Models
| Model | Provider | Speed | Quality | Cost |
|-------|----------|-------|---------|------|
| Qwen 2.5 7B | HuggingFace | β‘β‘β‘ | βββ | π° |
| Qwen 2.5 72B | HuggingFace | β‘β‘ | ββββ | π°π° |
| Llama 3.1 70B | HuggingFace | β‘β‘ | ββββ | π°π° |
| Mistral Large | HuggingFace | β‘β‘ | ββββ | π°π° |
## π Expected Performance
### Typical Execution Times
| Phase | Duration | Notes |
|-------|----------|-------|
| Researcher Agent | 20-30s | Includes web search |
| Analyzer Agent | 20-30s | Includes web search |
| Critic Agent | 10-20s | No web search |
| Synthesizer Agent | 15-25s | No web search |
| **Total** | **80-120s** | ~2 minutes |
### Factors Affecting Speed
- Model size (larger = slower)
- Topic complexity
- Internet speed (affects web search)
- API response time
- System load
## π Troubleshooting
### "HF_TOKEN not found"
**Solution**: Set the environment variable:
```bash
export HF_TOKEN=hf_your_token_here
```
### "API compatibility issue"
**Solution**: The system automatically falls back to compatible configurations. If issues persist:
1. Try using Qwen models instead
2. Simplify your research topic
3. Check your internet connection
### "Research stuck on Running"
**Solution**:
1. Check internet connection
2. Verify HF_TOKEN is valid
3. Try a simpler topic
4. Check HuggingFace API status
### "Empty results"
**Solution**:
1. Check the Live Dashboard for errors
2. Verify all models are available
3. Try with default model configuration
4. Simplify the research topic
## π¦ Deployment
### Local Deployment
```bash
python app.py
```
### HuggingFace Spaces
1. Create new Space on HuggingFace
2. Upload files:
- `app.py`
- `requirements.txt`
- `.env` (with HF_TOKEN)
3. HuggingFace automatically detects Gradio app
4. Space launches automatically
### Docker Deployment
```dockerfile
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY app.py .
ENV HF_TOKEN=your_token_here
CMD ["python", "app.py"]
```
## π File Structure
```
.
βββ app.py # Main application
βββ requirements.txt # Python dependencies
βββ agents_config.yaml # Agent configuration (optional)
βββ .env # Environment variables (local only)
βββ README.md # This file
```
## π Security
### API Key Management
- Never commit `.env` file to version control
- Use HuggingFace Spaces secrets for deployment
- Rotate tokens regularly
- Use read-only tokens when possible
### Data Privacy
- Research results are not stored
- Web searches are performed by the models
- No data is sent to external services except HuggingFace API
- Each session is independent
## π API Reference
### Main Function: `run_research()`
```python
run_research(
topic: str,
model_query: str,
model_leaders: str,
model_practices: str,
model_quality: str,
model_recommendations: str,
progress: gr.Progress
) -> Tuple[str, str, str, str, str, str]
```
**Parameters:**
- `topic`: Research topic
- `model_*`: Model selection for each phase
- `progress`: Gradio progress callback
**Returns:**
- Summary, Leaders, Practices, Review, Recommendations, Dashboard
### Research Engine
```python
engine = MultiModelResearchEngine(phase_models)
engine.research_industry_leaders(topic)
engine.research_best_practices(topic)
engine.quality_review(research_text)
engine.generate_recommendations(topic, research_text)
```
## π€ Contributing
Contributions are welcome! Areas for enhancement:
- Additional model support
- Custom agent configurations
- Export formats (PDF, DOCX, etc.)
- Caching and persistence
- Advanced filtering options
## π License
MIT License - See LICENSE file for details
## π Support
### Getting Help
1. Check the Troubleshooting section
2. Review the Live Dashboard for error messages
3. Verify environment setup
4. Check HuggingFace API status
### Common Issues
**Q: How long does research take?**
A: Typically 80-120 seconds (about 2 minutes) depending on topic complexity and model selection.
**Q: Can I use different models for each phase?**
A: Yes! Use the "Configure AI Models" accordion to select different models.
**Q: What if a model fails?**
A: The system has automatic retry logic and will gracefully degrade to compatible configurations.
**Q: How many searches are performed?**
A: Typically 8-12 searches across the Researcher and Analyzer agents.
**Q: Can I export the results?**
A: Results are displayed in markdown format and can be copied. Future versions will support PDF/DOCX export.
## π Learning Resources
- [HuggingFace Hub Documentation](https://huggingface.co/docs/hub)
- [Gradio Documentation](https://www.gradio.app/docs)
- [SmolaGents Documentation](https://huggingface.co/docs/smolagents)
- [Multi-Agent Systems](https://en.wikipedia.org/wiki/Multi-agent_system)
## π Roadmap
### Upcoming Features
- [ ] PDF/DOCX export
- [ ] Custom agent configuration via YAML
- [ ] Result caching and history
- [ ] Advanced filtering options
- [ ] Custom prompt templates
- [ ] Multi-language support
- [ ] API endpoint for programmatic access
- [ ] Result persistence and database storage
## π Metrics & Analytics
The system tracks:
- Execution time per agent
- Model usage statistics
- Search queries performed
- Success/failure rates
- Research coverage metrics
All metrics are displayed in the Summary and Dashboard tabs.
---
**Made with β€οΈ for intelligent research and decision-making**
For questions or suggestions, please open an issue or contact the development team.
|