Team Ai
Apppublic

Coder19/interview_system

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
interview_socket.py36 linesDownload Raw Back to webrtc
1from fastapi import WebSocket, WebSocketDisconnect2import json3 4async def interview_socket(websocket: WebSocket):5    await websocket.accept()6 7    try:8        while True:9            message = await websocket.receive()10 11            if message["type"] == "websocket.receive":12                if "bytes" in message:13                    audio_data = message["bytes"]14                    # 🔊 You can process the audio here if needed15                    print("Received binary audio")16                elif "text" in message:17                    data = json.loads(message["text"])18                    print("Received text message:", data)19 20                    if data.get("type") == "start_interview":21                        await websocket.send_text(json.dumps({22                            "type": "message",23                            "message": "👋 Hi, I’m your AI Interviewer. What’s your name?"24                        }))25                    26                    elif data.get("type") == "response":27                        user_msg = data.get("message")28                        bot_reply = f"Nice to meet you, {user_msg}. Tell me about your background."29                        await websocket.send_text(json.dumps({30                            "type": "message",31                            "message": bot_reply32                        }))33 34    except WebSocketDisconnect:35        print("❌ Client disconnected")36