UMCU commited on
Commit
0403ade
·
verified ·
1 Parent(s): 5ffd00d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -8
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
- formatted = []
58
- for res in results:
59
- formatted.append({
60
- "sequence": res["sequence"],
61
- "score": round(res["score"], 4),
62
- "token": res["token_str"]
63
- })
64
- return formatted
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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(