Defkhan5960 commited on
Commit
b7997c9
1 Parent(s): cd43296

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +43 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from PIL import Image
4
+ import tensorflow as tf
5
+ from tensorflow.keras.preprocessing import image
6
+ from tensorflow.keras.models import load_model
7
+ from tensorflow.keras.applications.efficientnet import preprocess_input
8
+
9
+ # Load the trained model
10
+ model = load_model("efficent_net224B0.h5")
11
+
12
+ # Define the classes
13
+ waste_labels = {0: 'Fibres', 1: 'Nanowires', 2: 'Particles', 3: 'Powder'}
14
+
15
+ # Define the Gradio interface
16
+ def classify_image(pil_image):
17
+ # Convert PIL.Image to Numpy array
18
+ img = image.img_to_array(pil_image)
19
+
20
+ # Resize to the model's expected input size
21
+ img = tf.image.resize(img, (224, 224))
22
+
23
+ # Expand dimensions to create a batch size of 1
24
+ img = np.expand_dims(img, axis=0)
25
+
26
+ # Preprocess the input for the EfficientNet model
27
+ img = preprocess_input(img)
28
+
29
+ # Make prediction
30
+ prediction = model.predict(img)
31
+
32
+ # Get predicted class and confidence
33
+ predicted_class = np.argmax(prediction)
34
+ predicted_class = waste_labels[predicted_class]
35
+ confidence = prediction[0, np.argmax(prediction)]
36
+
37
+ return predicted_class
38
+
39
+ # Create the Gradio interface
40
+ iface = gr.Interface(fn=classify_image, inputs="image", outputs="text")
41
+
42
+ # Launch the Gradio interface
43
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+
2
+ pandas==1.5.3
3
+ plotly==5.0.0
4
+ tensorflow==2.12.0
5
+ gradio==4.7.1