Mattie / app.py
JamieAi33's picture
Update app.py
b0ce263 verified
import gradio as gr
import numpy as np
from tensorflow.keras.models import load_model
# Load the saved model
model2 = load_model('shoplifting_model.h5')
def predict_from_npy(npy_file):
try:
# Load the .npy file
data = np.load(npy_file.name, allow_pickle=True) # Use npy_file.name
# Reshape the data to (30, 51)
reshaped_data = data.reshape(30, 51)
# Make predictions
prediction = model2.predict(np.expand_dims(reshaped_data, axis=0))
threshold = 0.5
predicted_class = 'Shoplifting' if prediction[0][0] > threshold else 'Normal'
return predicted_class
except Exception as e:
return f"Error: {e}"
# Create Gradio interface
iface = gr.Interface(
fn=predict_from_npy,
inputs=gr.File(label="Upload .npy File"), # Input: File upload
outputs="text", # Output: Text (prediction)
title="Shoplifting Prediction from .npy",
description="Upload an .npy file containing keypoint data to get a shoplifting prediction."
)
# Launch the interface
iface.launch(debug=True)