ZeroShot / app.py
Mariamabed's picture
Update app.py
298eb7e verified
raw
history blame contribute delete
779 Bytes
from transformers import pipeline
import gradio as gr
# Initialize zero-shot-classification pipeline
zero_shot_classifier = pipeline("zero-shot-classification")
# Define classification function
def classify(text, labels):
classifier_labels = labels.split(",") # Split the comma-separated labels into a list
response = zero_shot_classifier(text, classifier_labels) # Perform the classification
return response
# Define Gradio interface elements
txt = gr.Textbox(lines=1, label="English", placeholder="Text to be classified")
labels = gr.Textbox(lines=1, label="Labels", placeholder="Comma-separated labels")
out = gr.Textbox(lines=1, label="Classification")
# Create the interface and launch it
gr.Interface(classify, inputs=[txt, labels], outputs=out).launch()