An end-to-end intelligent campus companion system combining a real-time WebRTC digital human, AI-powered educational counseling chatbot (Gigi), on-device AI photography, and an interactive campus navigation experience.
- System Overview
- Architecture
- Key Features
- Project Structure
- Technology Stack
- Getting Started
- API Reference
- AI Services
- Configuration
This system is built for Asia Pacific University (APU), Malaysia as a smart campus digital companion. It consists of three tightly integrated components:
| Component | Technology | Role |
|---|---|---|
| Android App | Kotlin + CameraX + WebRTC | Campus kiosk / mobile client |
| Django Backend | Python + Groq AI + RAG | AI counseling API & web interface |
| LiveTalking Server | GPU Server + WebRTC | Real-time digital human video rendering |
The digital human avatar "Gigi" serves as the primary interface — greeting visitors, answering questions about APU programs, guiding navigation, and enabling AI photography sessions, all driven by a large language model with a custom knowledge base.
┌─────────────────────────────────────────────────────────────────────┐
│ Android Application │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────┐ ┌───────────┐ │
│ │ SplashActivity│ │NewMainActivity│ │ Camera │ │ School │ │
│ │ (2.5s intro) │ │ Digital Human │ │ Activity │ │ Map │ │
│ └──────────────┘ │ + Chat UI │ │ (AI Photo)│ │ Activity │ │
│ └──────┬───────┘ └──────────┘ └───────────┘ │
│ │ │
│ ┌────────────┼────────────┐ │
│ ▼ ▼ ▼ │
│ DigitalHumanSDKManager │ DigitalHumanWebView │
│ (HTTP speak/chat) │ (WebRTC video stream) │
└───────────────────────────┼────────────────────────────────────────┘
│
┌───────────────┼───────────────┐
▼ ▼ ▼
┌──────────────────┐ ┌──────────────────────────────────────────┐
│ LiveTalking GPU │ │ Django Backend │
│ Server :8010 │ │ ┌─────────┐ ┌──────────┐ ┌──────────┐ │
│ (WebRTC / FLV) │ │ │ Groq AI │ │ Enhanced │ │ Conv. │ │
│ Real-time avatar│ │ │ LLaMA │ │ RAG │ │ Memory │ │
│ video rendering │ │ │ chatbot │ │ FAISS │ │ Service │ │
└──────────────────┘ │ └─────────┘ └──────────┘ └──────────┘ │
│ ┌──────────────────────────────────────┐ │
│ │ SQLite DB · JWT Auth · REST APIs │ │
│ └──────────────────────────────────────┘ │
└──────────────────────────────────────────┘
- Real-time WebRTC Avatar — Live video stream of digital human "Gigi" via LiveTalking
- Lip-sync Speech — Digital human speaks AI responses in real time
- Voice Input — Android speech recognition for hands-free queries
- Multilingual UI — Supports English (
en) and Malay (ms) interface - Animated Subtitle Display — Auto-disappearing subtitles synchronized with speech
- Debug Panel — Hidden developer panel for reconnection and testing
- Smart Background Replacement — ML Kit selfie segmentation for scene swaps
- Face Detection Overlay — Real-time facial landmark tracking
- AI Filter Engine — Color harmony, aesthetic filters, and export pipeline
- Gallery Management — Full photo gallery with edit, crop (uCrop), and share
- Interactive School Map — Multi-floor building maps with room lookup
- Building Information — Tap any building for details and floor plans
- Facility Booking — Integrated room/visit booking interface
- QR Code Generation — Auto-generate QR codes for appointments
- Gigi Chatbot — Groq LLaMA 3.1-8B-Instant powered APU educational counselor
- Enhanced RAG — Multi-strategy retrieval: Vector (FAISS + sentence-transformers), Exact Match, Semantic, Keyword, Category
- 4-Strategy Memory System — Short-term / Cross-learning / RAG-context / Hybrid
- Program Recommendation Engine — Personalized APU program matching by interests & background
- Real-time TTS — Edge-TTS + Groq PlayAI voice synthesis
- Speech-to-Text — SpeechRecognition + Google Speech API with Web Speech fallback
- Fine-tune Pipeline — Groq fine-tuning management with dataset upload
- Admin Dashboard — Full user management, analytics, and knowledge base import
- JWT Authentication — Secure token-based auth with refresh and session management
- ChatGPT-style Chat UI — Modern dark-themed chat interface
- Animated 2D Avatar — Lip-sync GIF avatar with blinking animations
- Conversation History — Create, rename, soft-delete, restore conversations
- Responsive Design — Mobile and desktop compatible
apu数字人最终版/
│
├── app/ # Android Application (Kotlin)
│ └── src/main/
│ ├── AndroidManifest.xml # App permissions & activities
│ ├── java/com/example/snapscenecamera/
│ │ ├── SplashActivity.kt # Launch screen → NewMainActivity
│ │ ├── NewMainActivity.kt # Main hub: digital human + chat
│ │ ├── CameraActivity.kt # AI photography with ML Kit
│ │ ├── EditActivity.kt # Photo editor (filters, crop, export)
│ │ ├── GalleryActivity.kt # Photo gallery & management
│ │ ├── SchoolMapActivity.kt # Campus interactive map
│ │ ├── BookingActivity.kt # Facility booking & QR codes
│ │ ├── SettingsActivity.kt # App settings & language toggle
│ │ ├── DigitalHumanSDKManager.kt # LiveTalking HTTP client (speak/chat)
│ │ ├── DigitalHumanWebView.kt # WebRTC video stream + JS bridge
│ │ ├── DigitalHumanAnimationView.kt # Fallback GIF avatar renderer
│ │ ├── adapter/ # RecyclerView adapters (rooms, floors, gallery)
│ │ ├── data/CampusData.kt # Static campus building & room data
│ │ ├── engine/ # FilterEngine, ColorHarmonyEngine, ExportEngine
│ │ ├── model/ # Building, FloorMap data classes
│ │ ├── ui/FaceOverlayView.kt # ML Kit face detection overlay
│ │ ├── utils/ # ImageSegmentationHelper, ColorCorrectionHelper
│ │ └── view/MapOverlayView.kt # Interactive map tap overlay
│ ├── assets/demo_configs.json # Avatar & TTS demo configuration
│ └── res/
│ ├── layout/ # XML layouts for all activities
│ └── values/ # Strings, colors, themes (EN/MS)
│
├── djangotutorial/
│ ├── README.md # Backend-specific documentation
│ └── backend/ # Django Backend
│ ├── manage.py
│ ├── requirements.txt
│ └── chatbot/ # Django App
│ ├── settings.py # App configuration
│ ├── urls.py # 40+ API endpoint routing
│ ├── views.py # All API view handlers (~96KB)
│ ├── models.py # Database models (~34KB)
│ ├── admin.py # Django admin customization
│ ├── admin_views.py # Knowledge base import view
│ ├── apps.py # RAG pre-initialization on startup
│ ├── migrations/ # 14 database migrations
│ ├── management/commands/ # Django management commands
│ │ ├── finetune_groq.py # Groq fine-tune pipeline
│ │ ├── load_dataset.py # Knowledge base loader
│ │ ├── load_new_dataset.py
│ │ ├── load_training_data.py
│ │ ├── process_conversation_learning.py
│ │ ├── run_finetune.py
│ │ ├── cleanup_sessions.py
│ │ ├── show_db.py
│ │ ├── update_model_defaults.py
│ │ └── create_admin.py
│ ├── services/
│ │ ├── chatbot_service.py # GroqChatbot core (LLM + RAG)
│ │ ├── enhanced_rag_service.py # Multi-strategy vector RAG
│ │ ├── rag_service.py # Base RAG service
│ │ ├── conversation_memory_service.py # 4-strategy memory manager
│ │ ├── program_recommendation_service.py # APU program matcher
│ │ ├── finetune_service.py # Model fine-tuning management
│ │ └── realtime_speech_service.py # Multi-provider STT
│ ├── groq_finetune_data/ # Training & fine-tuning datasets
│ │ ├── apu-educational-counselor_training_data.jsonl (809KB)
│ │ ├── academic-programs-data.jsonl
│ │ ├── academic-studymode-accommodation-data.jsonl
│ │ ├── full_qualification_entries.json (4MB)
│ │ ├── qualification_to_programme.json (326KB)
│ │ └── spm_profiles.json (3.2MB)
│ ├── templates/chatbot/
│ │ ├── index.html # Landing / login page (190KB)
│ │ ├── chat.html # Main chat interface (102KB)
│ │ └── admin_dashboard.html # Admin analytics dashboard
│ └── static/chatbot/
│ ├── avatar/ # Avatar images & animation JS
│ ├── accommodation/ # APU accommodation assets
│ ├── facilities/ # Campus facility images
│ └── icons/ # UI icons
│
└── .k/specs/gpu-server-integration/ # GPU server deployment specs
├── README.md # Server setup guide
├── requirements.md # Server requirements
├── livetalking.service # systemd service file
├── diagnose.sh # Server diagnostics
├── fix_host.sh / fix_network.sh / fix_server.sh # Repair scripts
└── ANDROID_TEST_GUIDE.md # End-to-end test checklist
| Library | Version | Purpose |
|---|---|---|
| Kotlin | 1.9 | Primary language |
| CameraX | 1.3.1 | Camera preview & capture |
| ML Kit Segmentation | 16.0.0-beta4 | Selfie background removal |
| ML Kit Face Detection | 16.1.5 | Face overlay & detection |
| OkHttp | 5.1.0 | HTTP client for API calls |
| Gson | 2.13.1 | JSON parsing |
| Glide | 4.16.0 | Image loading & caching |
| uCrop | 2.2.8 | Photo cropping |
| ZXing | 3.5.2 | QR code generation |
| PhotoView | 2.3.0 | Pinch-zoom image viewer |
| Coroutines | 1.7.3 | Async operations |
| Package | Version | Purpose |
|---|---|---|
| Django | 4.2+ | Web framework |
| Groq | 0.4.0+ | LLM API (LLaMA 3.1) |
| djangorestframework | 3.14+ | REST API |
| djangorestframework-simplejwt | 5.3+ | JWT auth |
| django-cors-headers | 4.0+ | CORS support |
| sentence-transformers | 2.5.1+ | Vector embeddings |
| faiss-cpu | 1.7.4+ | Vector similarity search |
| SpeechRecognition | 3.10+ | Google STT |
| edge-tts | 6.1.0+ | Free high-quality TTS |
| pydub | 0.25.1+ | Audio format conversion |
| requests | 2.31+ | HTTP proxy for LiveTalking |
- Android Studio (Flamingo or later) + Android SDK API 24+
- Python 3.9+
- Groq API Key — console.groq.com
- GPU Server with LiveTalking deployed (or public server:
43.153.51.59:8010)
cd djangotutorial/backend
# Create virtual environment
python -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # macOS/Linux
# Install dependencies
pip install -r requirements.txt
# Configure environment
# Edit chatbot/settings.py and set:
# GROQ_API_KEY = 'your-groq-api-key'
# SECRET_KEY = 'your-django-secret-key'
# Apply database migrations
python manage.py migrate
# Create admin account
python manage.py create_admin
# Load APU knowledge base (choose one)
python manage.py load_new_dataset # Full dataset (recommended)
# OR
python manage.py load_dataset # Base dataset only
# Start the server
python manage.py runserver 0.0.0.0:8000The backend will be available at http://localhost:8000
Admin panel at http://localhost:8000/admin/
The LiveTalking GPU server handles real-time WebRTC-based digital human video rendering.
# On the GPU server (Linux), set up as systemd service:
cp .k/specs/gpu-server-integration/livetalking.service /etc/systemd/system/
systemctl enable livetalking
systemctl start livetalking
# Verify the server is running:
curl http://YOUR_SERVER_IP:8010/webrtcapi.htmlDefault server:
http://43.153.51.59:8010(configured inDigitalHumanSDKManager.ktandchatbot/settings.py)
UpdateDIGITAL_HUMAN_SERVERinsettings.pyto point to your own server.
-
Open the project root in Android Studio.
-
Configure server URLs — Edit
app/src/main/java/com/example/snapscenecamera/DigitalHumanSDKManager.kt:private var djangoBaseUrl: String = "http://YOUR_DJANGO_SERVER:8000"
And update
NewMainActivity.ktfor the LiveTalking server URL. -
Set Groq API Key — Create
local.propertiesin the project root:GROQ_API_KEY=your_groq_api_key_here -
Build and run on a physical device or emulator (API 24+):
Android Studio → Run → Run 'app' -
Permissions required (requested at runtime):
CAMERA— For AI photographyRECORD_AUDIO— For voice inputINTERNET— For API communicationREAD_MEDIA_IMAGES— For gallery access
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/auth/login/ |
Login, returns JWT tokens |
POST |
/api/auth/register/ |
Register new user |
POST |
/api/auth/logout/ |
Logout & invalidate session |
POST |
/api/auth/refresh/ |
Refresh JWT access token |
GET |
/api/auth/status/ |
Check authentication status |
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/chat/ |
Full chat with memory & history |
POST |
/api/chat/simple/ |
Stateless chat (used by Android app) |
GET |
/api/conversations/ |
List all user conversations |
POST |
/api/conversations/create/ |
Create new conversation |
DELETE |
/api/conversations/{id}/delete/ |
Soft delete conversation |
PUT |
/api/conversations/{id}/rename/ |
Rename conversation |
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/transcribe/ |
Audio file → text (STT) |
POST |
/api/tts/ |
Text → audio (TTS) |
GET |
/api/tts/voices/ |
Available TTS voices |
POST |
/api/start-recording/ |
Start microphone capture |
POST |
/api/stop-recording/ |
Stop and transcribe recording |
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/digital-human/offer/ |
WebRTC SDP offer proxy |
POST |
/api/digital-human/send-text/ |
Send text to digital human |
GET |
/api/digital-human/get-audio/ |
Get generated audio |
POST |
/api/digital-human/record/ |
Record digital human response |
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/admin/users/ |
List all users |
GET |
/api/admin/analytics/ |
Usage analytics |
GET |
/api/admin/sessions/ |
Active user sessions |
DELETE |
/api/admin/sessions/{id}/terminate/ |
Terminate user session |
- Model:
Grok(upgrades to fine-tuned model when available) - Persona: APU educational counselor specializing in program guidance
- System Prompt: Includes APU-specific context, program knowledge, fee guidance
- Response: Streamed completion with RAG-enhanced context injection
User Query
│
├─── Vector Search (FAISS + sentence-transformers) ─── Score: 0.0-1.0
├─── Exact Question Match ─────────────────────────── Score: 1.0
├─── Semantic Similarity ──────────────────────────── Score: 0.0-1.0
├─── Keyword Matching ─────────────────────────────── Score: 0.0-0.8
└─── Category Weighting ───────────────────────────── Multiplier
Combined → Top-N Results → Context String → LLM System Prompt
| Strategy | Retention | Best For |
|---|---|---|
short_term |
1 day | Immediate follow-up questions |
cross_learning |
180 days | Learning from corrections |
rag_context |
7 days | Personalized RAG retrieval |
hybrid |
30 days | Production (combines all) |
# Upload training data and trigger Groq fine-tuning:
python manage.py finetune_groq --dataset apu-educational-counselor
# Monitor and activate fine-tuned model:
python manage.py update_model_defaults --activate# Groq AI
GROQ_API_KEY = 'your-groq-api-key-here'
# Digital Human Server
DIGITAL_HUMAN_SERVER = 'http://YOUR_SERVER:8010'
DIGITAL_HUMAN_WEBSOCKET = 'ws://YOUR_SERVER:8010'
DIGITAL_HUMAN_STREAM_URL = 'http://YOUR_SERVER:8080/live/livestream.flv'
DIGITAL_HUMAN_WEBRTC_URL = 'http://YOUR_SERVER:1985/rtc/v1/whep/?app=live&stream=livestream'
# JWT Token Lifetime
SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=60),
'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
}
# Vector embeddings (disable on low-memory servers)
DISABLE_VECTOR_EMBEDDINGS = FalseGROQ_API_KEY=your_groq_api_key_here{
"avatar": {
"defaultBehavior": { "blinking": "human-like" },
"speakingBehavior": {
"onStart": { "mouthAnimation": { "type": "open_half_to_full", "syncWithTTS": true } },
"onEnd": { "mouthAnimation": "close" }
}
},
"tts": {
"voice": { "gender": "female", "preset": "en-US-Wavenet-F" },
"speed": 0.85
}
}The system uses SQLite (development) via Django ORM. Key models:
| Model | Purpose |
|---|---|
UserProfile |
User preferences, theme, language |
Conversation |
Chat sessions with soft-delete support |
Message |
Individual messages per conversation |
UserSession |
JWT session tracking & management |
KnowledgeBaseEntry |
RAG knowledge Q&A pairs |
ConversationMemory |
Multi-strategy memory storage |
TrainingDataset |
Fine-tuning dataset management |
FineTunedModel |
Active fine-tuned model registry |
ProgramRecommendation |
Cached program recommendations |
- Django Backend: Recommended to run with
gunicorn+nginxin production. SetDEBUG = Falseand configure a properSECRET_KEY. - SQLite → PostgreSQL: For production scale, migrate to PostgreSQL by updating
DATABASESinsettings.py. - LiveTalking Server: Requires NVIDIA GPU. Deploy on a cloud GPU instance (e.g., AWS G4, Tencent Cloud) and open ports
8010,8080,1985. - Android Distribution: Build a signed release APK via
Build > Generate Signed Bundle/APKin Android Studio for distribution.
This project is licensed under the MIT License.
Built with ❤️ for Asia Pacific University (APU) Malaysia
Intelligent Digital Human · AI Counseling · Smart Campus Navigation
Developer: Jeffrey Gao
Institution: Asia Pacific University (APU), Malaysia