akdeniz27 commited on
Commit
a21078d
1 Parent(s): c1ca04c

Initial Commit

Browse files
Files changed (2) hide show
  1. app.py +77 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Turkish Zero-Shot Text Classification with XLM-RoBERTa
2
+
3
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
4
+ import plotly.graph_objects as go
5
+ import streamlit as st
6
+
7
+ text_1 = """Bilim insanları Botsvana’da Covid-19’un şu ana kadar en çok mutasyona uğramış varyantını tespit etti. \
8
+ Resmi olarak B.1.1.529 koduyla bilinen bu varyantı ise “Nu varyantı” adı verildi. Uzmanlar bu varyant içerisinde \
9
+ tam 32 farklı mutasyon tespit edildiğini açıklarken, bu virüsün corona virüsü aşılarına karşı daha dirençli olabileceğini duyurdu."""
10
+
11
+ text_2 = """Şampiyonlar Ligi’nde 5. hafta oynanan karşılaşmaların ardından sona erdi. Real Madrid, Inter ve Sporting \
12
+ oynadıkları mücadeleler sonrasında Son 16 turuna yükselmeyi başardı. Gecenin dev mücadelesinde ise Manchester City, \
13
+ PSG’yi yenerek liderliği garantiledi."""
14
+
15
+ @st.cache(allow_output_mutation=True)
16
+ def list2text(label_list):
17
+ labels = ""
18
+ for label in label_list:
19
+ labels = labels + label + ","
20
+ labels = labels[:-1]
21
+ return labels
22
+
23
+ label_list_1 = ["dünya", "ekonomi", "kültür", "sağlık", "siyaset", "spor", "teknoloji"]
24
+ label_list_2 = ["positive", "negative", "neutral"]
25
+
26
+ st.title("Turkish Zero-Shot Text Classification \
27
+ with Multilingual XLM-RoBERTa Models")
28
+
29
+ model_list = ['vicgalle/xlm-roberta-large-xnli-anli',
30
+ 'joeddav/xlm-roberta-large-xnli']
31
+
32
+ st.sidebar.header("Select Model")
33
+ model_checkpoint = st.sidebar.radio("", model_list)
34
+
35
+ st.sidebar.write("For details of models:")
36
+ st.sidebar.write("https://huggingface.co/vicgalle")
37
+ st.sidebar.write("https://huggingface.co/joeddav")
38
+
39
+ st.subheader("Select Text and Label List")
40
+ st.text_area("Text #1", text_1, height=128)
41
+ st.text_area("Text #2", text_2, height=128)
42
+ st.write(f"Label List #1: {list2text(label_list_1)}")
43
+ st.write(f"Label List #2: {list2text(label_list_2)}")
44
+
45
+ text = st.radio("Select Text", ("Text #1", "Text #2", "New Text"))
46
+ labels = st.radio("Select Label List", ("Label List #1", "Label List #2", "New Label List"))
47
+
48
+ if text == "Text #1": selected_text = text_1
49
+ elif text == "Text #2": selected_text = text_2
50
+ elif text == "New Text":
51
+ selected_text = st.text_area("New Text", value="", height=128)
52
+
53
+ if labels == "Label List #1": selected_labels = label_list_1
54
+ elif labels == "Label List #2": selected_labels = label_list_2
55
+ elif labels == "New Label List":
56
+ selected_labels = st.text_area("New Label List (Pls Input as comma-separated)", value="", height=16).split(",")
57
+
58
+ @st.cache(allow_output_mutation=True)
59
+ def setModel(model_checkpoint):
60
+ model = AutoModelForSequenceClassification.from_pretrained(model_checkpoint)
61
+ tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
62
+ return pipeline("zero-shot-classification", model=model, tokenizer=tokenizer)
63
+
64
+ Run_Button = st.button("Run", key=None)
65
+ if Run_Button == True:
66
+
67
+ zstc_pipeline = setModel(model_checkpoint)
68
+ output = zstc_pipeline(sequences=selected_text, candidate_labels=selected_labels)
69
+ output_labels = output["labels"]
70
+ output_scores = output["scores"]
71
+
72
+ st.header("Result")
73
+ import plotly.graph_objects as go
74
+ fig = go.Figure([go.Bar(x=output_labels, y=output_scores)])
75
+ st.plotly_chart(fig, use_container_width=False, sharing="streamlit")
76
+
77
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ transformers
3
+ plotly