Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,40 +3,23 @@ import tensorflow as tf
|
|
| 3 |
import numpy as np
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
-
# Load
|
| 7 |
-
model = tf.keras.models.load_model("
|
| 8 |
-
|
| 9 |
-
# Define class
|
| 10 |
-
class_names = ["
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
confidence_scores = {class_names[i]: float(predictions[0][i]) for i in range(len(class_names))} # Get probability scores
|
| 27 |
-
|
| 28 |
-
return {"Predicted Class": class_names[predicted_class], "Confidence Scores": confidence_scores}
|
| 29 |
-
|
| 30 |
-
# Gradio API Interface
|
| 31 |
-
interface = gr.Interface(
|
| 32 |
-
fn=predict,
|
| 33 |
-
inputs=gr.Image(type="pil"), # Accept image as input
|
| 34 |
-
outputs=gr.JSON(), # Return JSON response
|
| 35 |
-
title="Fire Detection API",
|
| 36 |
-
description="Send an image to classify it into one of four categories: Fake, Low, Medium, or High."
|
| 37 |
-
)
|
| 38 |
-
|
| 39 |
-
# Launch API
|
| 40 |
-
if __name__ == "__main__":
|
| 41 |
-
interface.launch(share=True)
|
| 42 |
-
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
+
# Load model
|
| 7 |
+
model = tf.keras.models.load_model("Mobilenet_model.h5")
|
| 8 |
+
|
| 9 |
+
# Define class labels
|
| 10 |
+
class_names = ["Organic", "Recyclable", "Hazardous"]
|
| 11 |
+
|
| 12 |
+
def classify_image(image):
|
| 13 |
+
image = image.resize((128, 128)) # Resize to match input size
|
| 14 |
+
img_array = np.array(image) / 255.0
|
| 15 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 16 |
+
predictions = model.predict(img_array)
|
| 17 |
+
class_index = np.argmax(predictions[0])
|
| 18 |
+
return class_names[class_index]
|
| 19 |
+
|
| 20 |
+
gr.Interface(
|
| 21 |
+
fn=classify_image,
|
| 22 |
+
inputs=gr.Image(type="pil"),
|
| 23 |
+
outputs="text",
|
| 24 |
+
title="Waste Classification Model",
|
| 25 |
+
).launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|