#%pip install setfit[openvino] ipywidgets widgetsnbextensionfrom time import perf_counter
from setfit import SetFitModel

NUM_ITERS=100

model_id = "lewtun/my-awesome-setfit-model"
model = SetFitModel.from_pretrained("lewtun/my-awesome-setfit-model")

# Run inference
input_text = ["i loved the spiderman movie!", "pineapple on pizza is the worst 🤮"]

start = perf_counter()
for i in range(NUM_ITERS):
    preds = model(input_text)
end = perf_counter()

preds, f"{end-start:.2f} seconds"from setfit import SetFitModel
from setfit.exporters.openvino import export_to_openvino

output_path = "model.xml"
export_to_openvino(model, output_path)from transformers import AutoTokenizer
import openvino.runtime as ov

tokenizer = AutoTokenizer.from_pretrained(model_id)
inputs = tokenizer(
    input_text,
    padding=True,
    truncation=True,
    return_attention_mask=True,
    return_token_type_ids=True,
    return_tensors="np",
)

inputs_dict = dict(inputs)

core = ov.Core()
ov_model = core.read_model(output_path)
compiled_model = core.compile_model(ov_model, "CPU")
output = compiled_model.output(0)

start = perf_counter()
for i in range(NUM_ITERS):
    ov_preds = compiled_model(inputs_dict)[output]
end = perf_counter()

ov_preds, f"{end-start:.2f} seconds"
