peshoet commited on
Commit
889ddf2
·
verified ·
1 Parent(s): 41cfc65

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from tensorflow.keras.models import load_model
3
+ import numpy as np
4
+
5
+ # Load the model
6
+ model = load_model(r"C:\Users\uSeR\Documents\ai-tutor-ruangguru\project\waste_classifier_model.keras")
7
+
8
+ # Prediction function
9
+ def classify_image(image):
10
+ # Ensure the image is in the expected format
11
+ if image is None:
12
+ return "No image provided."
13
+
14
+ # Convert the image to a numpy array
15
+ image = np.array(image)
16
+
17
+ # Check if the image has the expected shape and resize if necessary
18
+ if image.shape != (128, 128, 3):
19
+ image = np.resize(image, (128, 128, 3)) # Resize the image to (128, 128, 3)
20
+
21
+ # Normalize the image
22
+ image = image / 255.0
23
+
24
+ # Add batch dimension
25
+ image = np.expand_dims(image, axis=0)
26
+
27
+ # Make prediction
28
+ prediction = model.predict(image)
29
+
30
+ # Interpret the prediction
31
+ class_label = 'Organic' if prediction[0][0] > 0.5 else 'Recycleable' # Adjust labels based on your model's output
32
+ return class_label
33
+
34
+ # Create Gradio interface
35
+ interface = gr.Interface(fn=classify_image, inputs=gr.Image(type="numpy"), outputs="text")
36
+ interface.launch(share=True)