nimra2019 commited on
Commit
28da6d0
·
verified ·
1 Parent(s): 9e39540

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Load sentiment-analysis pipeline
5
+ @st.cache_resource
6
+ def load_model():
7
+ return pipeline("sentiment-analysis")
8
+
9
+ analyzer = load_model()
10
+
11
+ # Streamlit app UI
12
+ st.title("🧠 Sentiment Analysis App")
13
+ st.write("Enter text to analyze the sentiment (Positive/Negative)")
14
+
15
+ user_input = st.text_area("Your text:")
16
+
17
+ if st.button("Analyze"):
18
+ if user_input.strip() == "":
19
+ st.warning("Please enter some text.")
20
+ else:
21
+ with st.spinner("Analyzing..."):
22
+ result = analyzer(user_input)
23
+ label = result[0]['label']
24
+ score = result[0]['score']
25
+ st.success(f"**Sentiment:** {label} \n**Confidence:** {score:.2f}")