Files changed (3) hide show
  1. Nutrient-Model (2).h5 +3 -0
  2. app.py +47 -0
  3. requirements.txt +6 -0
Nutrient-Model (2).h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0b2ad242e6c6fa31b44c6ece988f11bd18677feb17e23d226db8ffe747835c9f
3
+ size 516595296
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ # Load the model
7
+ model = tf.keras.models.load_model('Nutrient-Model.h5')
8
+
9
+ # Define the class names
10
+ class_names = ['Magnesium','Nitrogen','Potassium','Phosphorus','Sulfur']
11
+
12
+ # Function to classify the image
13
+ def classify_image(image):
14
+ # Convert the numpy array to a PIL Image object
15
+ pil_image = Image.fromarray(np.uint8(image)).convert('RGB')
16
+
17
+ # Resize the image
18
+ pil_image = pil_image.resize((224, 224))
19
+
20
+ # Convert the PIL Image object to a numpy array
21
+ image_array = np.array(pil_image)
22
+
23
+ # Normalize the image
24
+ normalized_image_array = (image_array.astype(np.float32) / 255.0)
25
+
26
+ # Reshape the image
27
+ data = normalized_image_array.reshape((1, 224, 224, 3))
28
+
29
+ # Make the prediction
30
+ prediction = model.predict(data)[0]
31
+
32
+ # Get the predicted class name
33
+ predicted_class = class_names[np.argmax(prediction)]
34
+
35
+ # Get the confidence score for the predicted class
36
+ confidence_score = np.max(prediction)
37
+
38
+ # Return the predicted class and confidence score
39
+ return f"{predicted_class} ({confidence_score*100:.2f}%)"
40
+
41
+ # Define the Gradio interface
42
+ inputs = gr.inputs.Image()
43
+ outputs = gr.outputs.Textbox()
44
+ interface = gr.Interface(fn=classify_image, inputs=inputs, outputs=outputs, title="Image Classification", description="Classify an image into one of six classes: Phosphorus, Magnesium, Nitrogen,Potassium, Calcium, Sulfur.")
45
+
46
+ # Launch the interface
47
+ interface.launch()
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ gradio==3.28.1
2
+ numpy==1.23.4
3
+ Pillow==9.5.0
4
+ Requests==2.29.0
5
+ tensorflow==2.10.0
6
+ tensorflow_gpu==2.10.1