Pravin30994/career_discovery
π Career Discovery AI β Full Backend
AI-Powered Career Counseling Platform for High School Students
Voice-based conversational AI that helps students discover their ideal career path through intelligent dialogue.
π Live Demo
Once deployed, your API will be available at:
https://YOUR_USERNAME-career-discovery.hf.space/API Documentation (Swagger UI):
https://YOUR_USERNAME-career-discovery.hf.space/docsπ€ AI Models
This Space runs three state-of-the-art open-source models:
Total model size: ~8 GB (cached after first run)
π‘ API Endpoints
Core Endpoints
# Health check
GET /api/health
# Model status
GET /api/models/status
# Speech to text
POST /api/stt
Content-Type: multipart/form-data
Body: audio file (wav/webm/ogg)
# Generate AI response
POST /api/llm
Content-Type: application/json
Body: {
"student": {
"name": "Alex Chen",
"grade": "Grade 11",
"curriculum": "IB",
"subjects": "Maths, Computer Science",
"interests": "Coding, robotics"
},
"messages": [
{"role": "assistant", "content": "Hi Alex! Ready to explore?"},
{"role": "user", "content": "Yes! I love math and coding."}
],
"phase": "interests"
}
# Text to speech
POST /api/tts
Content-Type: application/json
Body: {"text": "Hello, I'm Ivy, your career coach!"}
# Generate career report (JSON)
POST /api/report
Content-Type: application/json
Body: {
"student": {...},
"history": [...]
}
# Generate career report (PDF)
POST /api/report/pdf
Content-Type: application/json
Body: {
"student": {...},
"history": [...]
}π― Features
β Voice Input: Record audio β automatic transcription β Conversational AI: Natural dialogue powered by Phi-3.5 β Voice Output: AI responses spoken aloud via neural TTS β Career Analysis: LLM-generated personalized career reports β PDF Export: Professional downloadable reports β Phase-Aware: Structured 6-phase conversation flow β Insight Extraction: Real-time analysis of interests & strengths
π§ Usage Example
Python Client
import requests
BASE = "https://YOUR_USERNAME-career-discovery.hf.space"
# Step 1: Student speaks
with open("recording.wav", "rb") as f:
files = {"audio": f}
r = requests.post(f"{BASE}/api/stt", files=files)
transcript = r.json()["text"]
print(f"Student said: {transcript}")
# Step 2: AI generates reply
payload = {
"student": {
"name": "Test Student",
"grade": "Grade 11",
"curriculum": "IB",
"subjects": "Math",
"interests": "Coding"
},
"messages": [
{"role": "user", "content": transcript}
],
"phase": "interests"
}
r = requests.post(f"{BASE}/api/llm", json=payload)
reply = r.json()["reply"]
print(f"AI reply: {reply}")
# Step 3: Convert reply to speech
r = requests.post(f"{BASE}/api/tts", json={"text": reply})
with open("response.wav", "wb") as f:
f.write(r.content)
print("β Saved audio response")JavaScript (Browser)
const API = 'https://YOUR_USERNAME-career-discovery.hf.space';
// Record audio with MediaRecorder
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
const recorder = new MediaRecorder(stream);
const chunks = [];
recorder.ondataavailable = e => chunks.push(e.data);
recorder.onstop = async () => {
const blob = new Blob(chunks, { type: 'audio/webm' });
// Send to STT
const formData = new FormData();
formData.append('audio', blob);
const sttRes = await fetch(`${API}/api/stt`, {
method: 'POST',
body: formData
});
const { text } = await sttRes.json();
console.log('Transcribed:', text);
// Get AI reply
const llmRes = await fetch(`${API}/api/llm`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
student: { name: 'Alex', grade: 'Grade 11', curriculum: 'IB', subjects: '', interests: '' },
messages: [{ role: 'user', content: text }],
phase: 'interests'
})
});
const { reply } = await llmRes.json();
console.log('AI reply:', reply);
// Play TTS
const ttsRes = await fetch(`${API}/api/tts`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text: reply })
});
const audioBlob = await ttsRes.blob();
const url = URL.createObjectURL(audioBlob);
new Audio(url).play();
};
recorder.start();
// ... user speaks ...
recorder.stop();ποΈ Architecture
Browser/Client
β
FastAPI Server (port 7860)
β
βββββββββββββββ¬ββββββββββββββ¬ββββββββββββββ
β β β β
Moonshine STT Phi-3.5 LLM Kokoro TTS
β β β
SpeechβText Conversation TextβSpeech
β β β
βββββββββββββββ΄ββββββββββββββ
β
Career Reports
(JSON/PDF)βοΈ Configuration
Hardware Requirements
Recommendation: Start with CPU Basic (free) for testing. Upgrade to T4 small for production.
Environment Variables (Optional)
Set in Space Settings β Variables:
# Custom model cache location
HF_HOME=/data/models
# Hugging Face token (for private models)
HF_TOKEN=hf_xxxxxxxxxxxx
# Logging level
LOG_LEVEL=INFOπ Performance
Model Loading (first run):
- Downloads: ~8 GB
- Time: 10-15 minutes
- Subsequent runs: 30-60 seconds (cached)
Inference Speed (T4 GPU):
- STT: ~0.5 seconds per 10s audio
- LLM: ~2-3 seconds per response
- TTS: ~0.8 seconds per sentence
- Total turn: ~4-5 seconds
Inference Speed (CPU):
- STT: ~3 seconds per 10s audio
- LLM: ~12 seconds per response
- TTS: ~2 seconds per sentence
- Total turn: ~17 seconds
π Security Notes
β οΈ *This Space is configured with `allow_origins=[""]`** for maximum compatibility during development.
For production, restrict CORS in `server.py`:
app.add_middleware(
CORSMiddleware,
allow_origins=[
"https://yourdomain.com",
"https://app.yourdomain.com"
],
allow_methods=["*"],
allow_headers=["*"],
)Consider adding:
- Rate limiting (via
slowapi) - API key authentication
- Input validation & sanitization
- Request logging & monitoring
π Troubleshooting
Models Not Loading
Check logs (Space β Logs tab) for:
Loading STT (moonshine-base)β¦
STT ready β
Loading LLM (Phi-3.5-mini-instruct)β¦
LLM ready β
Loading TTS (Kokoro-82M)β¦
TTS ready β
All models loaded β server ready πIf any model fails:
- Increase hardware tier (more RAM/VRAM)
- Check model names are correct
- Verify network connectivity
CORS Errors
Already configured for * (all origins).
If still encountering CORS issues:
- Check browser console for specific error
- Verify request headers match CORS config
- Try request from Swagger UI (
/docs) first
Out of Memory
Solution 1: Upgrade to T4 small (more VRAM)
Solution 2: Use smaller models:
# In server.py, replace with:
model_id = "TinyLlama/TinyLlama-1.1B-Chat-v1.0" # ~2 GBπ License
This Space uses:
- Moonshine: Apache 2.0
- Phi-3.5: MIT License
- Kokoro: Apache 2.0
- FastAPI: MIT License
All models are open-source and free for commercial use.
π Links
- Frontend (HTML/JS): [Connect via API URL above]
- Swagger Documentation:
/docsendpoint - Source Code: Included in this Space
- Hugging Face Hub: https://huggingface.co/spaces
π― Use Cases
β High School Career Counseling β Students explore career paths β Educational Platforms β Integrate career guidance into LMS β College Prep Services β Help students choose majors β Career Coaching Apps β Voice-first career exploration β Research & Development β Test conversational AI systems
π Support
Issues with this Space:
- Check Logs tab for errors
- Test endpoints via
/docs(Swagger UI) - Verify all 3 files are uploaded correctly
Hugging Face Support:
- Community Forum: https://discuss.huggingface.co/
- Documentation: https://huggingface.co/docs/hub/spaces
π Quick Start Checklist
- [x] Space created with Docker SDK
- [ ]
server.pyuploaded - [ ]
requirements.txtuploaded - [ ]
Dockerfileuploaded - [ ] Space building (check Logs)
- [ ] Test
/api/healthendpoint - [ ] Test
/docsSwagger UI - [ ] Connect frontend with API URL
- [ ] Upgrade to T4 if needed
Built with β€οΈ using Hugging Face Transformers
Powered by open-source AI models for accessible, privacy-respecting career guidance.
