vrushabh94's picture
Removed the sharing
a9beb0c
raw
history blame
2.75 kB
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
model_name = "MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
premise = ""
hypothesis = ""
def zeroShotClassification(text_input, candidate_labels, hypothesis):
input = tokenizer(text_input, hypothesis, truncation=True, return_tensors="pt")
output = model(input["input_ids"].to(device)) # device = "cuda:0" or "cpu"
prediction = torch.softmax(output["logits"][0], -1).tolist()
labels = [label.strip(' ') for label in candidate_labels.split(',')]
prediction = {name: round(float(pred) * 100, 1) for pred, name in zip(prediction, labels)}
return prediction
examples = [
["Administrative", "Agency Fees and Invoices,Other Acknowledgement,Product Name Designation,Annlication/RegistrationJProcedure Number Assigned,Registration Ownership Transferred,Access to Information I Public Disclosure,First Sale Notification,Lot Release,Letter of Authorization/Access,Clinical Trial Site Information"],
["Agency Decisions", "Other Decision,Approval,Breakthrough Designation Revoked,Orohan Drug Designation Denied,Not Aoorovable Letter I Reiection Letter,Investigational Trial Hold,Accelerated Assessment,Application/Registration Cancellation-Withdrawal-Terminations,Anorovable Letter/NOC-c,Fast Track Designation Granted,Orohan Drug Designation Granted,Post Approval Commitment Letter,Special Protocol Assessment,Refusal to File,Advanced Therapy Granted,Breakthrough Designation Granted,Fast Track Designation Denied,Fast Track Designation Revoked,Inactivation of Application / Registration,Inspection / Warning Letter,Investigational Trial Hold Release,Orphan Drug Designation Revoked"],
["Content Review", "Response from Agency,Dear Health Care Professional Letter,Acceptance / Validation / Submission Filed,Agencv Information/Request/Question/Comment,Extension Request Granted,GSK Inquiry,GSK Response to Information/Request/Question/Comment,Variation/Supplement Request,Translation"],
["General Correspondence","Agency Update,GSK Update"],
["Meeting Details", "Meeting Agenda / Package,Meeting Request,Meeting Minutes / Outcomes"],
["Submission Receipt", "Submission Receipt"]
]
demo = gr.Interface(fn=zeroShotClassification, inputs=[gr.Textbox(label="Input"), gr.Textbox(label="Candidate Labels", value="Meeting Minutes / Outcomes,Submission Receipt"), gr.Textbox(label="Hypothesys", value="Meeting Minutes / Outcomes,Submission Receipt")], outputs=gr.Label(label="Classification"), examples=examples)
demo.launch();