Spaces:
Sleeping
Sleeping
changed logic on parsing
Browse files
app.py
CHANGED
|
@@ -1,6 +1,46 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
classifier = pipeline("text-classification", model="kuro-08/bert-transaction-categorization")
|
| 5 |
+
labels = {
|
| 6 |
+
0: "Utilities",
|
| 7 |
+
1: "Health",
|
| 8 |
+
2: "Dining",
|
| 9 |
+
3: "Travel",
|
| 10 |
+
4: "Education",
|
| 11 |
+
5: "Subscription",
|
| 12 |
+
6: "Family",
|
| 13 |
+
7: "Food",
|
| 14 |
+
8: "Festivals",
|
| 15 |
+
9: "Culture",
|
| 16 |
+
10: "Apparel",
|
| 17 |
+
11: "Transportation",
|
| 18 |
+
12: "Investment",
|
| 19 |
+
13: "Shopping",
|
| 20 |
+
14: "Groceries",
|
| 21 |
+
15: "Documents",
|
| 22 |
+
16: "Grooming",
|
| 23 |
+
17: "Entertainment",
|
| 24 |
+
18: "Social Life",
|
| 25 |
+
19: "Beauty",
|
| 26 |
+
20: "Rent",
|
| 27 |
+
21: "Money transfer",
|
| 28 |
+
22: "Salary",
|
| 29 |
+
23: "Tourism",
|
| 30 |
+
24: "Household",
|
| 31 |
+
}
|
| 32 |
|
| 33 |
+
def categorize(description: str):
|
| 34 |
+
result = classifier(description)[0]
|
| 35 |
+
label_id = int(result['label'].split('_')[1])
|
| 36 |
+
category = labels.get(label_id, "Miscellaneous")
|
| 37 |
+
return {"category": category}
|
| 38 |
+
|
| 39 |
+
demo = gr.Interface(
|
| 40 |
+
fn=categorize,
|
| 41 |
+
inputs=gr.Textbox(label="Transaction Description", placeholder="e.g., Dinner at Subway"),
|
| 42 |
+
outputs=gr.JSON(label="Category"),
|
| 43 |
+
title="Transaction Categorizer API"
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
demo.launch()
|