Spaces:
No application file
No application file
| import streamlit as st | |
| from transformers import pipeline | |
| # Set page config | |
| st.set_page_config(page_title="Sentiment Analyzer", layout="centered") | |
| # Header | |
| st.markdown("<h1 style='text-align: center; color: #4CAF50;'>๐ง Sentiment Analyzer App</h1>", unsafe_allow_html=True) | |
| st.markdown("<p style='text-align: center;'>Using Hugging Face Transformers with Streamlit</p>", unsafe_allow_html=True) | |
| # Input area | |
| st.write("### Enter your text below:") | |
| text = st.text_area("") | |
| # Button to run analysis | |
| if st.button("๐ Analyze Sentiment"): | |
| if text.strip() == "": | |
| st.warning("Please enter some text!") | |
| else: | |
| # Load model | |
| classifier = pipeline("sentiment-analysis") | |
| result = classifier(text)[0] | |
| label = result["label"] | |
| score = result["score"] | |
| # Output result | |
| st.success(f"**Sentiment:** {label}") | |
| st.info(f"**Confidence Score:** {score:.2f}") | |
| # Display bar chart | |
| st.write("### Sentiment Analysis Results") | |
| st.bar_chart({"Sentiment": [label], "Score": [score]}) | |