new api
Browse files- app.py +27 -30
- dls_origin-classifier_v1.pkl → food-origin-classifier-quantized.onnx +2 -2
- label_types_encoded.json +1 -1
- origin-classifier-stage-2.pkl +0 -3
- requirements.txt +0 -0
app.py
CHANGED
@@ -1,32 +1,29 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
from transformers import AutoTokenizer
|
3 |
-
import torch
|
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 |
-
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:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6ec5b4d3d27494c02cf26a60f413912cdcc773c3f688a4c07e44c8e141a4674a
|
3 |
+
size 83887251
|
label_types_encoded.json
CHANGED
@@ -1 +1 @@
|
|
1 |
-
{"
|
|
|
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
|
|