Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tensorflow as tf
|
3 |
+
import numpy as np
|
4 |
+
from tensorflow.keras.utils import load_img, img_to_array
|
5 |
+
|
6 |
+
# Load the pre-trained model
|
7 |
+
model = tf.keras.models.load_model('https://huggingface.co/yolac/BacterialMorphologyClassification/resolve/main/model')
|
8 |
+
|
9 |
+
# Define a function for making predictions
|
10 |
+
def predict_bacterial_morphology(image):
|
11 |
+
# Preprocess the input image
|
12 |
+
img_array = img_to_array(image) / 255.0
|
13 |
+
img_array = np.expand_dims(img_array, axis=0)
|
14 |
+
# Make a prediction
|
15 |
+
prediction = model.predict(img_array, verbose=0)
|
16 |
+
class_labels = ['cocci', 'bacilli', 'spirilla']
|
17 |
+
predicted_label = class_labels[np.argmax(prediction)]
|
18 |
+
return predicted_label
|
19 |
+
|
20 |
+
# Define the Gradio interface
|
21 |
+
iface = gr.Interface(
|
22 |
+
fn=predict_bacterial_morphology,
|
23 |
+
inputs=gr.inputs.Image(shape=(224, 224)),
|
24 |
+
outputs=gr.outputs.Textbox(label="Predicted Class"),
|
25 |
+
title="Bacterial Morphology Classification",
|
26 |
+
description="Upload an image of a bacterium to classify it into one of the following categories: cocci, bacilli, or spirilla."
|
27 |
+
)
|
28 |
+
|
29 |
+
# Launch the app
|
30 |
+
if __name__ == "__main__":
|
31 |
+
iface.launch()
|