KirtanG commited on
Commit
79c1071
·
1 Parent(s): c355b12

Deploy transaction classifier with Gradio API

Browse files
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import joblib
2
+ import gradio as gr
3
+ import pandas as pd
4
+
5
+ def clean_text(text:str)->str:
6
+ if pd.isna(text):
7
+ return ""
8
+ text = str(text).lower()
9
+ text = ''.join(char for char in text if char.isalpha() or char.isspace())
10
+ return text
11
+
12
+ LogisticModel = joblib.load(r'.\assets\transaction_classifier_model_Logistic_Regression.joblib')
13
+ Vectorizer = joblib.load(r'.\assets\tfidf_vectorizer.joblib')
14
+
15
+ def predict_category(description:str)->str:
16
+ cleaned_text = clean_text(description)
17
+ X = Vectorizer.transform([cleaned_text]).toarray()
18
+ predict = LogisticModel.predict(X)[0]
19
+ return predict
20
+
21
+ if __name__ == "__main__":
22
+ demo = gr.Interface(
23
+ fn=predict_category,
24
+ inputs=gr.Textbox(label="Enter Transaction Description"),
25
+ outputs=gr.Textbox(label="Predicted Category"),
26
+ title="Transaction Classifier",
27
+ description="Enter a transaction description to predict its category!"
28
+ )
29
+
30
+ demo.launch()
assets/tfidf_vectorizer.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a935342c5ee467059bcf3ef83251081ee7547dac6f077132d5d3ca098deeb9bf
3
+ size 352362
assets/transaction_classifier_model_Logistic_Regression.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7c08b662c45a28701b9f1dd74f6100ce2aa502060ae7bce63d0784d936b2fe7a
3
+ size 769655
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio==5.24.0
2
+ joblib==1.4.2
3
+ scikit-learn==1.6.1
4
+ pandas