aopp
Browse files
app.py
CHANGED
|
@@ -19,16 +19,16 @@ class_label_mapping = {label: idx for idx, label in enumerate(learner_inf.dls.vo
|
|
| 19 |
|
| 20 |
|
| 21 |
def predict_text(text):
|
| 22 |
-
prediction = learner_inf.blurr_predict(text)
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
return
|
| 27 |
|
| 28 |
iface = gr.Interface(
|
| 29 |
fn=predict_text,
|
| 30 |
inputs="text",
|
| 31 |
-
outputs=
|
| 32 |
title="Food Origin Classification App",
|
| 33 |
description="Enter a Recipe, and it will predict the class label.",
|
| 34 |
)
|
|
|
|
| 19 |
|
| 20 |
|
| 21 |
def predict_text(text):
|
| 22 |
+
prediction = learner_inf.blurr_predict(text)[0]
|
| 23 |
+
predicted_class_index = prediction['class_index']
|
| 24 |
+
predicted_class_label = list(class_label_mapping.keys())[list(class_label_mapping.values()).index(predicted_class_index)]
|
| 25 |
+
predicted_class_probability = prediction['probs'][predicted_class_index]
|
| 26 |
+
return {"label": predicted_class_label, "probability": f"{predicted_class_probability * 100:.2f}%"}
|
| 27 |
|
| 28 |
iface = gr.Interface(
|
| 29 |
fn=predict_text,
|
| 30 |
inputs="text",
|
| 31 |
+
outputs=gr.outputs.Label(num_top_classes=5),
|
| 32 |
title="Food Origin Classification App",
|
| 33 |
description="Enter a Recipe, and it will predict the class label.",
|
| 34 |
)
|