Spaces:
Runtime error
Runtime error
Commit
·
b442b87
1
Parent(s):
3e93e01
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,15 +4,24 @@ from transformers import pipeline
|
|
| 4 |
# Load the zero-shot classification pipeline
|
| 5 |
classifier = pipeline("zero-shot-classification")
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
# Define the Gradio interface
|
| 8 |
iface = gr.Interface(
|
| 9 |
-
fn=
|
| 10 |
-
inputs=[
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
live=True,
|
| 13 |
title="Zero-Shot Classification Web App",
|
| 14 |
description="Enter a text and candidate labels (comma-separated) to classify.",
|
| 15 |
)
|
| 16 |
|
| 17 |
# Launch the Gradio interface
|
| 18 |
-
iface.launch(share=True)
|
|
|
|
| 4 |
# Load the zero-shot classification pipeline
|
| 5 |
classifier = pipeline("zero-shot-classification")
|
| 6 |
|
| 7 |
+
# Function to perform classification
|
| 8 |
+
def classify_text(text, candidate_labels):
|
| 9 |
+
result = classifier(text, candidate_labels)
|
| 10 |
+
return result['labels'][0], result['scores'][0]
|
| 11 |
+
|
| 12 |
# Define the Gradio interface
|
| 13 |
iface = gr.Interface(
|
| 14 |
+
fn=classify_text,
|
| 15 |
+
inputs=[
|
| 16 |
+
gr.Textbox(label="Enter Text"),
|
| 17 |
+
gr.Textbox(label="Enter Candidate Labels (comma-separated)"),
|
| 18 |
+
gr.Button(text="Submit")
|
| 19 |
+
],
|
| 20 |
+
outputs=gr.Label(num_top_classes=1),
|
| 21 |
live=True,
|
| 22 |
title="Zero-Shot Classification Web App",
|
| 23 |
description="Enter a text and candidate labels (comma-separated) to classify.",
|
| 24 |
)
|
| 25 |
|
| 26 |
# Launch the Gradio interface
|
| 27 |
+
iface.launch(share=True)
|