hazarri commited on
Commit
84af299
·
verified ·
1 Parent(s): 5178e18

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load zero-shot classification model
5
+ classifier = pipeline(
6
+ "zero-shot-classification",
7
+ model="MoritzLaurer/deberta-v3-large-zeroshot-v2.0"
8
+ )
9
+
10
+ def classify_text(text, labels):
11
+ labels_list = [label.strip() for label in labels.split(",")]
12
+ result = classifier(text, candidate_labels=labels_list)
13
+ formatted = "\n".join([
14
+ f"{label}: {score:.2f}" for label, score in zip(result["labels"], result["scores"])
15
+ ])
16
+ return formatted
17
+
18
+ demo = gr.Interface(
19
+ fn=classify_text,
20
+ inputs=[
21
+ gr.Textbox(lines=3, label="Text to classify"),
22
+ gr.Textbox(lines=1, label="Labels (comma separated, e.g. adverse, beneficial, neutral)")
23
+ ],
24
+ outputs="text",
25
+ title="DeBERTa Zero-Shot Classification API",
26
+ description="Zero-shot classification using MoritzLaurer's DeBERTa-v3-large-zeroshot-v2.0 model."
27
+ )
28
+
29
+ demo.launch()