Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,40 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
| 8 |
-
description=description,
|
| 9 |
-
examples=examples
|
| 10 |
-
)
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import numpy as np
|
| 5 |
|
| 6 |
+
# Load your custom regression model
|
| 7 |
+
model_path = "freshwaterfish_classifier_model_ResNet50.keras"
|
| 8 |
+
model = tf.keras.models.load_model(model_path)
|
| 9 |
|
| 10 |
+
labels = ['Catfish', 'Freshwater Eel', 'Goby', 'Perch']
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
# Define regression function
|
| 13 |
+
def predict_regression(image):
|
| 14 |
+
# Preprocess image
|
| 15 |
+
image = Image.fromarray(image.astype('uint8'))
|
| 16 |
+
image = image.resize((224, 224)).convert('RGB')
|
| 17 |
+
image = np.array(image)
|
| 18 |
+
print(image.shape)
|
| 19 |
+
# Predict
|
| 20 |
+
prediction = model.predict(image[None, ...]) # Assuming single regression value
|
| 21 |
+
confidences = {labels[i]: np.round(float(prediction[0][i]), 2) for i in range(len(labels))}
|
| 22 |
+
return confidences
|
| 23 |
+
|
| 24 |
+
# Define the file paths for the test images
|
| 25 |
+
test_images = ["myImages/Egli1.jpeg", "myImages/Egli2.jpeg", "myImages/Wels1.jpeg", "myImages/Wels2.jpeg"]
|
| 26 |
+
|
| 27 |
+
# Load and preprocess the test images
|
| 28 |
+
example_images = [np.array(Image.open(image_path).resize((224, 224)).convert('RGB')) / 255.0 for image_path in test_images]
|
| 29 |
+
|
| 30 |
+
# Create Gradio interface
|
| 31 |
+
input_image = gr.Image()
|
| 32 |
+
output_text = gr.Textbox(label="Predicted Value")
|
| 33 |
+
interface = gr.Interface(fn=predict_regression,
|
| 34 |
+
inputs=input_image,
|
| 35 |
+
outputs=gr.Label(),
|
| 36 |
+
title="Freshwater Fish Classifier",
|
| 37 |
+
description="This model predicts four species of a freshwater fish from the lake of constance.",
|
| 38 |
+
examples=example_images
|
| 39 |
+
)
|
| 40 |
interface.launch()
|