Team Ai
Apppublic

datasciencedojo/Zero-Shot-Text-Classification

sourceHugging Faceupdated 3y agoView on Hugging Face
40likes
app.py89 linesDownload Raw Back to root
1import gradio as gr2from transformers import pipeline3 4classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")5 6def zeroShotClassification(text_input, candidate_labels):7  labels = [label.strip(' ') for label in candidate_labels.split(',')]8  output = {}9  prediction = classifier(text_input, labels)10  for i in range(len(prediction['labels'])):11    output[prediction['labels'][i]] = prediction['scores'][i]12  return output13 14examples = [["One day I will see the world", "travel, live, die, future"]]15 16css = """17footer {display:none !important}18.output-markdown{display:none !important}19.gr-button-primary {20    z-index: 14;21    height: 43px;22    width: 130px;23    left: 0px;24    top: 0px;25    padding: 0px;26    cursor: pointer !important; 27    background: none rgb(17, 20, 45) !important;28    border: none !important;29    text-align: center !important;30    font-family: Poppins !important;31    font-size: 14px !important;32    font-weight: 500 !important;33    color: rgb(255, 255, 255) !important;34    line-height: 1 !important;35    border-radius: 12px !important;36    transition: box-shadow 200ms ease 0s, background 200ms ease 0s !important;37    box-shadow: none !important;38}39.gr-button-primary:hover{40    z-index: 14;41    height: 43px;42    width: 130px;43    left: 0px;44    top: 0px;45    padding: 0px;46    cursor: pointer !important;47    background: none rgb(66, 133, 244) !important;48    border: none !important;49    text-align: center !important;50    font-family: Poppins !important;51    font-size: 14px !important;52    font-weight: 500 !important;53    color: rgb(255, 255, 255) !important;54    line-height: 1 !important;55    border-radius: 12px !important;56    transition: box-shadow 200ms ease 0s, background 200ms ease 0s !important;57    box-shadow: rgb(0 0 0 / 23%) 0px 1px 7px 0px !important;58}59.hover\:bg-orange-50:hover {60    --tw-bg-opacity: 1 !important;61    background-color: rgb(229,225,255) !important;62}63 64 65.to-orange-200 {66    --tw-gradient-to: rgb(37 56 133 / 37%) !important;67}68 69.from-orange-400 {70    --tw-gradient-from: rgb(17, 20, 45) !important;71    --tw-gradient-to: rgb(255 150 51 / 0);72    --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to) !important;73}74 75.group-hover\:from-orange-500{76    --tw-gradient-from:rgb(17, 20, 45) !important; 77    --tw-gradient-to: rgb(37 56 133 / 37%);78    --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to) !important;79}80.group:hover .group-hover\:text-orange-500{81    --tw-text-opacity: 1 !important;82    color:rgb(37 56 133 / var(--tw-text-opacity)) !important;83}84 85 86"""87 88demo = gr.Interface(fn=zeroShotClassification, inputs=[gr.Textbox(label="Input"), gr.Textbox(label="Candidate Labels")], outputs=gr.Label(label="Classification"), title="Zero Shot Text Classification | Data Science Dojo", examples=examples, css=css)89demo.launch()