Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,26 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
-
# Load zero-shot classification
|
| 5 |
-
classifier = pipeline(
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
-
def
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
return formatted
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 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 |
-
|
|
|
|
|
|
|
| 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()
|