JamieAi33 commited on
Commit
22bd9b8
·
verified ·
1 Parent(s): 44f4d06

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ import numpy as np
4
+ from tensorflow.keras.models import load_model
5
+
6
+ # Load the saved model
7
+ model2 = load_model('/content/shoplifting_model.h5')
8
+
9
+ def predict_from_npy(npy_file):
10
+ try:
11
+ # Load the .npy file
12
+ data = np.load(npy_file.name, allow_pickle=True) # Use npy_file.name
13
+
14
+ # Reshape the data to (30, 51)
15
+ reshaped_data = data.reshape(30, 51)
16
+
17
+ # Make predictions
18
+ prediction = model2.predict(np.expand_dims(reshaped_data, axis=0))
19
+ threshold = 0.5
20
+ predicted_class = 'Shoplifting' if prediction[0][0] > threshold else 'Normal'
21
+
22
+ return predicted_class
23
+ except Exception as e:
24
+ return f"Error: {e}"
25
+
26
+ # Create Gradio interface
27
+ iface = gr.Interface(
28
+ fn=predict_from_npy,
29
+ inputs=gr.File(label="Upload .npy File"), # Input: File upload
30
+ outputs="text", # Output: Text (prediction)
31
+ title="Shoplifting Prediction from .npy",
32
+ description="Upload an .npy file containing keypoint data to get a shoplifting prediction."
33
+ )
34
+
35
+ # Launch the interface
36
+ iface.launch(debug=True)