Maham930 commited on
Commit
a8e1d7b
·
verified ·
1 Parent(s): b807c3f

Added code for sentiment analysis

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # sentiment_app.py
2
+
3
+ import streamlit as st
4
+ from transformers import pipeline
5
+
6
+ # Load sentiment analysis pipeline
7
+ @st.cache_resource
8
+ def load_model():
9
+ return pipeline("sentiment-analysis")
10
+
11
+ classifier = load_model()
12
+
13
+ # Streamlit UI
14
+ st.set_page_config(page_title="Sentiment Classifier", layout="centered")
15
+ st.title("🧠 Sentiment Classification App")
16
+ st.write("Enter a piece of text, and the model will predict its sentiment.")
17
+
18
+ # Text input
19
+ text_input = st.text_area("Enter your text here", height=150)
20
+
21
+ # Predict button
22
+ if st.button("Classify Sentiment"):
23
+ if text_input.strip() == "":
24
+ st.warning("Please enter some text to analyze.")
25
+ else:
26
+ with st.spinner("Analyzing..."):
27
+ result = classifier(text_input)
28
+ label = result[0]['label']
29
+ score = result[0]['score']
30
+ st.success(f"**Prediction:** {label} ({score:.2f} confidence)")