Spaces:
Runtime error
Runtime error
Initial commit
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import streamlit as st
|
3 |
+
import pandas as pd
|
4 |
+
|
5 |
+
|
6 |
+
|
7 |
+
def filter_candidates(candidates):
|
8 |
+
df = pd.DataFrame(columns=["Candidates", "Probability"])
|
9 |
+
cand_list = []
|
10 |
+
score_list = []
|
11 |
+
for candidate in candidates:
|
12 |
+
if candidate["token_str"][:2] != "##":
|
13 |
+
cand = candidate["sequence"]
|
14 |
+
score = candidate["score"]
|
15 |
+
cand_list.append(cand)
|
16 |
+
score_list.append('{0:.5f}'.format(score))
|
17 |
+
if len(score_list) == 5:
|
18 |
+
break
|
19 |
+
df["Candidates"] = cand_list
|
20 |
+
df["Probability"] = score_list
|
21 |
+
|
22 |
+
df.index = [1,2,3,4,5]
|
23 |
+
|
24 |
+
return df
|
25 |
+
|
26 |
+
nlp = pipeline("fill-mask", model="flax-community/alberti-bert-base-multilingual-cased")
|
27 |
+
|
28 |
+
user_input = st.text_input("Mask token: [MASK]", "Me encanta escribir [MASK].")
|
29 |
+
|
30 |
+
if st.button("Guess!"):
|
31 |
+
results = filter_candidates(nlp(user_input, top_k=20))
|
32 |
+
st.table(results)
|
33 |
+
|