|
import streamlit as st |
|
from transformers import pipeline |
|
|
|
|
|
@st.cache_resource |
|
def load_model(): |
|
return pipeline( |
|
"sentiment-analysis", |
|
model="distilbert-base-uncased-finetuned-sst-2-english" |
|
) |
|
|
|
sentiment_model = load_model() |
|
|
|
|
|
def main(): |
|
|
|
st.title("Sentiment Analyzer") |
|
st.write("Enter a sentence to analyze its sentiment (Positive/Negative)") |
|
|
|
|
|
user_input = st.text_area("Your Text", placeholder="Type your sentence here...", height=100) |
|
|
|
|
|
if st.button("Analyze"): |
|
if user_input: |
|
try: |
|
result = sentiment_model(user_input)[0] |
|
sentiment = result['label'] |
|
confidence = result['score'] |
|
|
|
|
|
st.success(f"Sentiment: {sentiment}") |
|
st.info(f"Confidence: {confidence:.4f}") |
|
|
|
|
|
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() |
|
|