import gradio as gr from transformers import pipeline from datetime import datetime import sqlite3 import os import random # ------------------------------------------------- # 🎯 MODEL INITIALIZATION # ------------------------------------------------- MODEL_NAME = "superb/hubert-large-superb-er" emotion_classifier = pipeline("audio-classification", model=MODEL_NAME) # (Optional) Simulated DB path os.makedirs("data", exist_ok=True) DB_PATH = "data/scm_emotion.db" # ------------------------------------------------- # 😄 EMOTION MAP + COLORS # ------------------------------------------------- EMOTION_MAP = { "ang": ("Angry", "😡", "#ff4d4d"), "hap": ("Happy", "😄", "#4caf50"), "neu": ("Neutral", "😐", "#9e9e9e"), "sad": ("Sad", "😢", "#2196f3"), "exc": ("Excited", "🤩", "#ff9800"), "fru": ("Frustrated", "😤", "#f44336"), "fea": ("Fearful", "😨", "#673ab7"), "sur": ("Surprised", "😲", "#00bcd4"), "dis": ("Disgusted", "🤢", "#8bc34a"), } # ------------------------------------------------- # 🧠 EMOTION ANALYSIS # ------------------------------------------------- def analyze_emotion(audio, team, purpose): if audio is None: return "
⚠️ Please record or upload audio.
", None # If team/purpose not filled if team == "Other": team = "Custom/Unspecified" if purpose == "Other": purpose = "Custom/Unspecified" results = emotion_classifier(audio) results = sorted(results, key=lambda x: x['score'], reverse=True) top = results[0] label, emoji, color = EMOTION_MAP.get(top['label'], (top['label'], "🎭", "#607d8b")) score = round(top['score'] * 100, 2) # Dashboard HTML dashboard_html = f"""Detected Emotion Intensity (Confidence)
{insights}
(Demo mode — not stored to any database)
This is a demonstration version created for HR and leadership showcases.
Your voice data is
NOT being saved or shared
anywhere.
Database logging is simulated — you can record or upload audio freely.
✅ Safe to explore and test in this environment.
Analyze live or uploaded audio from meetings to understand emotional tone within teams.
Built for HR & Managers to assess engagement and team well-being.
💾 (Demo Mode) Database integration coming soon for Power BI visualization.
""") if __name__ == "__main__": app.launch(server_name="0.0.0.0", server_port=7860)