abishek-official's picture
Update app.py
06e1e4c verified
import tensorflow as tf
import tensorflow_hub as hub
import tensorflow_text as text
import pandas as pd
import tensorflow as tf
import gradio as gr
# Load the SavedModel
model_path = 'Model'
loaded_model = tf.saved_model.load(model_path)
# Retrieve the inference function (usually 'serving_default')
infer = loaded_model.signatures['serving_default']
def pre_process(input_data):
input_tensor = tf.constant(input_data, dtype=tf.string)
return input_tensor
def ask(name):
data = pre_process(name)
predictions = infer(text = data)
output_tensor = predictions['output']
op = output_tensor.numpy()
if op[0] > 0.5:
return "The entered message is related to Banking"
else:
return "It is a non-banking message. May subject to be SPAM or other messages"
interface = gr.Interface(
fn=ask, # Function to call for prediction
inputs=gr.Textbox(label="Enter the bank message here:", placeholder="Type your message...", lines=5), # Input component
outputs=gr.Textbox(label="Prediction"), # Output component
title="Bank Message Classifier", # Title of the interface
description="Classify your bank messages as 'Banking' or 'Non-Banking'.", # Description text
theme="compact", # UI theme for compact design
css="""
.gradio-container {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
border-radius: 10px;
padding: 20px;
}
.gradio-title {
font-size: 24px;
font-weight: bold;
color: #423f3f;
text-align: center;
}
.gradio-description {
font-size: 16px;
color: #423f3f;
text-align: center;
margin-bottom: 20px;
}
.input_textbox {
border: 1px solid #ddd;
border-radius: 5px;
padding: 10px;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
}
.output_textbox {
border: 1px solid #ddd;
border-radius: 5px;
padding: 10px;
background-color: #e9ffe9;
}
"""
)
interface.launch()