usamaferoz12 commited on
Commit
f2a367d
1 Parent(s): fc9e735

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Load the sentiment analysis pipeline
5
+ pipe = pipeline("text-classification", model="finiteautomata/bertweet-base-sentiment-analysis")
6
+
7
+ # Define a function to perform sentiment analysis
8
+ def analyze_sentiment(text):
9
+ results = pipe(text)
10
+ sentiment = results[0]['label']
11
+ confidence = results[0]['score']
12
+ return sentiment, confidence
13
+
14
+ # Create a Streamlit app
15
+ st.title("Sentiment Analysis App")
16
+
17
+ # Get the user input
18
+ text = st.text_input("Enter text for sentiment analysis")
19
+
20
+ # Perform sentiment analysis
21
+ sentiment, confidence = analyze_sentiment(text)
22
+
23
+ # Display the output
24
+ if sentiment == "POSITIVE":
25
+ st.success(f"Sentiment: Positive, Confidence: {confidence:.2f}")
26
+ elif sentiment == "NEGATIVE":
27
+ st.error(f"Sentiment: Negative, Confidence: {confidence:.2f}")
28
+ else:
29
+ st.info(f"Sentiment: Neutral, Confidence: {confidence:.2f}")