Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
import tensorflow_hub as hub
|
| 3 |
+
import tensorflow_text as text
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import tensorflow as tf
|
| 6 |
+
import gradio as gr
|
| 7 |
+
|
| 8 |
+
# Load the SavedModel
|
| 9 |
+
model_path = '/content/drive/MyDrive/BERT/saved_model'
|
| 10 |
+
loaded_model = tf.saved_model.load(model_path)
|
| 11 |
+
|
| 12 |
+
# Retrieve the inference function (usually 'serving_default')
|
| 13 |
+
infer = loaded_model.signatures['serving_default']
|
| 14 |
+
|
| 15 |
+
def pre_process(input_data):
|
| 16 |
+
input_tensor = tf.constant(input_data, dtype=tf.string)
|
| 17 |
+
return input_tensor
|
| 18 |
+
|
| 19 |
+
def 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 |
+
|
| 29 |
+
demo = gr.Interface(fn=ask, inputs="text", outputs="text")
|
| 30 |
+
demo.launch()
|
| 31 |
+
|
| 32 |
+
|