File size: 972 Bytes
640262e
 
 
bdfe5a9
640262e
a4cdb08
640262e
9787b63
640262e
 
 
3503540
640262e
 
 
 
 
 
 
 
a4cdb08
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import streamlit as st
from transformers import pipeline

st.title('Sentiment Analysis using Transformers pipeline function')

# steamlit form
form = st.form(key='sentiment-form')
user_input = form.text_area(label = 'Enter your text', value = "I love steamlit and hugging face!")
submit = form.form_submit_button('Submit')

if submit:
    classifier = pipeline("sentiment-analysis") #using the pipeline() function
    result = classifier(user_input)[0]
    label = result['label']
    score = result['score']

    if label == 'POSITIVE':
        st.success(f'{label} sentiment (score: {score})')
    else:
        st.error(f'{label} sentiment (score: {score})')



st.write('References:')
st.write('1. https://medium.com/@rtkilian/deploy-and-share-your-sentiment-analysis-app-using-streamlit-sharing-2ba3ca6a3ead')
st.write('2. https://huggingface.co/learn/nlp-course/chapter1/3?fw=pt')
st.write('3. https://docs.streamlit.io/library/api-reference/widgets/st.text_input')