Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from optimum.onnxruntime import ORTModelForSequenceClassification
|
| 3 |
+
from transformers import pipeline, AutoTokenizer
|
| 4 |
+
|
| 5 |
+
# Load tokenizer
|
| 6 |
+
tokenizer = AutoTokenizer.from_pretrained("iam-tsr/finetuned-distilbert-employ-feedback")
|
| 7 |
+
|
| 8 |
+
# Load Quantized ONNX model
|
| 9 |
+
onnx_filename = "model_qint8.onnx"
|
| 10 |
+
model = ORTModelForSequenceClassification.from_pretrained("iam-tsr/finetuned-distilbert-employ-feedback", file_name=onnx_filename)
|
| 11 |
+
|
| 12 |
+
def pred(model, tokenizer, text):
|
| 13 |
+
|
| 14 |
+
pipe = pipeline(task="text-classification", model=model, tokenizer=tokenizer, device="cpu")
|
| 15 |
+
return pipe(text)[0]['label']
|
| 16 |
+
|
| 17 |
+
demo = gr.Interface(
|
| 18 |
+
fn=lambda text: pred(model, tokenizer, text),
|
| 19 |
+
inputs=["text"],
|
| 20 |
+
outputs=["text"],
|
| 21 |
+
api_name="predict"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
demo.launch(share=True)
|