File size: 14,418 Bytes
8f4d405 79ea999 8f4d405 3f8cddc 79ea999 3f8cddc 79ea999 3f8cddc 8f4d405 79ea999 8f4d405 5787d0a 8f4d405 5787d0a 8f4d405 5787d0a 8f4d405 79ea999 8f4d405 79ea999 8f4d405 79ea999 8f4d405 79ea999 8f4d405 79ea999 8f4d405 5787d0a 8f4d405 79ea999 8f4d405 79ea999 8f4d405 79ea999 8f4d405 |
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 |
---
title: AI Research Assistant MVP
emoji: ๐ง
colorFrom: blue
colorTo: purple
sdk: docker
app_port: 7860
pinned: false
license: apache-2.0
tags:
- ai
- chatbot
- research
- education
- transformers
models:
- meta-llama/Llama-3.1-8B-Instruct
- intfloat/e5-base-v2
- Qwen/Qwen2.5-1.5B-Instruct
datasets:
- wikipedia
- commoncrawl
base_path: research-assistant
hf_oauth: true
hf_token: true
disable_embedding: false
duplicated_from: null
extra_gated_prompt: null
extra_gated_fields: {}
gated: false
public: true
---
# AI Research Assistant - MVP
<div align="center">




**Academic-grade AI assistant with transparent reasoning and mobile-optimized interface**
[](https://huggingface.co/spaces/your-username/research-assistant)
[](https://github.com/your-org/research-assistant/wiki)
</div>
## ๐ฏ Overview
This MVP demonstrates an intelligent research assistant framework featuring **transparent reasoning chains**, **specialized agent architecture**, and **mobile-first design**. Built for Hugging Face Spaces with NVIDIA T4 GPU acceleration for local model inference.
### Key Differentiators
- **๐ Transparent Reasoning**: Watch the AI think step-by-step with Chain of Thought
- **๐ง Specialized Agents**: Multiple AI models working together for optimal performance
- **๐ฑ Mobile-First**: Optimized for seamless mobile web experience
- **๐ Academic Focus**: Designed for research and educational use cases
## ๐ API Documentation
**Comprehensive API documentation is available:** [API_DOCUMENTATION.md](API_DOCUMENTATION.md)
The API provides REST endpoints for:
- Chat interactions with AI assistant
- Health checks
- Context management
- Session tracking
**Quick API Example:**
```python
import requests
response = requests.post(
"https://huggingface.co/spaces/JatinAutonomousLabs/HonestAI/api/chat",
json={
"message": "What is machine learning?",
"session_id": "my-session",
"user_id": "user-123"
}
)
data = response.json()
print(data["message"])
print(f"Performance: {data.get('performance', {})}")
```
## ๐ Quick Start
### Option 1: Use Our Demo
Visit our live demo on Hugging Face Spaces:
```bash
https://huggingface.co/spaces/JatinAutonomousLabs/HonestAI
```
### Option 2: Deploy Your Own Instance
#### Prerequisites
- Hugging Face account with [write token](https://huggingface.co/settings/tokens)
- Basic understanding of Hugging Face Spaces
#### Deployment Steps
1. **Fork this space** using the Hugging Face UI
2. **Add your HF token** (optional, only needed for gated models):
- Go to your Space โ Settings โ Repository secrets
- Add `HF_TOKEN` with your Hugging Face token (only needed if using gated models)
- **Note**: Local models are used for inference - HF_TOKEN is only for downloading models
3. **The space will auto-build** (takes 5-10 minutes)
#### Manual Build (Advanced)
```bash
# Clone the repository
git clone https://huggingface.co/spaces/your-username/research-assistant
cd research-assistant
# Install dependencies
pip install -r requirements.txt
# Set up environment (optional - only needed for gated models)
export HF_TOKEN="your_hugging_face_token_here" # Optional: only for downloading gated models
# Launch the application (multiple options)
python main.py # Full integration with error handling
python launch.py # Simple launcher
python app.py # UI-only mode
```
## ๐ Integration Structure
The MVP now includes complete integration files for deployment:
```
โโโ main.py # ๐ฏ Main integration entry point
โโโ launch.py # ๐ Simple launcher for HF Spaces
โโโ app.py # ๐ฑ Mobile-optimized UI
โโโ requirements.txt # ๐ฆ Dependencies
โโโ src/
โโโ __init__.py # ๐ฆ Package initialization
โโโ database.py # ๐๏ธ SQLite database management
โโโ event_handlers.py # ๐ UI event integration
โโโ config.py # โ๏ธ Configuration
โโโ llm_router.py # ๐ค LLM routing
โโโ orchestrator_engine.py # ๐ญ Request orchestration
โโโ context_manager.py # ๐ง Context management
โโโ mobile_handlers.py # ๐ฑ Mobile UX handlers
โโโ agents/
โโโ __init__.py # ๐ค Agents package
โโโ intent_agent.py # ๐ฏ Intent recognition
โโโ synthesis_agent.py # โจ Response synthesis
โโโ safety_agent.py # ๐ก๏ธ Safety checking
```
### Key Features:
- **๐ Graceful Degradation**: Falls back to mock mode if components fail
- **๐ฑ Mobile-First**: Optimized for mobile devices and small screens
- **๐๏ธ Database Ready**: SQLite integration with session management
- **๐ Event Handling**: Complete UI-to-backend integration
- **โก Error Recovery**: Robust error handling throughout
## ๐๏ธ Architecture
```
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Mobile Web โ โโ โ ORCHESTRATOR โ โโ โ AGENT SWARM โ
โ Interface โ โ (Core Engine) โ โ (5 Specialists)โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ PERSISTENCE LAYER โ
โ (SQLite + FAISS Lite) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
### Core Components
| Component | Purpose | Technology |
|-----------|---------|------------|
| **Orchestrator** | Main coordination engine | Python + Async |
| **Intent Recognition** | Understand user goals | RoBERTa-base + CoT |
| **Context Manager** | Session memory & recall | FAISS + SQLite |
| **Response Synthesis** | Generate final answers | Mistral-7B |
| **Safety Checker** | Content moderation | Unbiased-Toxic-RoBERTa |
| **Research Agent** | Information gathering | Web search + analysis |
## ๐ก Usage Examples
### Basic Research Query
```
User: "Explain quantum entanglement in simple terms"
Assistant:
1. ๐ค [Reasoning] Breaking down quantum physics concepts...
2. ๐ [Research] Gathering latest explanations...
3. โ๏ธ [Synthesis] Creating simplified explanation...
[Final Response]: Quantum entanglement is when two particles become linked...
```
### Technical Analysis
```
User: "Compare transformer models for text classification"
Assistant:
1. ๐ท๏ธ [Intent] Identifying technical comparison request
2. ๐ [Analysis] Evaluating BERT vs RoBERTa vs DistilBERT
3. ๐ [Synthesis] Creating comparison table with metrics...
```
## โ๏ธ Configuration
### Environment Variables
```python
# Required
HF_TOKEN="your_hugging_face_token"
# Optional
MAX_WORKERS=4
CACHE_TTL=3600
DEFAULT_MODEL="meta-llama/Llama-3.1-8B-Instruct"
EMBEDDING_MODEL="intfloat/e5-base-v2"
CLASSIFICATION_MODEL="Qwen/Qwen2.5-1.5B-Instruct"
HF_HOME="/tmp/huggingface" # Cache directory (auto-configured)
LOG_LEVEL="INFO"
```
**Cache Directory Management:**
- Automatically configured with secure fallback chain
- Supports HF_HOME, TRANSFORMERS_CACHE, or user cache
- Validates write permissions automatically
- See `.env.example` for all available options
### Model Configuration
The system uses multiple specialized models optimized for T4 16GB GPU:
| Task | Model | Purpose | Quantization |
|------|-------|---------|--------------|
| Primary Reasoning | `meta-llama/Llama-3.1-8B-Instruct` | General responses | 4-bit NF4 |
| Embeddings | `intfloat/e5-base-v2` | Semantic search | None (768-dim) |
| Intent Classification | `Qwen/Qwen2.5-1.5B-Instruct` | User goal detection | 4-bit NF4 |
| Safety Checking | `meta-llama/Llama-3.1-8B-Instruct` | Content moderation | 4-bit NF4 |
**Performance Optimizations:**
- โ
4-bit quantization (NF4) for memory efficiency
- โ
Model preloading for faster responses
- โ
Connection pooling for API calls
- โ
Parallel agent processing
## ๐ฑ Mobile Optimization
### Key Mobile Features
- **Touch-friendly** interface (44px+ touch targets)
- **Progressive Web App** capabilities
- **Offline functionality** for cached sessions
- **Reduced data usage** with optimized responses
- **Keyboard-aware** layout adjustments
### Supported Devices
- โ
Smartphones (iOS/Android)
- โ
Tablets
- โ
Desktop browsers
- โ
Screen readers (accessibility)
## ๐ ๏ธ Development
### Project Structure
```
research-assistant/
โโโ app.py # Main Gradio application
โโโ requirements.txt # Dependencies
โโโ Dockerfile # Container configuration
โโโ src/
โ โโโ orchestrator.py # Core orchestration engine
โ โโโ agents/ # Specialized agent modules
โ โโโ llm_router.py # Multi-model routing
โ โโโ mobile_ux.py # Mobile optimizations
โโโ tests/ # Test suites
โโโ docs/ # Documentation
```
### Adding New Agents
1. Create agent module in `src/agents/`
2. Implement agent protocol:
```python
class YourNewAgent:
async def execute(self, user_input: str, context: dict) -> dict:
# Your agent logic here
return {
"result": processed_output,
"confidence": 0.95,
"metadata": {}
}
```
3. Register agent in orchestrator configuration
## ๐งช Testing
### Run Test Suite
```bash
# Install test dependencies
pip install -r requirements.txt
# Run all tests
pytest tests/ -v
# Run specific test categories
pytest tests/test_agents.py -v
pytest tests/test_mobile_ux.py -v
```
### Test Coverage
- โ
Agent functionality
- โ
Mobile UX components
- โ
LLM routing logic
- โ
Error handling
- โ
Performance benchmarks
## ๐จ Troubleshooting
### Common Build Issues
| Issue | Solution |
|-------|----------|
| **HF_TOKEN not found** | Optional - only needed for gated model access |
| **Local models unavailable** | Check transformers/torch installation |
| **Build timeout** | Reduce model sizes in requirements |
| **Memory errors** | Check GPU memory usage, optimize model loading |
| **Import errors** | Check Python version (3.9+) |
### Performance Optimization
1. **Enable caching** in context manager
2. **Use smaller models** for initial deployment
3. **Implement lazy loading** for mobile users
4. **Monitor memory usage** with built-in tools
### Debug Mode
Enable detailed logging:
```python
import logging
logging.basicConfig(level=logging.DEBUG)
```
## ๐ Performance Metrics
The API now includes comprehensive performance metrics in every response:
```json
{
"performance": {
"processing_time": 1230.5, // milliseconds
"tokens_used": 456,
"agents_used": 4,
"confidence_score": 85.2, // percentage
"agent_contributions": [
{"agent": "Intent", "percentage": 25.0},
{"agent": "Synthesis", "percentage": 40.0},
{"agent": "Safety", "percentage": 15.0},
{"agent": "Skills", "percentage": 20.0}
],
"safety_score": 85.0,
"latency_seconds": 1.230,
"timestamp": "2024-01-15T10:30:45.123456"
}
}
```
| Metric | Target | Current |
|--------|---------|---------|
| Response Time | <10s | ~7s |
| Cache Hit Rate | >60% | ~65% |
| Mobile UX Score | >80/100 | 85/100 |
| Error Rate | <5% | ~3% |
| Performance Tracking | โ
| โ
Implemented |
## ๐ฎ Roadmap
### Phase 1 (Current - MVP)
- โ
Basic agent orchestration
- โ
Mobile-optimized interface
- โ
Multi-model routing
- โ
Transparent reasoning display
- โ
Performance metrics tracking
- โ
Enhanced configuration management
- โ
4-bit quantization for T4 GPU
- โ
Model preloading and optimization
### Phase 2 (Next 3 months)
- ๐ง Advanced research capabilities
- ๐ง Plugin system for tools
- ๐ง Enhanced mobile PWA features
- ๐ง Multi-language support
### Phase 3 (Future)
- ๐ฎ Autonomous agent swarms
- ๐ฎ Voice interface integration
- ๐ฎ Enterprise features
- ๐ฎ Advanced analytics
## ๐ฅ Contributing
We welcome contributions! Please see:
1. [Contributing Guidelines](docs/CONTRIBUTING.md)
2. [Code of Conduct](docs/CODE_OF_CONDUCT.md)
3. [Development Setup](docs/DEVELOPMENT.md)
### Quick Contribution Steps
```bash
# 1. Fork the repository
# 2. Create feature branch
git checkout -b feature/amazing-feature
# 3. Commit changes
git commit -m "Add amazing feature"
# 4. Push to branch
git push origin feature/amazing-feature
# 5. Open Pull Request
```
## ๐ Citation
If you use this framework in your research, please cite:
```bibtex
@software{research_assistant_mvp,
title = {AI Research Assistant - MVP},
author = {Your Name},
year = {2024},
url = {https://huggingface.co/spaces/your-username/research-assistant}
}
```
## ๐ License
This project is licensed under the Apache 2.0 License - see the [LICENSE](LICENSE) file for details.
## ๐ Acknowledgments
- [Hugging Face](https://huggingface.co) for the infrastructure
- [Gradio](https://gradio.app) for the web framework
- Model contributors from the HF community
- Early testers and feedback providers
---
<div align="center">
**Need help?**
- [Open an Issue](https://github.com/your-org/research-assistant/issues)
- [Join our Discord](https://discord.gg/your-discord)
- [Email Support](mailto:[email protected])
*Built with โค๏ธ for the research community*
</div>
|