An offline-first AI tutoring system using Model Context Protocol (MCP) for refugee and underserved students. Works locally via Wi-Fi hotspot with optional cloud integration.
- Offline-First: Works without internet using local AI models
- Multi-Agent System: Specialized agents for tutoring, translation, quizzes, and content retrieval
- Bilingual Support: Arabic and English with real-time translation
- Progressive Web App: Works on phones, tablets, and computers
- Local Network Access: Students connect via Wi-Fi hotspot or LAN
- Cloud Sync: Syncs progress when internet is available
- Tutor Agent - Explains concepts, answers questions
- Translator Agent - Arabic β English translation
- Quiz Agent - Generates and grades assessments
- Content Agent - Retrieves from stored educational materials (RAG)
- Sync Agent - Syncs data to cloud when online
- Python 3.9+
- 4GB+ RAM (for local models)
- Wi-Fi hotspot capability or local network
# Clone the repository
git clone <your-repo-url>
cd ufuq
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Download models (first time only)
python download_models.pyCreate a .env file:
# Optional: Add API keys for online mode
OPENAI_API_KEY=your_key_here
SAMBANOVA_API_KEY=your_key_here
MODAL_API_KEY=your_key_here
# Debug mode
DEBUG=True# Start the Flask backend
python app.pyThe server will run on http://0.0.0.0:5000 (accessible on local network)
- Enable Wi-Fi Hotspot on the host device
- Students connect to the hotspot
- Students open browser and navigate to:
http://<host-ip>:5000 - Start learning!
ufuq/
βββ app.py # Main Flask application
βββ mcp_runtime.py # MCP agent orchestration hub
βββ agents.py # All 5 MCP agents
βββ storage.py # Database and caching
βββ config.py # Configuration management
βββ requirements.txt # Python dependencies
βββ download_models.py # Model download script
βββ data/
β βββ ufuq.db # SQLite database
β βββ cache/ # Offline cache
β βββ vectordb/ # ChromaDB vector storage
β βββ content/ # Educational PDFs/materials
βββ frontend/ # React PWA (separate)
βββ ...
POST /api/chat
{
"student_id": "student_123",
"message": "Explain Newton's laws",
"language": "en"
}POST /api/translate
{
"text": "Hello, how are you?",
"source_lang": "en",
"target_lang": "ar"
}POST /api/quiz/generate
{
"student_id": "student_123",
"topic": "Physics - Newton's Laws",
"difficulty": "medium",
"num_questions": 5,
"language": "en"
}POST /api/quiz/submit
{
"student_id": "student_123",
"quiz_id": 1,
"answers": ["A", "B", "C", "D", "A"]
}POST /api/content/retrieve
{
"query": "What is photosynthesis?",
"subject": "biology",
"language": "en"
}GET /api/student/progress?student_id=student_123POST /api/sync
{
"student_id": "student_123"
}GET /api/mode- Student Request β Flask receives HTTP request
- MCP Router β Routes to appropriate agent
- Agent Execution β Agent processes with local/cloud models
- Mode Detection β Automatically switches between offline/online
- Response β Returns result to student
- Storage β Saves interaction locally, syncs when online
# MCP Runtime automatically routes based on request type
mcp_runtime.route_request(
agent_type="tutor", # or "translator", "quiz", "content", "sync"
payload={...}
)The system automatically detects internet connectivity:
- Offline: Uses Hugging Face models (FLAN-T5, Helsinki-NLP)
- Online: Uses OpenAI GPT-4 for better quality
- Hybrid: Falls back to offline if online fails
# Create a content ingestion script
from content_ingestion import ingest_pdf
# Add textbooks
ingest_pdf('path/to/physics_textbook.pdf', subject='physics')
ingest_pdf('path/to/math_textbook.pdf', subject='mathematics')from agents import ContentAgent
from config import Config
config = Config()
content_agent = ContentAgent(config)
# Add content manually
content_agent.collection.add(
documents=["Newton's First Law: Objects at rest stay at rest..."],
metadatas=[{"subject": "physics", "source": "textbook_ch1"}],
ids=["physics_newton_1"]
)# Set API key in .env
OPENAI_API_KEY=sk-...pip install modal
modal token new# Add SambaNova API key
SAMBANOVA_API_KEY=your_key# Run tests
pytest tests/
# Test specific agent
pytest tests/test_tutor_agent.py
# Test offline mode
FORCE_OFFLINE=True pytest tests/The React PWA connects to these endpoints. Example:
// Chat with tutor
const response = await fetch('http://<host-ip>:5000/api/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
student_id: 'student_123',
message: 'Explain gravity',
language: 'en'
})
});
const data = await response.json();
console.log(data.response); // AI tutor's explanation- Local Network Only: By default, only accessible on LAN
- No Authentication: Add authentication for production
- Data Privacy: All data stored locally, synced optionally
- API Keys: Keep in
.env, never commit to git
# Re-download models
python download_models.py --force# Change port in app.py
app.run(host='0.0.0.0', port=5001)- Reduce model sizes in
config.py - Use smaller models (e.g.,
flan-t5-smallinstead ofbase) - Disable local model loading and use online-only mode
- Check firewall settings
- Ensure all devices on same network
- Use IP address instead of localhost
# In config.py, use smaller models
'offline': {
'tutor': 'google/flan-t5-small', # Instead of base
'translator': 'Helsinki-NLP/opus-mt-tc-big-en-ar' # Smaller variant
}# Process multiple quiz questions at once
quiz_agent.execute({
'action': 'batch_generate',
'topics': ['physics', 'math', 'chemistry']
})- Fork the repository
- Create a feature branch
- Make your changes
- Test offline and online modes
- Submit a pull request
MIT License - Feel free to use for educational purposes
For issues during the hackathon:
- Check logs:
tail -f logs/ufuq.log - Test mode:
curl http://localhost:5000/health
- Add voice input/output
- Implement peer-to-peer quiz sharing
- Add gamification (points, badges)
- Multi-user collaboration features
- Teacher dashboard for monitoring
- More languages (French, Spanish)
- Offline video lessons
Built with β€οΈ for underserved students worldwide