Spaces:
Build error
Build error
Change output to json
Browse filesclf_text()-output to dict instead of text & gradio_interface outputs to json from text
app.py
CHANGED
|
@@ -21,8 +21,9 @@ def clf_text(txt: str):
|
|
| 21 |
res = classifier(txt, categories, multi_label=True)
|
| 22 |
items = sorted(zip(res["labels"], res["scores"]), key=lambda tpl: tpl[1])
|
| 23 |
# d = dict(zip(res["labels"], res["scores"]))
|
| 24 |
-
output = [f"{lbl}:\t{score}" for lbl, score in items]
|
| 25 |
-
return "\n".join(output)
|
|
|
|
| 26 |
# classifier(sequence_to_classify, candidate_labels)
|
| 27 |
#{'labels': ['travel', 'dancing', 'cooking'],
|
| 28 |
# 'scores': [0.9938651323318481, 0.0032737774308770895, 0.002861034357920289],
|
|
@@ -36,6 +37,6 @@ gradio_interface = gradio.Interface(
|
|
| 36 |
# fn = my_inference_function,
|
| 37 |
fn = clf_text,
|
| 38 |
inputs = "text",
|
| 39 |
-
outputs = "
|
| 40 |
)
|
| 41 |
gradio_interface.launch()
|
|
|
|
| 21 |
res = classifier(txt, categories, multi_label=True)
|
| 22 |
items = sorted(zip(res["labels"], res["scores"]), key=lambda tpl: tpl[1])
|
| 23 |
# d = dict(zip(res["labels"], res["scores"]))
|
| 24 |
+
# output = [f"{lbl}:\t{score}" for lbl, score in items]
|
| 25 |
+
# return "\n".join(output)
|
| 26 |
+
return dict(items)
|
| 27 |
# classifier(sequence_to_classify, candidate_labels)
|
| 28 |
#{'labels': ['travel', 'dancing', 'cooking'],
|
| 29 |
# 'scores': [0.9938651323318481, 0.0032737774308770895, 0.002861034357920289],
|
|
|
|
| 37 |
# fn = my_inference_function,
|
| 38 |
fn = clf_text,
|
| 39 |
inputs = "text",
|
| 40 |
+
outputs = "json"
|
| 41 |
)
|
| 42 |
gradio_interface.launch()
|