File size: 1,103 Bytes
e5728f5
 
 
aa42168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e5728f5
aa42168
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import gradio as gr
from transformers import pipeline

classifier = pipeline("text-classification", model="kuro-08/bert-transaction-categorization")
labels = {
    0: "Utilities",
    1: "Health",
    2: "Dining",
    3: "Travel",
    4: "Education",
    5: "Subscription",
    6: "Family",
    7: "Food",
    8: "Festivals",
    9: "Culture",
    10: "Apparel",
    11: "Transportation",
    12: "Investment",
    13: "Shopping",
    14: "Groceries",
    15: "Documents",
    16: "Grooming",
    17: "Entertainment",
    18: "Social Life",
    19: "Beauty",
    20: "Rent",
    21: "Money transfer",
    22: "Salary",
    23: "Tourism",
    24: "Household",
}

def categorize(description: str):
    result = classifier(description)[0]
    label_id = int(result['label'].split('_')[1])
    category = labels.get(label_id, "Miscellaneous")
    return {"category": category}

demo = gr.Interface(
    fn=categorize,
    inputs=gr.Textbox(label="Transaction Description", placeholder="e.g., Dinner at Subway"),
    outputs=gr.JSON(label="Category"),
    title="Transaction Categorizer API"
)

demo.launch()