sanjid commited on
Commit
4829bea
·
1 Parent(s): 72ef52b
Files changed (1) hide show
  1. app.py +6 -6
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
- predicted_probs = prediction[0]['scores']
24
- predicted_labels = prediction[0]['class_labels']
25
- result = {label: f"{prob*100:.2f}%" for label, prob in zip(predicted_labels, predicted_probs)}
26
- return result
27
 
28
  iface = gr.Interface(
29
  fn=predict_text,
30
  inputs="text",
31
- outputs="text",
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
  )