Jacob Jaroya commited on
Commit
7a801db
1 Parent(s): cc15aa8

app update

Browse files
Files changed (1) hide show
  1. app.py +89 -0
app.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import streamlit.components.v1 as com
3
+ #import libraries
4
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer, AutoConfig
5
+ import numpy as np
6
+ #convert logits to probabilities
7
+ from scipy.special import softmax
8
+ from transformers import pipeline
9
+
10
+ #Set the page configs
11
+ st.set_page_config(page_title='Movie Sentiments Analysis',page_icon='🎬',layout='wide')
12
+
13
+ # Movie Sentiment Analysis Animation
14
+ st.markdown("<h1 style='text-align: center'> Movie Sentiment Analysis </h1>", unsafe_allow_html=True)
15
+ st.image("https://media.istockphoto.com/id/1055587418/vector/banner-for-online-cinema-with-old-movie-projector.jpg?s=612x612&w=0&k=20&c=ZsMSmd6CZfuUVDAvUSTb9XHBqeg4ucb43n52xV5-y1c=", use_column_width=True)
16
+ st.write("<h2 style='font-size: 24px;'> Analyze movie reviews and discover the sentiment of the audience </h2>", unsafe_allow_html=True)
17
+
18
+
19
+ # Create a form to take user inputs
20
+ with st.form(key='sentence', clear_on_submit = True):
21
+ # Input text
22
+ text = st.text_area('Copy and paste a sentence(s) or type one',
23
+ placeholder='I really enjoyed the movie, it was so entertaining.')
24
+ # Set examples related to movie sentiments
25
+ alt_text = st.selectbox("Can't Type? Select an Example below", (
26
+ 'The movie was amazing, I loved every moment of it.',
27
+ 'I found the acting in the movie to be quite impressive.',
28
+ 'This film was a complete waste of my time, terrible.',
29
+ 'The plot of the movie was confusing and hard to follow.',
30
+ 'The cinematography in this film is outstanding.'))
31
+ # Select a model
32
+ models = {
33
+ 'Bert': 'UholoDala/sentence_sentiments_analysis_bert',
34
+ 'Distilbert': 'UholoDala/sentence_sentiments_analysis_distilbert',
35
+ 'Roberta': 'UholoDala/sentence_sentiments_analysis_roberta'
36
+ }
37
+ model = st.selectbox('Which model would you want to Use?', ('Bert', 'Distilbert', 'Roberta'))
38
+ # Submit
39
+ submit = st.form_submit_button('Predict', 'Continue processing input')
40
+
41
+
42
+ # Clear button
43
+ clear = st.button('Clear')
44
+
45
+
46
+
47
+ selected_model=models[model]
48
+
49
+
50
+ #create columns to show outputs
51
+ col1,col2,col3=st.columns(3)
52
+ col1.write('<h2 style="font-size: 24px;"> Sentiment Emoji </h2>',unsafe_allow_html=True)
53
+ col2.write('<h2 style="font-size: 24px;"> How this user feels about the movie </h2>',unsafe_allow_html=True)
54
+ col3.write('<h2 style="font-size: 24px;"> Confidence of this prediction </h2>',unsafe_allow_html=True)
55
+
56
+ if submit:
57
+ #Check text
58
+ if text=="":
59
+ text=alt_text
60
+ st.success(f"Input text is set to: '{text}'")
61
+ else:
62
+ st.success('Text received',icon='✅')
63
+
64
+ #import the model
65
+ pipe=pipeline(model=selected_model)
66
+
67
+ #pass text to model
68
+ output=pipe(text)
69
+ output_dict=output[0]
70
+ lable=output_dict['label']
71
+ score=output_dict['score']
72
+
73
+ #output
74
+ if lable=='NEGATIVE' or lable=='LABEL_0':
75
+ with col1:
76
+ com.iframe("https://embed.lottiefiles.com/animation/125694")
77
+ col2.write('NEGATIVE')
78
+ col3.write(f'{score:.2%}')
79
+ else:
80
+ lable=='POSITIVE'or lable=='LABEL_2'
81
+ with col1:
82
+ com.iframe("https://embed.lottiefiles.com/animation/148485")
83
+ col2.write('POSITIVE')
84
+ col3.write(f'{score:.2%}')
85
+
86
+ # Clear button action
87
+ text = "" # Clear the input text
88
+ if clear:
89
+ st.success('Input fields cleared', icon='✅')