| 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 |
|
|
| |
| model_path = 'Model' |
| loaded_model = tf.saved_model.load(model_path) |
|
|
| |
| 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, |
| inputs=gr.Textbox(label="Enter the bank message here:", placeholder="Type your message...", lines=5), |
| outputs=gr.Textbox(label="Prediction"), |
| title="Bank Message Classifier", |
| description="Classify your bank messages as 'Banking' or 'Non-Banking'.", |
| theme="compact", |
| 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() |
|
|
|
|
|
|