Krishna086's picture
Create app.py
3e27a6a verified
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()