sanjid commited on
Commit
81c4f19
·
1 Parent(s): 903663a
app.py CHANGED
@@ -1,32 +1,29 @@
1
  import gradio as gr
 
2
  from transformers import AutoTokenizer
3
- import torch
4
- from fastai.text.all import *
5
- from blurr.text.data.all import *
6
- from blurr.text.modeling.all import *
7
-
8
- # Define the path to your model and dataloaders
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
- 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 {predicted_class_label: float(predicted_class_probability)}
23
-
24
- iface = gr.Interface(
25
- fn=predict_text,
26
- inputs="text",
27
- outputs=gr.outputs.JSON(label="Predicted Class and Probability"),
28
- title="Food Origin Classification App",
29
- description="Enter a Recipe, and it will predict the class label.",
30
- )
31
-
32
- iface.launch()
 
1
  import gradio as gr
2
+ import onnxruntime as rt
3
  from transformers import AutoTokenizer
4
+ import torch, json
5
+
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained("distilroberta-base")
8
+
9
+ with open("label_types_encoded.json", "r") as fp:
10
+ encode_genre_types = json.load(fp)
11
+
12
+ genres = list(encode_genre_types.keys())
13
+
14
+ inf_session = rt.InferenceSession('food-origin-classifier-quantized.onnx')
15
+ input_name = inf_session.get_inputs()[0].name
16
+ output_name = inf_session.get_outputs()[0].name
17
+
18
+
19
+ def classify_food_Ingredient(article):
20
+ input_ids = tokenizer(article)['input_ids'][:512]
21
+ logits = inf_session.run([output_name], {input_name: [input_ids]})[0]
22
+ logits = torch.FloatTensor(logits)
23
+ probs = torch.sigmoid(logits)[0]
24
+ return dict(zip(genres, map(float, probs)))
25
+
26
+
27
+ label = gr.outputs.Label(num_top_classes=6)
28
+ iface = gr.Interface(fn=classify_food_Ingredient, inputs="text", outputs=label)
29
+ iface.launch(inline=False)
 
 
 
 
dls_origin-classifier_v1.pkl → food-origin-classifier-quantized.onnx RENAMED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:9300bfb9eaab679fd1147fac44b9dfce671f700cd2e0c61b1ebfd4c1bb60e2df
3
- size 345308264
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6ec5b4d3d27494c02cf26a60f413912cdcc773c3f688a4c07e44c8e141a4674a
3
+ size 83887251
label_types_encoded.json CHANGED
@@ -1 +1 @@
1
- {"Amish and Mennonite": 0, "Argentinian": 1, "Australian and New Zealander": 2, "Austrian": 3, "Bangladeshi": 4, "Belgian": 5, "Brazilian": 6, "Cajun and Creole": 7, "Canadian": 8, "Chilean": 9, "Chinese": 10, "Colombian": 11, "Cuban": 12, "Danish": 13, "Dutch": 14, "Filipino": 15, "Finnish": 16, "French": 17, "German": 18, "Greek": 19, "Indian": 20, "Indonesian": 21, "Israeli": 22, "Italian": 23, "Jamaican": 24, "Japanese": 25, "Jewish": 26, "Korean": 27, "Lebanese": 28, "Malaysian": 29, "Norwegian": 30, "Pakistani": 31, "Persian": 32, "Peruvian": 33, "Polish": 34, "Portuguese": 35, "Puerto Rican": 36, "Russian": 37, "Scandinavian": 38, "Soul Food": 39, "South African": 40, "Southern Recipes": 41, "Spanish": 42, "Swedish": 43, "Swiss": 44, "Tex-Mex": 45, "Thai": 46, "Turkish": 47, "Vietnamese": 48, "Australian and New Zealander Recipes": 49, "Cajun and Creole Recipes": 50, "Canadian Recipes": 51, "Chinese Recipes": 52, "Filipino Recipes": 53, "French Recipes": 54, "German Recipes": 55, "Greek Recipes": 56, "Indian Recipes": 57, "Italian Recipes": 58, "Japanese Recipes": 59, "Jewish Recipes": 60, "Korean Recipes": 61, "Polish Recipes": 62, "Scandinavian Recipes": 63, "Spanish Recipes": 64, "Thai Recipes": 65, "Vietnamese Recipes": 66}
 
1
+ {"Southern_Recipes": 0, "Australian_and_New_Zealander": 1, "Midle_eastern": 2, "Vietnamese_Recipes": 3, "Cajun_and_Creole": 4, "Indian_Recipes": 5, "Peruvian": 6, "Swedish_Norway": 7, "Greek_Recipes": 8, "German_Recipes": 9, "South_asian": 10, "Brazilian": 11, "European": 12, "Amish_and_Mennonite": 13, "Russian": 14, "Canadian": 15, "Chinese_Recipes": 16, "Filipino_Recipes": 17, "Puerto_Rican": 18, "Spanish_Recipes": 19, "Cuban": 20, "South_African": 21, "Cajun_and_Creole_Recipes": 22, "Scandinavian_Recipes": 23, "French_Recipes": 24, "Thai_Recipes": 25, "Latin": 26, "Jewish_Recipes": 27, "Tex-Mex": 28, "Portuguese": 29, "Japanese_Recipes": 30, "Canadian_Recipes": 31, "Italian_Recipes": 32, "Korean_Recipes": 33, "Polish": 34, "Persian": 35}
origin-classifier-stage-2.pkl DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:dafbc1f7af6bfd3afad4030fc21ad5639192be90f6aa11479a56526723acd86b
3
- size 330579429
 
 
 
 
requirements.txt CHANGED
Binary files a/requirements.txt and b/requirements.txt differ