khadija3818 commited on
Commit
f4f0513
·
1 Parent(s): 89c5209

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+
4
+ # Load the sentiment analysis model from Hugging Face
5
+ sentiment_analysis = pipeline("sentiment-analysis")
6
+
7
+ # Function to get sentiment prediction
8
+ def predict_sentiment(text):
9
+ result = sentiment_analysis(text)
10
+ label = result[0]['label']
11
+ score = result[0]['score']
12
+ return label, score
13
+
14
+ # Streamlit web app
15
+ def main():
16
+ st.title("Sentiment Analysis App")
17
+
18
+ # Input text area
19
+ user_input = st.text_area("Enter text:", "Type or paste your text here...")
20
+
21
+ # Button to trigger sentiment prediction
22
+ if st.button("Predict Sentiment"):
23
+ # Display the result
24
+ sentiment_label, sentiment_score = predict_sentiment(user_input)
25
+ st.write(f"Sentiment: {sentiment_label}, Score: {sentiment_score:.4f}")
26
+
27
+ # Run the app
28
+ if __name__ == "__main__":
29
+ main()
30
+