Update app.py
Browse files
app.py
CHANGED
|
@@ -54,14 +54,29 @@ def fill_masked(text: str, model_name: str, top_k: int):
|
|
| 54 |
results = fill_mask(text, top_k=top_k)
|
| 55 |
|
| 56 |
# Format results for display
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
# Build the Gradio interface with a slider for top-k
|
| 67 |
iface = gr.Interface(
|
|
|
|
| 54 |
results = fill_mask(text, top_k=top_k)
|
| 55 |
|
| 56 |
# Format results for display
|
| 57 |
+
res_dict = {}
|
| 58 |
+
if isinstance(results[0], list):
|
| 59 |
+
for mask_num, mas_results in enumerate(results):
|
| 60 |
+
formatted = []
|
| 61 |
+
for cand in mas_results:
|
| 62 |
+
formatted.append({
|
| 63 |
+
"sequence": cand["sequence"],
|
| 64 |
+
"score": round(cand["score"], 4),
|
| 65 |
+
"token": cand["token_str"]
|
| 66 |
+
})
|
| 67 |
+
res_dict[mask_num] = formatted
|
| 68 |
+
elif
|
| 69 |
+
formatted = []
|
| 70 |
+
for cand in mas_results:
|
| 71 |
+
formatted.append({
|
| 72 |
+
"sequence": cand["sequence"],
|
| 73 |
+
"score": round(cand["score"], 4),
|
| 74 |
+
"token": cand["token_str"]
|
| 75 |
+
})
|
| 76 |
+
res_dict[0] = formatted
|
| 77 |
+
else:
|
| 78 |
+
raise ValueError("The results need to be presented in a list or a list of lists")
|
| 79 |
+
return res_dict
|
| 80 |
|
| 81 |
# Build the Gradio interface with a slider for top-k
|
| 82 |
iface = gr.Interface(
|