Views
No views yet

1import os
2import json
3import tensorflow as tf
4import tensorflow_hub as hub
5
6# Paths to the model and labels.
7MODEL_PATH = r"final_model.h5"
8LABELS_PATH = r"labels.json"
9
10def load_labels(labels_file):
11 with open(labels_file, 'r', encoding='utf-8') as f:
12 return json.load(f)
13
14def main():
15 print("Loading model from:", MODEL_PATH)
16 model = tf.keras.models.load_model(MODEL_PATH, custom_objects={'KerasLayer': hub.KerasLayer})
17 print("Model loaded successfully.")
18
19 labels = load_labels(LABELS_PATH)
20 print("Loaded labels:", labels)
21
22 # Sample sentence for testing.
23 sample_sentence = "John Doe's account number 1234567890 was flagged for review due to unusual activity."
24 print("Sample sentence:", sample_sentence)
25
26 # Run prediction.
27 predictions = model.predict([sample_sentence])
28 print("Predictions:")
29 for label, prob in zip(labels, predictions[0]):
30 print(f"{label}: {prob:.2f}")
31
32if __name__ == "__main__":
33 main()