File size: 911 Bytes
79c1071
 
 
 
 
 
 
 
 
 
 
c7dc3bf
 
79c1071
 
 
 
 
 
 
d39cfcd
 
79c1071
 
 
 
 
 
 
d39cfcd
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
import joblib
import gradio as gr
import pandas as pd

def clean_text(text:str)->str:
  if pd.isna(text):
        return ""
  text = str(text).lower()
  text = ''.join(char for char in text if char.isalpha() or char.isspace())
  return text

LogisticModel = joblib.load(r'transaction_classifier_model_Logistic_Regression.joblib')
Vectorizer = joblib.load(r'tfidf_vectorizer.joblib')

def predict_category(description:str)->str:
    cleaned_text = clean_text(description)
    X = Vectorizer.transform([cleaned_text]).toarray()
    predict = LogisticModel.predict(X)[0]
    return predict 


demo = gr.Interface(
        fn=predict_category,
        inputs=gr.Textbox(label="Enter Transaction Description"),
        outputs=gr.Textbox(label="Predicted Category"),
        title="Transaction Classifier",
        description="Enter a transaction description to predict its category!"
    )

demo.launch(share=True)