File size: 1,056 Bytes
1361040 90ff4ab 1361040 a058b69 1361040 a058b69 1361040 3b5af6e 6e02710 1361040 3b5af6e 82dd379 1361040 3b5af6e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import gradio as gr
from transformers import AutoTokenizer
import torch
from fastai.text.all import *
from blurr.text.data.all import *
from blurr.text.modeling.all import *
# Define the path to your model and dataloaders
model_path = "origin-classifier-stage-2.pkl"
dls_path = "dls_origin-classifier_v1.pkl"
learner_inf = load_learner(model_path)
dls = torch.load(dls_path)
class_label_mapping = {label: idx for idx, label in enumerate(learner_inf.dls.vocab)}
def predict_text(text):
prediction = learner_inf.blurr_predict(text)
predicted_probs = prediction[0]['scores']
predicted_labels = prediction[0]['class_labels']
result = {label: f"{prob*100:.2f}%" for label, prob in zip(predicted_labels, predicted_probs)}
return result
iface = gr.Interface(
fn=predict_text,
inputs=gr.inputs.Textbox(lines=2, placeholder='Enter Recipe Here...'),
outputs=gr.outputs.Label(num_top_classes=3),
title="Food Origin Classification App",
description="Enter a Recipe, and it will predict the class label.",
)
iface.launch() |