Spaces:
Sleeping
Sleeping
WilliamVoster commited on
Commit ·
74428fe
1
Parent(s): b030947
basic sentiment analysis demo, with defaults
Browse files- src/streamlit_app.py +22 -24
src/streamlit_app.py
CHANGED
|
@@ -1,32 +1,30 @@
|
|
| 1 |
-
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
|
|
|
|
| 7 |
|
| 8 |
-
num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
|
| 9 |
-
num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
|
| 10 |
|
| 11 |
-
|
| 12 |
-
theta = 2 * np.pi * num_turns * indices
|
| 13 |
-
radius = indices
|
| 14 |
|
| 15 |
-
x = radius * np.cos(theta)
|
| 16 |
-
y = radius * np.sin(theta)
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
"rand": np.random.randn(num_points),
|
| 23 |
-
})
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
| 1 |
+
|
|
|
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
|
| 5 |
+
st.title("Sentiment Analysis")
|
| 6 |
+
|
| 7 |
+
@st.cache_resource
|
| 8 |
+
def load_pipe():
|
| 9 |
+
return pipeline("sentiment-analysis")
|
| 10 |
|
| 11 |
|
| 12 |
+
sentiment_analysis_classifier = load_pipe()
|
| 13 |
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
user_input = st.text_area("Enter text to analyze:")
|
|
|
|
|
|
|
| 16 |
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
if st.button("Analyze"):
|
| 19 |
+
if user_input:
|
| 20 |
+
|
| 21 |
+
result = sentiment_analysis_classifier(user_input)[0]
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
label = result['label']
|
| 24 |
+
score = result['score']
|
| 25 |
+
|
| 26 |
+
st.write(f"**Sentiment:** {label}")
|
| 27 |
+
st.progress(score)
|
| 28 |
+
st.write(f"Confidence: {100*score:.2f}%")
|
| 29 |
+
else:
|
| 30 |
+
st.warning("Please enter some text.")
|