Spaces:
Running
Running
hafizh zaki prasetyo adi
commited on
initial commit
Browse files- requirements.txt +3 -0
- streamlit_app.py +54 -0
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
liqfit==1.0.0
|
2 |
+
transformers==4.37.2
|
3 |
+
SentencePiece
|
streamlit_app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from liqfit.pipeline import ZeroShotClassificationPipeline
|
2 |
+
from liqfit.models import T5ForZeroShotClassification
|
3 |
+
from transformers import T5Tokenizer
|
4 |
+
import streamlit as st
|
5 |
+
import time
|
6 |
+
|
7 |
+
model = T5ForZeroShotClassification.from_pretrained('knowledgator/comprehend_it-multilingual-t5-base')
|
8 |
+
tokenizer = T5Tokenizer.from_pretrained('knowledgator/comprehend_it-multilingual-t5-base')
|
9 |
+
classifier = ZeroShotClassificationPipeline(model=model, tokenizer=tokenizer,ypothesis_template = '{}', encoder_decoder = True)
|
10 |
+
st.title('Natural Language Project')
|
11 |
+
st.markdown('Hafizh Zaki Prasetyo Adi|[email protected]|https://www.linkedin.com/in/hafizhzpa/')
|
12 |
+
part=st.sidebar.radio("project",["sentimen", "emosi", "label khusus"],captions = ["menentukan label sentimen", "menentukan label emosi", "klasifikasi berdasarkan label yang ditentukan"])
|
13 |
+
text = st.text_input('text', 'Saya sudah menggunakan produk ini selama sebulan dan saya sangat puas dengan hasilnya')
|
14 |
+
multiclass = st.checkbox('Izinkan multi label')
|
15 |
+
if part=='label khusus':
|
16 |
+
start=time.time()
|
17 |
+
label = st.text_input('label', 'positive,negative,neutral')
|
18 |
+
if st.button('run'):
|
19 |
+
candidate_labels = label.split(',')
|
20 |
+
result=classifier(text, candidate_labels, multi_label=multiclass)
|
21 |
+
if not multiclass:
|
22 |
+
st.text(f"label:{result['labels'][0]}")
|
23 |
+
st.text(f"skor:{result['scores'][0]}")
|
24 |
+
else:
|
25 |
+
bool_score=[score>0.5 for score in result['scores']]
|
26 |
+
st.text(f"label:{','.join([label for i,label in enumerate(result['labels']) if bool_score[i]])}")
|
27 |
+
st.text(f"skor:{','.join([skor for i,skor in enumerate(result['scores']) if bool_score[i]])}")
|
28 |
+
st.text(f"waktu:{time.time()-start}")
|
29 |
+
if part=='sentimen':
|
30 |
+
start=time.time()
|
31 |
+
if st.button('run'):
|
32 |
+
candidate_labels = ["positive','negative','neutral"]
|
33 |
+
result=classifier(text, candidate_labels, multi_label=multiclass)
|
34 |
+
if not multiclass:
|
35 |
+
st.text(f"label:{result['labels'][0]}")
|
36 |
+
st.text(f"skor:{result['scores'][0]}")
|
37 |
+
else:
|
38 |
+
bool_score=[score>0.5 for score in result['scores']]
|
39 |
+
st.text(f"label:{','.join([label for i,label in enumerate(result['labels']) if bool_score[i]])}")
|
40 |
+
st.text(f"skor:{','.join([skor for i,skor in enumerate(result['scores']) if bool_score[i]])}")
|
41 |
+
st.text(f"waktu:{time.time()-start}")
|
42 |
+
if part=='emotion':
|
43 |
+
start=time.time()
|
44 |
+
if st.button('run'):
|
45 |
+
candidate_labels = ["bahagia", "sedih", "takut", "marah", "antisipasi", "terkejut", "jijik","percaya"]
|
46 |
+
result=classifier(text, candidate_labels, multi_label=multiclass)
|
47 |
+
if not multiclass:
|
48 |
+
st.text(f"label:{result['labels'][0]}")
|
49 |
+
st.text(f"skor:{result['scores'][0]}")
|
50 |
+
else:
|
51 |
+
bool_score=[score>0.5 for score in result['scores']]
|
52 |
+
st.text(f"label:{','.join([label for i,label in enumerate(result['labels']) if bool_score[i]])}")
|
53 |
+
st.text(f"skor:{','.join([skor for i,skor in enumerate(result['scores']) if bool_score[i]])}")
|
54 |
+
st.text(f"waktu:{time.time()-start}")
|