Vincent Claes
commited on
Commit
•
1d6cf0f
1
Parent(s):
f8879c5
inital commit
Browse files- README.md +3 -3
- app.py +37 -0
- requirements.txt +3 -0
README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
---
|
2 |
title: Bad Stuff
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.19.1
|
8 |
app_file: app.py
|
|
|
1 |
---
|
2 |
title: Bad Stuff
|
3 |
+
emoji: 🚭
|
4 |
+
colorFrom: gray
|
5 |
+
colorTo: gray
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.19.1
|
8 |
app_file: app.py
|
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the zero-shot classification pipeline
|
5 |
+
classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
|
6 |
+
|
7 |
+
def classify_text(line_item, classes):
|
8 |
+
# Split the classes string into a list
|
9 |
+
class_list = classes.split(',')
|
10 |
+
# Perform classification
|
11 |
+
results = classifier(line_item, class_list, multi_class=True)
|
12 |
+
|
13 |
+
# Prepare the output as a dictionary {label: score}
|
14 |
+
output = {label: round(score, 4) for label, score in zip(results['labels'], results['scores'])}
|
15 |
+
|
16 |
+
return output
|
17 |
+
|
18 |
+
# Define Gradio interface with example
|
19 |
+
interface = gr.Interface(
|
20 |
+
classify_text,
|
21 |
+
[
|
22 |
+
gr.Textbox(lines=2, placeholder="Enter Line Item Here...", label="Line Item"),
|
23 |
+
gr.Textbox(placeholder="Enter Classes Here, Separated by Commas", label="Classes")
|
24 |
+
],
|
25 |
+
gr.Label(num_top_classes=None, label="Class Probability Scores"),
|
26 |
+
title="Bad Stuff, But So Good.",
|
27 |
+
description="A zero-shot classification app using facebook/bart-large-mnli model to classify text into given categories.",
|
28 |
+
examples=[
|
29 |
+
["wijn glas x3 $18", "tobacco,alcohol"], # Example input
|
30 |
+
["Stoofvlees $25", "tobacco,alcohol"],
|
31 |
+
["Marlboro 10$", "tobacco,alcohol"],
|
32 |
+
]
|
33 |
+
)
|
34 |
+
|
35 |
+
# Launch the application
|
36 |
+
if __name__ == "__main__":
|
37 |
+
interface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
gradio
|
3 |
+
torch
|