aopp
Browse files
app.py
CHANGED
@@ -9,32 +9,25 @@ from blurr.text.modeling.all import *
|
|
9 |
model_path = "origin-classifier-stage-2.pkl"
|
10 |
dls_path = "dls_origin-classifier_v1.pkl"
|
11 |
|
12 |
-
# Load the learner
|
13 |
learner_inf = load_learner(model_path)
|
14 |
|
15 |
-
# Load the DataLoaders
|
16 |
dls = torch.load(dls_path)
|
17 |
|
18 |
-
# Create a mapping from class labels to indices
|
19 |
class_label_mapping = {label: idx for idx, label in enumerate(learner_inf.dls.vocab)}
|
20 |
|
21 |
-
# Define a function to make predictions
|
22 |
def predict_text(text):
|
23 |
-
prediction = learner_inf.blurr_predict(text)
|
24 |
-
predicted_probs = prediction['scores']
|
25 |
-
predicted_labels = prediction['class_labels']
|
26 |
result = {label: f"{prob*100:.2f}%" for label, prob in zip(predicted_labels, predicted_probs)}
|
27 |
return result
|
28 |
|
29 |
-
# Create a Gradio interface
|
30 |
iface = gr.Interface(
|
31 |
fn=predict_text,
|
32 |
-
inputs=
|
33 |
-
outputs=
|
34 |
title="Food Origin Classification App",
|
35 |
description="Enter a Recipe, and it will predict the class label.",
|
36 |
)
|
37 |
|
38 |
-
|
39 |
-
iface.launch()
|
40 |
-
|
|
|
9 |
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 |
dls = torch.load(dls_path)
|
15 |
|
|
|
16 |
class_label_mapping = {label: idx for idx, label in enumerate(learner_inf.dls.vocab)}
|
17 |
|
|
|
18 |
def predict_text(text):
|
19 |
+
prediction = learner_inf.blurr_predict(text)
|
20 |
+
predicted_probs = prediction[0]['scores']
|
21 |
+
predicted_labels = prediction[0]['class_labels']
|
22 |
result = {label: f"{prob*100:.2f}%" for label, prob in zip(predicted_labels, predicted_probs)}
|
23 |
return result
|
24 |
|
|
|
25 |
iface = gr.Interface(
|
26 |
fn=predict_text,
|
27 |
+
inputs=gr.inputs.Textbox(lines=2, placeholder='Enter Recipe Here...'),
|
28 |
+
outputs=gr.outputs.Label(num_top_classes=3),
|
29 |
title="Food Origin Classification App",
|
30 |
description="Enter a Recipe, and it will predict the class label.",
|
31 |
)
|
32 |
|
33 |
+
iface.launch()
|
|
|
|