Spaces:
Sleeping
Sleeping
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))+"%") |