app update
Browse files
app.py
CHANGED
|
@@ -21,17 +21,18 @@ class_label_mapping = {label: idx for idx, label in enumerate(learner_inf.dls.vo
|
|
| 21 |
# Define a function to make predictions
|
| 22 |
def predict_text(text):
|
| 23 |
prediction = learner_inf.blurr_predict(text)[0]
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
| 27 |
|
| 28 |
# Create a Gradio interface
|
| 29 |
iface = gr.Interface(
|
| 30 |
fn=predict_text,
|
| 31 |
inputs="text",
|
| 32 |
-
outputs=
|
| 33 |
-
title="
|
| 34 |
-
description="Enter a
|
| 35 |
)
|
| 36 |
|
| 37 |
# Start the Gradio app
|
|
|
|
| 21 |
# Define a function to make predictions
|
| 22 |
def predict_text(text):
|
| 23 |
prediction = learner_inf.blurr_predict(text)[0]
|
| 24 |
+
predicted_probs = prediction['probs']
|
| 25 |
+
top_5_indices = predicted_probs.argsort(descending=True)[:5]
|
| 26 |
+
top_5_labels = [list(class_label_mapping.keys())[list(class_label_mapping.values()).index(idx)] for idx in top_5_indices]
|
| 27 |
+
return top_5_labels
|
| 28 |
|
| 29 |
# Create a Gradio interface
|
| 30 |
iface = gr.Interface(
|
| 31 |
fn=predict_text,
|
| 32 |
inputs="text",
|
| 33 |
+
outputs=gr.outputs.Label(num_top_classes=5),
|
| 34 |
+
title="Food Origin Classification App",
|
| 35 |
+
description="Enter a Recipe, and it will predict the class label.",
|
| 36 |
)
|
| 37 |
|
| 38 |
# Start the Gradio app
|