abishek-official/Bert_Text_Classification
0
1import tensorflow as tf2import tensorflow_hub as hub3import tensorflow_text as text4import pandas as pd5import tensorflow as tf6import gradio as gr7 8# Load the SavedModel9model_path = 'Model'10loaded_model = tf.saved_model.load(model_path)11 12# Retrieve the inference function (usually 'serving_default')13infer = loaded_model.signatures['serving_default']14 15def pre_process(input_data):16 input_tensor = tf.constant(input_data, dtype=tf.string)17 return input_tensor18 19def ask(name):20 data = pre_process(name)21 predictions = infer(text = data)22 output_tensor = predictions['output']23 op = output_tensor.numpy()24 if op[0] > 0.5:25 return "The entered message is related to Banking"26 else:27 return "It is a non-banking message. May subject to be SPAM or other messages"28 29interface = gr.Interface(30 fn=ask, # Function to call for prediction31 inputs=gr.Textbox(label="Enter the bank message here:", placeholder="Type your message...", lines=5), # Input component32 outputs=gr.Textbox(label="Prediction"), # Output component33 title="Bank Message Classifier", # Title of the interface34 description="Classify your bank messages as 'Banking' or 'Non-Banking'.", # Description text35 theme="compact", # UI theme for compact design36 css="""37 .gradio-container {38 font-family: Arial, sans-serif;39 background-color: #f4f4f4;40 border-radius: 10px;41 padding: 20px;42 }43 .gradio-title {44 font-size: 24px;45 font-weight: bold;46 color: #423f3f;47 text-align: center;48 }49 .gradio-description {50 font-size: 16px;51 color: #423f3f;52 text-align: center;53 margin-bottom: 20px;54 }55 .input_textbox {56 border: 1px solid #ddd;57 border-radius: 5px;58 padding: 10px;59 box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);60 }61 .output_textbox {62 border: 1px solid #ddd;63 border-radius: 5px;64 padding: 10px;65 background-color: #e9ffe9;66 }67 """68)69 70interface.launch()71 72 73 