Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import plotly.express as px
|
3 |
+
from plotly.subplots import make_subplots
|
4 |
+
from utils import *
|
5 |
+
|
6 |
+
########## Title for the Web App ##########
|
7 |
+
st.title("Text Classification for HC")
|
8 |
+
|
9 |
+
########## Create Input field ##########
|
10 |
+
feedback = st.text_input('Type your text here', 'Customer suggested that the customer service needs to be improved and the response time needs to be improved.')
|
11 |
+
|
12 |
+
if st.button('Click for predictions!'):
|
13 |
+
with st.spinner('Generating predictions...'):
|
14 |
+
|
15 |
+
topics_prob, sentiment_prob = get_single_prediction(feedback)
|
16 |
+
|
17 |
+
bar = px.bar(topics_prob, x='probability', y='topic')
|
18 |
+
|
19 |
+
pie = px.pie(sentiment_prob,
|
20 |
+
values='probability',
|
21 |
+
names='sentiment',
|
22 |
+
color_discrete_map={'positive':'rgb(0, 204, 0)',
|
23 |
+
'negative':'rgb(215, 11, 11)'
|
24 |
+
},
|
25 |
+
color='sentiment'
|
26 |
+
)
|
27 |
+
|
28 |
+
st.plotly_chart(bar, use_container_width=True)
|
29 |
+
st.plotly_chart(pie, use_container_width=True)
|
30 |
+
|
31 |
+
st.write("\n")
|
32 |
+
st.subheader('Or... Upload a csv file if you have a file instead.')
|
33 |
+
st.write("\n")
|
34 |
+
|
35 |
+
st.download_button(
|
36 |
+
label="Download sample file here",
|
37 |
+
data=sample_file,
|
38 |
+
file_name='sample_data.csv',
|
39 |
+
mime='text/csv',
|
40 |
+
)
|
41 |
+
|
42 |
+
uploaded_file = st.file_uploader("Please upload a csv file with only 1 column of texts.")
|
43 |
+
|
44 |
+
if uploaded_file is not None:
|
45 |
+
|
46 |
+
with st.spinner('Generating predictions...'):
|
47 |
+
results = get_multiple_predictions(uploaded_file)
|
48 |
+
|
49 |
+
st.download_button(
|
50 |
+
label="Download results as CSV",
|
51 |
+
data=results,
|
52 |
+
file_name='results.csv',
|
53 |
+
mime='text/csv',
|
54 |
+
)
|
55 |
+
|
56 |
+
|