WilliamVoster commited on
Commit
74428fe
·
1 Parent(s): b030947

basic sentiment analysis demo, with defaults

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +22 -24
src/streamlit_app.py CHANGED
@@ -1,32 +1,30 @@
1
- import altair as alt
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
- indices = np.linspace(0, 1, num_points)
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
- df = pd.DataFrame({
19
- "x": x,
20
- "y": y,
21
- "idx": indices,
22
- "rand": np.random.randn(num_points),
23
- })
24
 
25
- st.altair_chart(alt.Chart(df, height=700, width=700)
26
- .mark_point(filled=True)
27
- .encode(
28
- x=alt.X("x", axis=None),
29
- y=alt.Y("y", axis=None),
30
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
31
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
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.")