File size: 4,515 Bytes
c402a4a
 
 
 
 
 
 
 
 
2193f37
7aa5bf1
c402a4a
 
 
23e9146
 
 
7aa5bf1
 
c402a4a
 
 
7aa5bf1
 
 
 
c402a4a
 
7aa5bf1
 
 
 
c402a4a
 
23e9146
 
 
7aa5bf1
a4e1301
c402a4a
 
7aa5bf1
 
 
 
c402a4a
 
7aa5bf1
 
 
 
aaaadf1
c402a4a
23e9146
 
 
7aa5bf1
c402a4a
 
 
7aa5bf1
 
 
 
c402a4a
 
7aa5bf1
 
 
 
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
from liqfit.pipeline import ZeroShotClassificationPipeline
from liqfit.models import T5ForZeroShotClassification
from transformers import T5Tokenizer
import streamlit as st
import time

model = T5ForZeroShotClassification.from_pretrained('knowledgator/comprehend_it-multilingual-t5-base')
tokenizer = T5Tokenizer.from_pretrained('knowledgator/comprehend_it-multilingual-t5-base')
classifier = ZeroShotClassificationPipeline(model=model, tokenizer=tokenizer,ypothesis_template = '{}', encoder_decoder = True)
st.markdown("<h2 style='text-align: center; color: black;'>NLP Project </h2>", unsafe_allow_html=True)
st.markdown("<p style='text-align: center; color: black;'>Hafizh Zaki Prasetyo Adi|hafizhzaki6661@gmail.com|https://www.linkedin.com/in/hafizhzpa/ </p>", unsafe_allow_html=True)
part=st.sidebar.radio("project",["sentimen", "emosi", "label khusus"],captions = ["menentukan label sentimen", "menentukan label emosi", "klasifikasi berdasarkan label yang ditentukan"])
if part=='label khusus':
    start=time.time()
    col1, col2 = st.columns(2)
    text = col1.text_area('text', 'Saya sudah menggunakan produk ini selama sebulan dan saya sangat puas dengan hasilnya')
    multiclass = col1.checkbox('Izinkan multi label')
    label = col1.text_area('label', 'positive,negative,neutral')
    if col1.button('run'):
        candidate_labels = label.split(',')
        result=classifier(text, candidate_labels, multi_label=multiclass)
        if not multiclass:
            col2.markdown("result")
            col2.markdown(f"<h4 style='text-align: center; color: black;'>{result['labels'][0]} </h4>", unsafe_allow_html=True)
            col2.progress(round(result['scores'][0],2))
            col2.text(str(round(result['scores'][0]*100,2))+"%")
        else:
            bool_score=[score>0.5 for score in result['scores']]
            col2.markdown("result")
            col2.markdown(f"<h4 style='text-align: center; color: black;'>{','.join([label for i,label in enumerate(result['labels']) if bool_score[i]])} </h4>", unsafe_allow_html=True)
            col2.progress(round(result['scores'][0],2))
            col2.text(str(round(result['scores'][0]*100,2))+"%")
if part=='sentimen':
    start=time.time()
    col1, col2 = st.columns(2)
    text = col1.text_area('text', 'Saya sudah menggunakan produk ini selama sebulan dan saya sangat puas dengan hasilnya')
    multiclass = col1.checkbox('Izinkan multi label')
    if col1.button('run'):
        candidate_labels = ['positive','negative','neutral']
        result=classifier(text, candidate_labels, multi_label=multiclass)
        if not multiclass:
            col2.markdown("result")
            col2.markdown(f"<h4 style='text-align: center; color: black;'>{result['labels'][0]} </h4>", unsafe_allow_html=True)
            col2.progress(round(result['scores'][0],2))
            col2.text(str(round(result['scores'][0]*100,2))+"%")
        else:
            bool_score=[score>0.5 for score in result['scores']]
            col2.markdown("result")
            col2.markdown(f"<h4 style='text-align: center; color: black;'>{','.join([label for i,label in enumerate(result['labels']) if bool_score[i]])} </h4>", unsafe_allow_html=True)
            col2.progress(round(result['scores'][0],2))
            col2.text(str(round(result['scores'][0]*100,2))+"%")
if part=='emosi':
    start=time.time()
    col1, col2 = st.columns(2)
    text = col1.text_area('text', 'Saya sudah menggunakan produk ini selama sebulan dan saya sangat puas dengan hasilnya')
    multiclass = col1.checkbox('Izinkan multi label')
    if col1.button('run'):
        candidate_labels = ["bahagia", "sedih", "takut", "marah", "antisipasi", "terkejut", "jijik","percaya"]
        result=classifier(text, candidate_labels, multi_label=multiclass)
        if not multiclass:
            col2.markdown("result")
            col2.markdown(f"<h4 style='text-align: center; color: black;'>{result['labels'][0]} </h4>", unsafe_allow_html=True)
            col2.progress(round(result['scores'][0],2))
            col2.text(str(round(result['scores'][0]*100,2))+"%")
        else:
            bool_score=[score>0.5 for score in result['scores']]
            col2.markdown("result")
            col2.markdown(f"<h4 style='text-align: center; color: black;'>{','.join([label for i,label in enumerate(result['labels']) if bool_score[i]])} </h4>", unsafe_allow_html=True)
            col2.progress(round(result['scores'][0],2))
            col2.text(str(round(result['scores'][0]*100,2))+"%")