Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
# import numpy as np
|
| 4 |
+
|
| 5 |
+
model=tf.keras.models.load_model("final_model_v_full.keras")
|
| 6 |
+
class_names =['Potato___Early_blight','Potato___healthy','Potato___Late_blight']
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def predict(img):
|
| 11 |
+
img_array = img.reshape(-1,256,256,3)
|
| 12 |
+
# img_array = tf.keras.preprocessing.image.img_to_array(img)
|
| 13 |
+
#img_array = tf.expand_dims(img_array, 0)
|
| 14 |
+
|
| 15 |
+
predictions = model.predict(img_array)
|
| 16 |
+
predicted_class = class_names[np.argmax(predictions[0])]
|
| 17 |
+
confidence = round(100 * (np.max(predictions[0])), 2)
|
| 18 |
+
return {class_names[i]: float(predictions[0][i]) for i in range(3)}
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
article = "<h3>How to Use:</h3> " \
|
| 22 |
+
"<ul><li>Click on the Upload button to upload an image,you can also drag the image to the upload box.</li> " \
|
| 23 |
+
"<li>Choose a Image from your computer</li>" \
|
| 24 |
+
"<li>Click on the 'Submit' button. <strong>Voila!</strong>. " \
|
| 25 |
+
"and labels will be displayed on screen.</li></ul>"
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# with gr.Blocks() as demo:
|
| 29 |
+
demo = gr.Interface(fn=predict,
|
| 30 |
+
inputs=[gr.Image(label="Upload an image",show_share_button=True,interactive=True,show_download_button=True)],
|
| 31 |
+
outputs=[gr.Label(num_top_classes=3,label="Predictions")],
|
| 32 |
+
title="Potato Disease Classification",
|
| 33 |
+
description="",
|
| 34 |
+
examples=['sample_images\potato_early_blight.JPG','sample_images\potato_healty.JPG','sample_images\potato_late_blight.JPG'],
|
| 35 |
+
allow_flagging="never",
|
| 36 |
+
article=article,
|
| 37 |
+
theme=gr.themes.Soft(),
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
demo.launch(debug=True,share=True)
|
| 41 |
+
|