CoolFace
Apppublic

Pravin30994/career_discovery

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
App README

πŸŽ“ 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:

ModelPurposeSizeProvider
moonshine-baseSpeech-to-Text~250 MBUsefulSensors
Phi-3.5-mini-instructConversational AI~7.5 GBMicrosoft
Kokoro-82MText-to-Speech~300 MBhexgrad

Total model size: ~8 GB (cached after first run)


πŸ“‘ API Endpoints

Core Endpoints

bash
# 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

python
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)

javascript
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

HardwareRAMVRAMBoot TimeResponse Time
CPU Basic16 GBβ€”12-15 min15-20 sec
T4 small16 GB16 GB10 min4-5 sec
A10G small24 GB24 GB8 min2-3 sec

Recommendation: Start with CPU Basic (free) for testing. Upgrade to T4 small for production.


Environment Variables (Optional)

Set in Space Settings β†’ Variables:

bash
# 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`:

python
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:

  1. 1.Check browser console for specific error
  2. 2.Verify request headers match CORS config
  3. 3.Try request from Swagger UI (/docs) first

Out of Memory

Solution 1: Upgrade to T4 small (more VRAM)

Solution 2: Use smaller models:

python
# 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: /docs endpoint
  • β€”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.py uploaded
  • β€”[ ] requirements.txt uploaded
  • β€”[ ] Dockerfile uploaded
  • β€”[ ] Space building (check Logs)
  • β€”[ ] Test /api/health endpoint
  • β€”[ ] Test /docs Swagger 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.