RohitCSharp commited on
Commit
cada587
·
verified ·
1 Parent(s): 069c519

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load zero-shot-classification pipeline
5
+ classifier = pipeline("zero-shot-classification",
6
+ model="facebook/bart-large-mnli") # Can also use 'joeddav/xlm-roberta-large-xnli'
7
+
8
+ def classify_text(text, labels):
9
+ candidate_labels = [label.strip() for label in labels.split(",")]
10
+ result = classifier(text, candidate_labels)
11
+ return {label: float(f"{score:.3f}") for label, score in zip(result["labels"], result["scores"])}
12
+
13
+ demo = gr.Interface(
14
+ fn=classify_text,
15
+ inputs=[
16
+ gr.Textbox(lines=3, placeholder="Enter the text to classify...", label="Input Text"),
17
+ gr.Textbox(lines=1, placeholder="Enter comma-separated labels (e.g., finance, tech, sports)", label="Candidate Labels")
18
+ ],
19
+ outputs="label",
20
+ title="Zero-Shot Text Classification with BART & XLM-RoBERTa",
21
+ description="Classify text into categories without training data using transformer-based models. Based on the article from C# Corner."
22
+ )
23
+
24
+ demo.launch()