AraJARIR / app.py
Hamda's picture
Update app.py
c871b03
raw
history blame
1.26 kB
import streamlit as st
import transformers
from transformers import pipeline
from transformers import AutoTokenizer, AutoModelForMaskedLM
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
tokenizer = AutoTokenizer.from_pretrained("moussaKam/AraBART", padding= True, truncation=True, max_length=128)
model = AutoModelForMaskedLM.from_pretrained("moussaKam/AraBART")
#@st.cache
def next_word(text, pipe):
res_dict= {
'Word':[],
'Score':[],
}
res=pipe(text)
for e in res:
res_dict['Word'].append(e['token_str'])
res_dict['Score'].append(e['score'])
return res_dict
st.title("Predict Next Word")
st.write("Use our model to expand your query based on the DB content")
default_value = "التاريخ هو تحليل و"
# sent is the the variable holding the user's input
sent = st.text_area("Text", default_value, height = 30)
sent += ' <mask>'
pipe = pipeline("fill-mask", tokenizer = tokenizer, model = model)
dict_next_words = next_word(sent, pipe)
df = pd.DataFrame.from_dict(dict_next_words)
df.reset_index(drop=True, inplace=True)
#design the graph theme
sns.set_theme(style="whitegrid")
sns.set_color_codes("pastel")
fig = sns.barplot(data=df, orient = 'h')
st.pyplot(fig)
#st.table(df)