hazarri commited on
Commit
880ab0e
·
verified ·
1 Parent(s): b74bdd2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -23
app.py CHANGED
@@ -1,29 +1,26 @@
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()
 
 
1
  from transformers import pipeline
2
+ import gradio as gr
3
 
4
+ # Load zero-shot classification pipeline
5
+ classifier = pipeline("zero-shot-classification", model="MoritzLaurer/deberta-v3-large-zeroshot-v2.0")
6
+
7
+ # Define possible classes
8
+ labels = ["dangerous", "mild", "neutral"]
9
 
10
+ def classify_side_effect(text):
11
+ if not text.strip():
12
+ return {"error": "Empty input"}
13
+ result = classifier(text, candidate_labels=labels)
14
+ scores = {label: float(score) for label, score in zip(result["labels"], result["scores"])}
15
+ return scores
 
16
 
17
+ # Gradio interface
18
+ iface = gr.Interface(
19
+ fn=classify_side_effect,
20
+ inputs=gr.Textbox(label="Enter a side effect or sentence"),
21
+ outputs=gr.Label(label="Classification Result"),
22
+ title="Zero-Shot ADR Severity Classifier",
23
+ description="Classifies a given sentence (e.g. side effect) as dangerous, mild, or neutral using DeBERTa v3 Large Zero-Shot."
 
 
24
  )
25
 
26
+ iface.launch()