Spaces:
Sleeping
Sleeping
File size: 2,773 Bytes
3ab6535 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
import streamlit as st
from utils.ui_helpers import format_sentiment_result, plot_sentiment_gauge
def show_sentiment_analyzer(nlp_engine):
"""Display the sentiment analysis UI component"""
#st.markdown("๐๐โน๏ธ - ๐")
st.title("Sentiment Analysis๐๐โน๏ธโก๏ธ๐")
st.markdown("""
Analyze the sentiment of text using the DistilBERT model fine-tuned on the SST-2 dataset.
This model classifies text as either positive or negative.
""")
# Text input
text_input = st.text_area(
"Enter text to analyze sentiment",
"Hugging Face is a great platform for NLP.",
height=150
)
# Process button
if st.button("Analyze Sentiment"):
with st.spinner("Analyzing sentiment..."):
# Get sentiment
sentiment_result = nlp_engine.analyze_sentiment(text_input)
# Format results
formatted_result = format_sentiment_result(sentiment_result)
# Display results
st.markdown("### Results")
# Create columns for layout
col1, col2 = st.columns([1, 1])
with col1:
st.markdown(f"### {formatted_result['emoji']} {formatted_result['dataframe'].iloc[0]['Label']}")
st.dataframe(formatted_result['dataframe'], hide_index=True)
with col2:
# Display gauge chart
st.plotly_chart(
plot_sentiment_gauge(
formatted_result['score'],
formatted_result['color']
),
use_container_width=True
)
# Example section
with st.expander("Example texts to try"):
st.markdown("""
- This movie was absolutely terrible. The acting was poor and the plot made no sense.
- I had the best time at the concert! The band was amazing and the crowd was so energetic.
- The weather today is okay, not great but not bad either.
- I'm absolutely thrilled with the results of this project. Everything exceeded my expectations!
""")
# Information about the model
with st.expander("About this model"):
st.markdown("""
**Model**: `distilbert-base-uncased-finetuned-sst-2-english`
This is a DistilBERT model fine-tuned on the Stanford Sentiment Treebank v2 (SST-2) dataset.
- **Accuracy**: ~91% on the SST-2 validation set
- **Size**: 66M parameters (compared to BERT's 110M)
- **Speed**: ~60% faster than BERT
The model classifies text as either positive (LABEL_1) or negative (LABEL_0).
""")
|