Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from transformers import pipeline | |
| import numpy as np | |
| print ("Load model...") | |
| # Load the pre-trained emotion classification pipeline | |
| model_name = "bhadresh-savani/distilbert-base-uncased-emotion" | |
| emotion_classifier = pipeline("text-classification", model=model_name) | |
| # Title and Description | |
| st.title("Emotion Classifier") | |
| st.write("""write down how your day went or what your mood is.""") | |
| st.write("""On this space used model "bhadresh-savani/distilbert-base-uncased-emotion". | |
| """) | |
| # Input text box | |
| input_text = st.text_area("Enter text to analyze emotions:", "") | |
| if st.button("Classify Emotion"): | |
| if input_text.strip() == "": | |
| st.write("Please enter some text to classify.") | |
| else: | |
| # Get classification results | |
| results = emotion_classifier(input_text, top_k=None) | |
| # Extract scores and normalize to sum to 1 | |
| scores = np.array([result["score"] for result in results]) | |
| normalized_scores = scores / scores.sum() | |
| # Display normalized results | |
| st.subheader("Emotions:") | |
| for i, result in enumerate(results): | |
| st.write(f"**{result['label']}**: {normalized_scores[i]:.4f}") |