Spaces:
Sleeping
Sleeping
File size: 1,620 Bytes
6f0a968 ded5d23 6f0a968 8fd1827 6f0a968 ded5d23 6f0a968 e29a2b3 916235d 1ea99dc 6f0a968 e29a2b3 6f0a968 916235d 6f0a968 6930b6e 916235d 6f0a968 e29a2b3 50d971d 6f0a968 cb45be7 6f0a968 |
1 2 3 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 30 31 32 33 34 |
import gradio as gr
from transformers import pipeline
import concurrent.futures
import ktrain
import time
zero_shot = pipeline("zero-shot-classification")
distilbert = ktrain.load_predictor("models/distilbert-base-uncased-finetuned-internet-provider-v2")
def zero_shot_predict(text):
labels = ["Slow Connection", "Billing", "Setup", "No Connectivity"]
preds = zero_shot(text, candidate_labels=labels)
return {label: float(pred) for label, pred in zip(preds["labels"], preds["scores"])}
def distilbert_predict(text):
labels = distilbert.get_classes()
preds = distilbert.predict_proba(text)
return {label: float(pred) for label, pred in zip(labels, preds)}
def predict(text):
with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
zero_shot_future = executor.submit(zero_shot_predict, text)
distilbert_future = executor.submit(distilbert_predict, text)
concurrent.futures.wait([zero_shot_future, distilbert_future])
zero_shot_preds = zero_shot_future.result()
distilbert_preds = distilbert_future.result()
return zero_shot_preds, distilbert_preds
input = gr.inputs.Textbox(label="Customer Sentence")
outputs = [gr.outputs.Label(num_top_classes=4, label="Zero-Shot-Classification"), gr.outputs.Label(num_top_classes=4, label="DistilBERT")]
title = "Case Template Classification"
description = "Comparison of Zero-Shot-Classification and a fine-tuned DistilBERT."
gr.Interface(predict, input, outputs, live=False, live_update=False, title=title, analytics_enabled=False,
description=description, capture_session=True).launch() |