aopp
Browse files
app.py
CHANGED
@@ -10,28 +10,26 @@ model_path = "origin-classifier-stage-2.pkl"
|
|
10 |
dls_path = "dls_origin-classifier_v1.pkl"
|
11 |
|
12 |
learner_inf = load_learner(model_path)
|
13 |
-
|
14 |
-
|
15 |
dls = torch.load(dls_path)
|
16 |
|
17 |
-
|
18 |
class_label_mapping = {label: idx for idx, label in enumerate(learner_inf.dls.vocab)}
|
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
|
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 |
)
|
35 |
|
36 |
-
|
37 |
iface.launch()
|
|
|
10 |
dls_path = "dls_origin-classifier_v1.pkl"
|
11 |
|
12 |
learner_inf = load_learner(model_path)
|
|
|
|
|
13 |
dls = torch.load(dls_path)
|
14 |
|
|
|
15 |
class_label_mapping = {label: idx for idx, label in enumerate(learner_inf.dls.vocab)}
|
16 |
|
|
|
17 |
def predict_text(text):
|
18 |
prediction = learner_inf.blurr_predict(text)[0]
|
19 |
predicted_class_index = prediction['class_index']
|
20 |
predicted_class_label = list(class_label_mapping.keys())[list(class_label_mapping.values()).index(predicted_class_index)]
|
21 |
predicted_class_probability = prediction['probs'][predicted_class_index]
|
22 |
+
return {"Label": predicted_class_label, "Probability": predicted_class_probability}
|
23 |
|
24 |
iface = gr.Interface(
|
25 |
fn=predict_text,
|
26 |
inputs="text",
|
27 |
+
outputs=[
|
28 |
+
gr.outputs.Textbox(label="Label"),
|
29 |
+
gr.outputs.Label(num_top_classes=1, type="confidences", label="Probability")
|
30 |
+
],
|
31 |
title="Food Origin Classification App",
|
32 |
description="Enter a Recipe, and it will predict the class label.",
|
33 |
)
|
34 |
|
|
|
35 |
iface.launch()
|