Spaces:
Sleeping
Sleeping
import gradio as gr | |
import torchaudio | |
from transformers import pipeline | |
import numpy as np | |
# Load model for speech emotion recognition | |
emotion_pipeline = pipeline("audio-classification", model="superb/hubert-large-superb-er") | |
# Voice Analysis Logic | |
def analyze_voice(audio): | |
if audio is None: | |
return "Please record or upload your voice." | |
# Get emotion | |
results = emotion_pipeline(audio["array"]) | |
top = max(results, key=lambda x: x["score"]) | |
emotion = top["label"].capitalize() | |
confidence = round(top["score"] * 100, 2) | |
# Personality interpretation (rule-based) | |
personality_map = { | |
"Happy": "You sound energetic, warm, and approachable. Possibly a social butterfly or a natural leader.", | |
"Sad": "You're deep and thoughtful. Often empathetic and emotionally intelligent.", | |
"Angry": "You radiate power and confidence. A strong-willed individual whoβs not afraid to speak out.", | |
"Neutral": "Balanced and calm. Likely introspective and logical in decision-making.", | |
"Fearful": "You might be cautious, observant, and sensitive to surroundings.", | |
"Disgust": "Sharp-witted with a strong sense of right and wrong.", | |
"Surprise": "Curious and spontaneous. You embrace the unexpected with open arms." | |
} | |
persona = personality_map.get(emotion, "A unique voice with a unique mind. Hard to label, easy to admire.") | |
return f""" | |
## ποΈ Voice2Persona-AI Report | |
**Detected Emotion**: {emotion} | |
**Confidence**: {confidence}% | |
**Inferred Personality Vibe**: | |
{persona} | |
""" | |
# Gradio UI | |
demo = gr.Interface( | |
fn=analyze_voice, | |
inputs=gr.Audio(source="microphone", type="numpy", label="π€ Record or Upload Your Voice"), | |
outputs=gr.Markdown(), | |
title="π Voice2Persona-AI", | |
description="Speak for 5β10 seconds and get a fun AI-generated personality profile based on your tone & emotion.", | |
theme="soft", | |
live=True | |
) | |
if __name__ == "__main__": | |
demo.launch() |