Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -33,27 +33,44 @@ tokenizer = BertTokenizer.from_pretrained("RuudVelo/dutch_news_clf_bert_finetune
|
|
33 |
# Title
|
34 |
st.title("Dutch news article classification")
|
35 |
|
36 |
-
text = st.text_area('Please type/copy/paste text of the Dutch article')
|
37 |
|
38 |
-
if text:
|
39 |
-
encoding = tokenizer(text, return_tensors="pt")
|
40 |
-
outputs = model(**encoding)
|
41 |
-
predictions = outputs.logits.argmax(-1)
|
42 |
-
probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
43 |
|
44 |
-
fig = plt.figure()
|
45 |
-
ax = fig.add_axes([0,0,1,1])
|
46 |
-
labels_plot = ['Binnenland', 'Buitenland' ,'Cultuur & Media' ,'Economie' ,'Koningshuis',
|
47 |
-
'Opmerkelijk' ,'Politiek', 'Regionaal nieuws', 'Tech']
|
48 |
-
probs_plot = probabilities[0].cpu().detach().numpy()
|
49 |
|
50 |
-
ax.barh(labels_plot,probs_plot )
|
51 |
-
st.pyplot(fig)
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
|
|
|
|
|
|
|
|
|
|
57 |
#encoding = tokenizer(text, return_tensors="pt")
|
58 |
#import numpy as np
|
59 |
|
|
|
33 |
# Title
|
34 |
st.title("Dutch news article classification")
|
35 |
|
36 |
+
#text = st.text_area('Please type/copy/paste text of the Dutch article')
|
37 |
|
38 |
+
#if text:
|
39 |
+
# encoding = tokenizer(text, return_tensors="pt")
|
40 |
+
# outputs = model(**encoding)
|
41 |
+
# predictions = outputs.logits.argmax(-1)
|
42 |
+
# probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
43 |
|
44 |
+
## fig = plt.figure()
|
45 |
+
# ax = fig.add_axes([0,0,1,1])
|
46 |
+
# labels_plot = ['Binnenland', 'Buitenland' ,'Cultuur & Media' ,'Economie' ,'Koningshuis',
|
47 |
+
# 'Opmerkelijk' ,'Politiek', 'Regionaal nieuws', 'Tech']
|
48 |
+
# probs_plot = probabilities[0].cpu().detach().numpy()
|
49 |
|
50 |
+
# ax.barh(labels_plot,probs_plot )
|
51 |
+
# st.pyplot(fig)
|
52 |
+
|
53 |
+
|
54 |
+
input = st.text_input('Context')
|
55 |
+
|
56 |
+
if st.button('Submit'):
|
57 |
+
with st.spinner('Generating a response...'):
|
58 |
+
encoding = tokenizer(text, return_tensors="pt")
|
59 |
+
outputs = model(**encoding)
|
60 |
+
predictions = outputs.logits.argmax(-1)
|
61 |
+
probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
62 |
+
|
63 |
+
fig = plt.figure()
|
64 |
+
ax = fig.add_axes([0,0,1,1])
|
65 |
+
labels_plot = ['Binnenland', 'Buitenland' ,'Cultuur & Media' ,'Economie' ,'Koningshuis',
|
66 |
+
'Opmerkelijk' ,'Politiek', 'Regionaal nieuws', 'Tech']
|
67 |
+
probs_plot = probabilities[0].cpu().detach().numpy()
|
68 |
|
69 |
+
ax.barh(labels_plot,probs_plot )
|
70 |
+
st.pyplot(fig)
|
71 |
+
# output = genQuestion(option, input)
|
72 |
+
# print(output)
|
73 |
+
# st.write(output)
|
74 |
#encoding = tokenizer(text, return_tensors="pt")
|
75 |
#import numpy as np
|
76 |
|