Spaces:
Runtime error
Runtime error
AleksBlacky
commited on
Commit
Β·
6afc0d2
1
Parent(s):
dabf7ab
added second output and model to repo
Browse files- app.py +19 -30
- models/scibert/pytorch_model.bin +3 -0
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,9 +1,10 @@
|
|
1 |
import streamlit as st
|
2 |
-
import transformers
|
3 |
import pickle
|
4 |
-
|
5 |
from pandas import DataFrame
|
|
|
6 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
|
7 |
|
8 |
st.markdown("# Hello, friend!")
|
9 |
st.markdown(" This magic application going to help you with understanding of science paper topic! Cool? Yeah! ")
|
@@ -18,32 +19,7 @@ with open('./models/scibert/decode_dict.pkl', 'rb') as f:
|
|
18 |
with st.form(key="my_form"):
|
19 |
st.markdown("### π Do you want a little magic? ")
|
20 |
st.markdown(" Write your article title and abstract to textboxes bellow and I'll gues topic of your paper! ")
|
21 |
-
# ce, c1, ce, c2, c3 = st.columns([0.07, 1, 0.07, 5, 0.07])
|
22 |
ce, c2, c3 = st.columns([0.07, 5, 0.07])
|
23 |
-
# with c1:
|
24 |
-
# ModelType = st.radio(
|
25 |
-
# "Choose your model",
|
26 |
-
# ["DistilBERT (Default)", "Flair"],
|
27 |
-
# help="At present, you can choose between 2 models (Flair or DistilBERT) to embed your text. More to come!",
|
28 |
-
# )
|
29 |
-
#
|
30 |
-
# if ModelType == "Default (DistilBERT)":
|
31 |
-
# # kw_model = KeyBERT(model=roberta)
|
32 |
-
#
|
33 |
-
# @st.cache(allow_output_mutation=True)
|
34 |
-
# def load_model():
|
35 |
-
# return KeyBERT(model=roberta)
|
36 |
-
#
|
37 |
-
#
|
38 |
-
# kw_model = load_model()
|
39 |
-
#
|
40 |
-
# else:
|
41 |
-
# @st.cache(allow_output_mutation=True)
|
42 |
-
# def load_model():
|
43 |
-
# return KeyBERT("distilbert-base-nli-mean-tokens")
|
44 |
-
#
|
45 |
-
#
|
46 |
-
# kw_model = load_model()
|
47 |
|
48 |
with c2:
|
49 |
doc_title = st.text_area(
|
@@ -113,9 +89,12 @@ model_local = "models/scibert/"
|
|
113 |
|
114 |
title = doc_title
|
115 |
abstract = doc_abstract
|
116 |
-
|
|
|
|
|
|
|
117 |
|
118 |
-
predicts = make_predict(
|
119 |
|
120 |
st.markdown("## π Yor article probably about: ")
|
121 |
st.header("")
|
@@ -125,9 +104,15 @@ df = (
|
|
125 |
.sort_values(by="Prob", ascending=False)
|
126 |
.reset_index(drop=True)
|
127 |
)
|
128 |
-
|
129 |
df.index += 1
|
130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
# Add styling
|
132 |
cmGreen = sns.light_palette("green", as_cmap=True)
|
133 |
cmRed = sns.light_palette("red", as_cmap=True)
|
@@ -145,6 +130,10 @@ format_dictionary = {
|
|
145 |
}
|
146 |
|
147 |
df = df.format(format_dictionary)
|
|
|
148 |
|
149 |
with c2:
|
|
|
150 |
st.table(df)
|
|
|
|
|
|
1 |
import streamlit as st
|
|
|
2 |
import pickle
|
3 |
+
|
4 |
from pandas import DataFrame
|
5 |
+
import transformers
|
6 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
7 |
+
import seaborn as sns
|
8 |
|
9 |
st.markdown("# Hello, friend!")
|
10 |
st.markdown(" This magic application going to help you with understanding of science paper topic! Cool? Yeah! ")
|
|
|
19 |
with st.form(key="my_form"):
|
20 |
st.markdown("### π Do you want a little magic? ")
|
21 |
st.markdown(" Write your article title and abstract to textboxes bellow and I'll gues topic of your paper! ")
|
|
|
22 |
ce, c2, c3 = st.columns([0.07, 5, 0.07])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
with c2:
|
25 |
doc_title = st.text_area(
|
|
|
89 |
|
90 |
title = doc_title
|
91 |
abstract = doc_abstract
|
92 |
+
try:
|
93 |
+
tokens = tokenizer_(title + abstract, return_tensors="pt")
|
94 |
+
except ValueError:
|
95 |
+
st.error("Word parsing into tokens went wrong! Is input valid? If yes, pls contact author [email protected]")
|
96 |
|
97 |
+
predicts = make_predict(tokens, decode_dict)
|
98 |
|
99 |
st.markdown("## π Yor article probably about: ")
|
100 |
st.header("")
|
|
|
104 |
.sort_values(by="Prob", ascending=False)
|
105 |
.reset_index(drop=True)
|
106 |
)
|
|
|
107 |
df.index += 1
|
108 |
|
109 |
+
df2 = (
|
110 |
+
DataFrame(predicts.items(), columns=["Topic", "Prob"])
|
111 |
+
.sort_values(by="Prob", ascending=False)
|
112 |
+
.reset_index(drop=True)
|
113 |
+
)
|
114 |
+
# df2.index += 1
|
115 |
+
|
116 |
# Add styling
|
117 |
cmGreen = sns.light_palette("green", as_cmap=True)
|
118 |
cmRed = sns.light_palette("red", as_cmap=True)
|
|
|
130 |
}
|
131 |
|
132 |
df = df.format(format_dictionary)
|
133 |
+
df2 = df.format(format_dictionary)
|
134 |
|
135 |
with c2:
|
136 |
+
st.markdown("#### We suppose your research about: ")
|
137 |
st.table(df)
|
138 |
+
st.markdown("##### More detailed, it's about topic: ")
|
139 |
+
st.table(df2)
|
models/scibert/pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a3c198018ce26ff40d59d298bf6aa40515fb952ee2a522591b82565c44077b48
|
3 |
+
size 440146413
|
requirements.txt
CHANGED
@@ -1,2 +1,3 @@
|
|
1 |
transformers
|
2 |
-
torch
|
|
|
|
1 |
transformers
|
2 |
+
torch
|
3 |
+
seaborn
|