NKASG commited on
Commit
74c59ff
·
verified ·
1 Parent(s): 7f22d93

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -14
app.py CHANGED
@@ -1,21 +1,27 @@
1
- import tensorflow as tf
2
- import requests
3
  import gradio as gr
 
 
4
 
5
- inception_net = tf.keras.applications.MobileNetV2()
6
- response = requests.get("https://git.io/JJkYN")
7
- labels = response.text.split("\n")
8
 
9
- def classify_image(inp):
10
- inp = inp.reshape((-1, 224, 224, 3))
11
- inp = tf.keras.applications.mobilenet_v2.preprocess_input(inp)
12
- prediction = inception_net.predict(inp).flatten()
13
- confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
 
 
 
 
14
  return confidences
15
 
16
- demo = gr.Interface(fn=classify_image,
17
- inputs=gr.Image(type="pil"),
18
- outputs=gr.Label(num_top_classes=3),
19
- )
 
 
 
 
20
 
21
  demo.launch()
 
1
+ import tf_keras as keras
 
2
  import gradio as gr
3
+ import cv2
4
+ import os
5
 
 
 
 
6
 
7
+ print(os.listdir('./model'))
8
+ used_model = keras.models.load_model('./model')
9
+ new_classes = ['Potato___Early_blight', 'Potato___Late_blight', 'Potato___healthy']
10
+
11
+ def classify_image(img_dt):
12
+ img_dt = cv2.resize(img_dt,(256,256))
13
+ img_dt = img_dt.reshape((-1,256,256,3))
14
+ prediction = used_model.predict(img_dt).flatten()
15
+ confidences = {new_classes[i]: float(prediction[i]) for i in range (4) }
16
  return confidences
17
 
18
+
19
+ with gr.Blocks() as demo:
20
+ signal = gr.Markdown(''' Welcome to Maize Classifier,This model can identify if a leaf is
21
+ **HEALTHY**, has **'Potato___Early_blight'** or **Potato_late___blight**''')
22
+ with gr.Row():
23
+ inp = gr.Image()
24
+ out = gr.Label()
25
+ inp.upload(fn= classify_image, inputs = inp, outputs = out)
26
 
27
  demo.launch()