root
commited on
Commit
•
5f9dcd8
1
Parent(s):
a4d9585
Initial Commit
Browse files- app.py +32 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import gradio as gr
|
3 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
4 |
+
import torch
|
5 |
+
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
6 |
+
|
7 |
+
model_name = "MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli"
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
10 |
+
|
11 |
+
premise = ""
|
12 |
+
hypothesis = ""
|
13 |
+
|
14 |
+
def zeroShotClassification(text_input, hypothesis, candidate_labels):
|
15 |
+
input = tokenizer(text_input, hypothesis, truncation=True, return_tensors="pt")
|
16 |
+
output = model(input["input_ids"].to(device)) # device = "cuda:0" or "cpu"
|
17 |
+
prediction = torch.softmax(output["logits"][0], -1).tolist()
|
18 |
+
label_names = candidate_labels #["entailment", "neutral", "contradiction"]
|
19 |
+
prediction = {name: round(float(pred) * 100, 1) for pred, name in zip(prediction, label_names)}
|
20 |
+
return prediction
|
21 |
+
|
22 |
+
examples = [
|
23 |
+
["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"],
|
24 |
+
["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"],
|
25 |
+
["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"],
|
26 |
+
["General Correspondence","Agency Update,GSK Update"],
|
27 |
+
["Meeting Details", "Meeting Agenda / Package,Meeting Request,Meeting Minutes / Outcomes"],
|
28 |
+
["Submission Receipt", "Submission Receipt"]
|
29 |
+
]
|
30 |
+
|
31 |
+
demo = gr.Interface(fn=zeroShotClassification, inputs=[gr.Textbox(label="Input"), gr.Textbox(label="Candidate Labels", value="Meeting Minutes / Outcomes,Submission Receipt")], outputs=gr.Label(label="Classification"), examples=examples)
|
32 |
+
demo.launch();
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
gradio
|
3 |
+
transformers
|
4 |
+
torch
|