Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the sentiment analysis pipeline
|
5 |
+
sentiment_pipeline = pipeline("sentiment-analysis")
|
6 |
+
|
7 |
+
# Streamlit UI
|
8 |
+
st.title("Sentiment Analysis")
|
9 |
+
st.write("Enter text below to analyze sentiment:")
|
10 |
+
|
11 |
+
# Text input
|
12 |
+
user_input = st.text_area("Text input")
|
13 |
+
|
14 |
+
# Button to perform sentiment analysis
|
15 |
+
if st.button("Analyze Sentiment"):
|
16 |
+
if user_input:
|
17 |
+
# Perform sentiment analysis
|
18 |
+
results = sentiment_pipeline(user_input)
|
19 |
+
# Display the results
|
20 |
+
sentiment = results[0]['label']
|
21 |
+
score = results[0]['score']
|
22 |
+
st.write(f"Sentiment: {sentiment} (Confidence: {score:.2f})")
|
23 |
+
else:
|
24 |
+
st.write("Please enter some text to analyze.")
|