File size: 1,754 Bytes
3e27a6a |
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 |
import streamlit as st
from transformers import pipeline
# Load sentiment analysis model
@st.cache_resource
def load_model():
return pipeline(
"sentiment-analysis",
model="distilbert-base-uncased-finetuned-sst-2-english"
)
sentiment_model = load_model()
# Main app
def main():
# UI setup
st.title("Sentiment Analyzer")
st.write("Enter a sentence to analyze its sentiment (Positive/Negative)")
# Text input
user_input = st.text_area("Your Text", placeholder="Type your sentence here...", height=100)
# Analyze button and result display
if st.button("Analyze"):
if user_input:
try:
result = sentiment_model(user_input)[0]
sentiment = result['label']
confidence = result['score']
# Display results
st.success(f"Sentiment: {sentiment}")
st.info(f"Confidence: {confidence:.4f}")
# Footer shown only after analysis
st.markdown("""
<p style="font-size: small; color: grey; text-align: center;">
Developed By: Krishna Prakash
<a href="https://www.linkedin.com/in/krishnaprakash-profile/" target="_blank">
<img src="https://img.icons8.com/ios-filled/30/0077b5/linkedin.png" alt="LinkedIn" style="vertical-align: middle; margin: 0 5px;"/>
</a>
</p>
""", unsafe_allow_html=True)
except Exception as e:
st.error(f"An error occurred: {str(e)}")
else:
st.warning("Please enter some text to analyze!")
if __name__ == "__main__":
main()
|