-
Notifications
You must be signed in to change notification settings - Fork 0
/
ai_utils.py
21 lines (17 loc) · 702 Bytes
/
ai_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import tensorflow as tf
from tensorflow.keras.models import load_model
import spacy
# Load pre-trained models
nlp = spacy.load('en_core_web_sm')
model = load_model('path/to/your/model.h5')
def text_entity_recognition(text):
"""Recognize entities in text using NLP model."""
doc = nlp(text)
return [(ent.text, ent.label_) for ent in doc.ents]
def image_classification(image_path):
"""Classify image using the deep learning model."""
image = tf.keras.preprocessing.image.load_img(image_path, target_size=(224, 224))
image = tf.keras.preprocessing.image.img_to_array(image)
image = tf.expand_dims(image, 0)
predictions = model.predict(image)
return predictions