File size: 2,642 Bytes
8cdbe40
 
 
747d201
c45446a
8cdbe40
 
747d201
123b344
4b44a9b
 
123b344
 
8cdbe40
f541c0d
747d201
41ee349
 
 
 
e38acc3
 
 
 
 
 
 
41ee349
c45446a
b56d254
 
 
 
 
 
b7ec123
b56d254
b7ec123
 
 
f42d3ef
 
 
 
b7ec123
f42d3ef
 
 
 
 
 
2d41505
8cdbe40
 
123b344
 
 
 
b5d21b7
f541c0d
41ee349
 
 
b56d254
 
 
 
 
b7ec123
f42d3ef
 
 
b7ec123
f42d3ef
 
8cdbe40
 
 
745ea4a
8cdbe40
 
 
b7ec123
8cdbe40
 
 
 
728a13e
8cdbe40
 
 
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import numpy as np
import streamlit as st
from transformers import pipeline

import torch

def bertweet(data):
    specific_model = pipeline(model="finiteautomata/bertweet-base-sentiment-analysis")
    result = specific_model(data)
    label = result[0]['label']
    score = result[0]['score']

    return label, score 

def roberta(data):
    specific_model = pipeline(model="cardiffnlp/twitter-roberta-base-sentiment")
    result = specific_model(data)
    label = result[0]['label']
    score = result[0]['score']

    if(label == 'LABEL_0'):
        label = 'Negative'
    elif(label == 'LABEL_1'):
        label = 'Neutral'
    else:
        label = 'Positive'

    return label, score 

def siebert(data):
    specific_model = pipeline(model='siebert/sentiment-roberta-large-english')
    result = specific_model(data)
    label = result[0]['label']
    score = result[0]['score']

    return label, score

def finetuned(data):
    specific_model = pipeline(model='dahongj/finetuned_toxictweets')
    result = specific_model(data)
    max = result[0]['label']
    maxscore = result[0]['score']
    sec = result[1]['label']
    secscore = result[1]['score']

    for i in result:
        if result[i]['score'] > secscore:
            sec = result[i]['label']
            secscore = result[i]['score']

    return max, maxscore, sec, secscore

def getSent(data, model):
    if(model == 'Bertweet'):
        label,score = bertweet(data)
        col1, col2 = st.columns(2)
        col1.metric("Feeling",label,None)
        col2.metric("Score",score,None)
    elif(model == 'Roberta'):
        label,score = roberta(data)
        col1, col2 = st.columns(2)
        col1.metric("Feeling",label,None)
        col2.metric("Score",score,None)
    elif(model == 'Siebert'):
        label,score = siebert(data)
        col1, col2 = st.columns(2)
        col1.metric("Feeling",label,None)
        col2.metric("Score",score,None)
    elif(model == 'Finetuned'):
        label, score, sec, secsc = finetuned(data)
        col1, col2, col3, col4 = st.columns(4)
        col1.metric("Highest",label,None)
        col2.metric("Score",score,None)
        col3.metric("Second Highest", sec, None)
        col4.metric("Score", secsc, None)

def rendPage():
    st.title("Sentiment Analysis")
    userText = st.text_area('User Input', "Hope you are having a great day!")
    st.text("")
    type = st.selectbox(
        'Choose your model',
        ('Bertweet','Roberta','Siebert','Finetuned'))
    st.text("")

    if st.button('Calculate'):
        if(userText!="" and type != None):
            st.text("")
            getSent(userText,type)

rendPage()