Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
from transformers import AutoTokenizer, AutoModelForMaskedLM
|
4 |
+
|
5 |
+
tokenizer = AutoTokenizer.from_pretrained("moussaKam/AraBART", padding= True, truncation=True, max_length=128)
|
6 |
+
@st.cache
|
7 |
+
def load_model(model_name):
|
8 |
+
model = AutoModelForMaskedLM.from_pretrained(model_name)
|
9 |
+
return model
|
10 |
+
model = load_model("moussaKam/AraBART")
|
11 |
+
|
12 |
+
|
13 |
+
@st.cache
|
14 |
+
def next_word(text, pipe):
|
15 |
+
res_dict= {
|
16 |
+
'token_str':[],
|
17 |
+
'score':[],
|
18 |
+
}
|
19 |
+
res=pipe(text)
|
20 |
+
for e in res:
|
21 |
+
res_dict['token_str'].extend(e['token_str'])
|
22 |
+
res_dict['score'].extend(e['score'])
|
23 |
+
return res_dict
|
24 |
+
|
25 |
+
st.title("Predict Next Word")
|
26 |
+
st.write("Use our model to expand your query based on the DB content")
|
27 |
+
default_value = "التاريخ هو تحليل و"
|
28 |
+
# sent is the the variable holding the user's input
|
29 |
+
sent = st.text_area("Text", default_value, height = 60)
|
30 |
+
sent += ' <mask>'
|
31 |
+
|
32 |
+
pipe = pipeline("fill-mask", tokenizer = tokenizer, model = model, device=0)
|
33 |
+
dict_next_words = next_word(sent, pipe)
|
34 |
+
|
35 |
+
st.write(dict_next_words)
|