File size: 1,075 Bytes
22bd9b8
 
 
 
 
 
b0ce263
22bd9b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

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)