Spaces:
Running
Running
kovacsvi
commited on
Commit
·
90fa7ec
1
Parent(s):
47c412f
np array to dict
Browse files
interfaces/cap_minor_media.py
CHANGED
@@ -95,7 +95,11 @@ def predict(text, major_model_id, minor_model_id, tokenizer_id, HF_TOKEN=None):
|
|
95 |
top_major_id = major_index_to_id[top_major_index]
|
96 |
|
97 |
# Default: show major topic predictions
|
98 |
-
filtered_probs =
|
|
|
|
|
|
|
|
|
99 |
output_pred = {
|
100 |
f"[{major_index_to_id[k]}] {CAP_MEDIA_LABEL_NAMES[filtered_probs[k]]}": v
|
101 |
for k, v in sorted(filtered_probs.items(), key=lambda item: item[1], reverse=True)
|
@@ -135,7 +139,7 @@ def predict_cap(text, language, domain):
|
|
135 |
return predict(text, major_model_id, minor_model_id, tokenizer_id)
|
136 |
|
137 |
demo = gr.Interface(
|
138 |
-
title="CAP Media Topics Babel Demo",
|
139 |
fn=predict_cap,
|
140 |
inputs=[gr.Textbox(lines=6, label="Input"),
|
141 |
gr.Dropdown(languages, label="Language"),
|
|
|
95 |
top_major_id = major_index_to_id[top_major_index]
|
96 |
|
97 |
# Default: show major topic predictions
|
98 |
+
filtered_probs = {
|
99 |
+
i: float(major_probs_np[i])
|
100 |
+
for i in np.argsort(major_probs_np)[::-1]
|
101 |
+
}
|
102 |
+
filtered_probs = normalize_probs(filtered_probs)
|
103 |
output_pred = {
|
104 |
f"[{major_index_to_id[k]}] {CAP_MEDIA_LABEL_NAMES[filtered_probs[k]]}": v
|
105 |
for k, v in sorted(filtered_probs.items(), key=lambda item: item[1], reverse=True)
|
|
|
139 |
return predict(text, major_model_id, minor_model_id, tokenizer_id)
|
140 |
|
141 |
demo = gr.Interface(
|
142 |
+
title="CAP Media/Minor Topics Babel Demo",
|
143 |
fn=predict_cap,
|
144 |
inputs=[gr.Textbox(lines=6, label="Input"),
|
145 |
gr.Dropdown(languages, label="Language"),
|