abdullah099 commited on
Commit
9bc1121
·
verified ·
1 Parent(s): 36b86d5

Upload assignment.py

Browse files
Files changed (1) hide show
  1. assignment.py +33 -0
assignment.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Set page config
5
+ st.set_page_config(page_title="Sentiment Analyzer", layout="centered")
6
+
7
+ # Header
8
+ st.markdown("<h1 style='text-align: center; color: #4CAF50;'>🧠 Sentiment Analyzer App</h1>", unsafe_allow_html=True)
9
+ st.markdown("<p style='text-align: center;'>Using Hugging Face Transformers with Streamlit</p>", unsafe_allow_html=True)
10
+
11
+ # Input area
12
+ st.write("### Enter your text below:")
13
+ text = st.text_area("")
14
+
15
+ # Button to run analysis
16
+ if st.button("🔍 Analyze Sentiment"):
17
+ if text.strip() == "":
18
+ st.warning("Please enter some text!")
19
+ else:
20
+ # Load model
21
+ classifier = pipeline("sentiment-analysis")
22
+ result = classifier(text)[0]
23
+ label = result["label"]
24
+ score = result["score"]
25
+
26
+ # Output result
27
+ st.success(f"**Sentiment:** {label}")
28
+ st.info(f"**Confidence Score:** {score:.2f}")
29
+
30
+ # Display bar chart
31
+ st.write("### Sentiment Analysis Results")
32
+ st.bar_chart({"Sentiment": [label], "Score": [score]})
33
+