Lord-Raven
commited on
Commit
·
2244b0c
1
Parent(s):
64af10f
Swapping to ONNX.
Browse files- app.py +15 -2
- requirements.txt +3 -1
app.py
CHANGED
@@ -1,8 +1,21 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
from transformers import pipeline
|
|
|
4 |
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
def predict(text):
|
8 |
result = classifier(text)
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
from transformers import AutoTokenizer, pipeline
|
4 |
+
from optimum.onnxruntime import ORTModelForSequenceClassification
|
5 |
|
6 |
+
model_id = "SamLowe/roberta-base-go_emotions-onnx"
|
7 |
+
file_name = "onnx/model_quantized.onnx"
|
8 |
+
|
9 |
+
model = ORTModelForSequenceClassification.from_pretrained(model_id, file_name=file_name)
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
11 |
+
|
12 |
+
classifier = pipeline(
|
13 |
+
task="text-classification",
|
14 |
+
model=model,
|
15 |
+
tokenizer=tokenizer,
|
16 |
+
top_k=None,
|
17 |
+
function_to_apply="sigmoid", # optional as is the default for the task
|
18 |
+
)
|
19 |
|
20 |
def predict(text):
|
21 |
result = classifier(text)
|
requirements.txt
CHANGED
@@ -1,3 +1,5 @@
|
|
1 |
torch==2.4.0
|
2 |
huggingface_hub==0.26.0
|
3 |
-
transformers==4.36
|
|
|
|
|
|
1 |
torch==2.4.0
|
2 |
huggingface_hub==0.26.0
|
3 |
+
transformers==4.36
|
4 |
+
onnxruntime==1.18.1
|
5 |
+
optimum==1.21.3
|