Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load the sentiment analysis pipeline
|
| 5 |
+
@st.cache(allow_output_mutation=True)
|
| 6 |
+
def load_pipeline():
|
| 7 |
+
return pipeline("sentiment-analysis")
|
| 8 |
+
|
| 9 |
+
classifier = load_pipeline()
|
| 10 |
+
|
| 11 |
+
st.title("Sentiment Analysis App")
|
| 12 |
+
st.write("Enter a sentence to analyze its sentiment.")
|
| 13 |
+
|
| 14 |
+
user_input = st.text_input("Sentence:", "")
|
| 15 |
+
|
| 16 |
+
if st.button("Analyze"):
|
| 17 |
+
if user_input:
|
| 18 |
+
result = classifier(user_input)
|
| 19 |
+
st.write("Sentiment:", result[0]['label'])
|
| 20 |
+
st.write("Confidence:", result[0]['score'])
|
| 21 |
+
else:
|
| 22 |
+
st.write("Please enter a sentence to analyze.")
|