muqeet1234 commited on
Commit
677d337
·
verified ·
1 Parent(s): cd8b6f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py CHANGED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Title and description
5
+ st.title("Text Sentiment Analyzer")
6
+ st.markdown("Analyze the sentiment of your text using a pre-trained Hugging Face model.")
7
+
8
+ # Load the sentiment analysis pipeline
9
+ @st.cache_resource
10
+ def load_sentiment_model():
11
+ return pipeline("sentiment-analysis")
12
+
13
+ sentiment_model = load_sentiment_model()
14
+
15
+ # Input box for user-provided text
16
+ user_input = st.text_area("Enter text to analyze sentiment:", placeholder="Type something here...")
17
+
18
+ # Analyze button
19
+ if st.button("Analyze"):
20
+ if user_input.strip():
21
+ # Perform sentiment analysis
22
+ with st.spinner("Analyzing sentiment..."):
23
+ result = sentiment_model(user_input)
24
+ sentiment = result[0]["label"]
25
+ confidence = result[0]["score"]
26
+
27
+ # Display results
28
+ st.write(f"**Sentiment:** {sentiment}")
29
+ st.write(f"**Confidence Score:** {confidence:.2f}")
30
+ else:
31
+ st.warning("Please enter some text to analyze.")
32
+
33
+ # Footer
34
+ st.markdown("---")
35
+ st.markdown("Powered by [Hugging Face Transformers](https://huggingface.co/transformers/) and Streamlit.")