Unmukt commited on
Commit
8ae7339
·
1 Parent(s): cd64de2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import gradio as gr
2
  import numpy as np
3
 
@@ -6,7 +7,9 @@ import tensorflow as tf
6
  from tensorflow import keras
7
  from tensorflow.keras import layers
8
  from tensorflow.keras.models import Sequential
9
- data_dir = "D:\\New Plant Diseases Dataset(Augmented)\\train"
 
 
10
  img_height,img_width=180,180
11
  batch_size=32
12
  train_ds = tf.keras.preprocessing.image_dataset_from_directory(
@@ -23,9 +26,6 @@ val_ds = tf.keras.preprocessing.image_dataset_from_directory(
23
  seed=123,
24
  image_size=(img_height, img_width),
25
  batch_size=batch_size)
26
- class_names = train_ds.class_names
27
- print(class_names)
28
-
29
  num_classes = 38
30
 
31
  model = Sequential([
@@ -50,8 +50,10 @@ history = model.fit(
50
  epochs=epochs
51
  )
52
  def predict_image(img):
53
- img_4d=img.reshape(-1,180,180,3)
54
- prediction=model.predict(img_4d)[0]
55
- return {class_names[i]: float(prediction[i]) for i in range(38)
 
 
56
 
57
- gr.Interface(fn=predict_image, inputs=gr.inputs.Image(shape=(180,180)), outputs=gr.outputs.Label(num_top_classes=5),interpretation='default').launch(share = 'True', debug='True')
 
1
+ !pip install gradio
2
  import gradio as gr
3
  import numpy as np
4
 
 
7
  from tensorflow import keras
8
  from tensorflow.keras import layers
9
  from tensorflow.keras.models import Sequential
10
+ from google.colab import drive
11
+ drive.mount('/content/drive')
12
+ data_dir = "/content/drive/MyDrive/Colab Notebooks/valid"
13
  img_height,img_width=180,180
14
  batch_size=32
15
  train_ds = tf.keras.preprocessing.image_dataset_from_directory(
 
26
  seed=123,
27
  image_size=(img_height, img_width),
28
  batch_size=batch_size)
 
 
 
29
  num_classes = 38
30
 
31
  model = Sequential([
 
50
  epochs=epochs
51
  )
52
  def predict_image(img):
53
+ img_4d=img.reshape(-1,180,180,3)
54
+ prediction=model.predict(img_4d)[0]
55
+ return {class_names[i]: float(prediction[i]) for i in range(5)}
56
+ image = gr.inputs.Image(shape=(180,180))
57
+ label = gr.outputs.Label(num_top_classes=5)
58
 
59
+ gr.Interface(fn=predict_image, inputs=image, outputs=label,interpretation='default').launch(share = 'True',debug='True')