Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,8 +2,6 @@ import gradio as gr
|
|
| 2 |
import tensorflow as tf
|
| 3 |
import numpy as np
|
| 4 |
from PIL import Image
|
| 5 |
-
import requests
|
| 6 |
-
from io import BytesIO
|
| 7 |
|
| 8 |
# Load the model
|
| 9 |
model = tf.keras.models.load_model('Nutrient-Model.h5')
|
|
@@ -11,6 +9,7 @@ model = tf.keras.models.load_model('Nutrient-Model.h5')
|
|
| 11 |
# Define the class names
|
| 12 |
class_names = ['Iron', 'Magnesium', 'Nitrogen', 'Potassium', 'Zinc']
|
| 13 |
|
|
|
|
| 14 |
def classify_image(image):
|
| 15 |
# Convert the numpy array to a PIL Image object
|
| 16 |
pil_image = Image.fromarray(np.uint8(image)).convert('RGB')
|
|
@@ -40,9 +39,9 @@ def classify_image(image):
|
|
| 40 |
return f"{predicted_class} ({confidence_score*100:.2f}%)"
|
| 41 |
|
| 42 |
# Define the Gradio interface
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
gr.Interface(fn=classify_image, inputs=
|
| 46 |
-
).launch(share=True)
|
| 47 |
-
|
| 48 |
|
|
|
|
|
|
|
|
|
| 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')
|
|
|
|
| 9 |
# Define the class names
|
| 10 |
class_names = ['Iron', 'Magnesium', 'Nitrogen', 'Potassium', 'Zinc']
|
| 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')
|
|
|
|
| 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 five classes: Iron, Magnesium, Nitrogen, Potassium, or Zinc.")
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
# Launch the interface
|
| 47 |
+
interface.launch(share=True)
|