saritha commited on
Commit
8e08196
·
verified ·
1 Parent(s): c9db949

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -6
app.py CHANGED
@@ -40,9 +40,9 @@ transform = transforms.Compose([
40
  class_names = ['BacterialBlights', 'Healthy', 'Mosaic', 'RedRot', 'Rust', 'Yellow']
41
 
42
  # Function to predict disease type from an image
43
- def predict_disease(image_path):
44
  # Open the image file
45
- img = Image.open(image_path)
46
 
47
  # Apply transformations to the image
48
  img_tensor = transform(img).unsqueeze(0) # Add batch dimension
@@ -57,7 +57,21 @@ def predict_disease(image_path):
57
 
58
  return predicted_label
59
 
60
- # Test with a new image
61
- image_path = 'img1.png' # Replace with your image path
62
- predicted_label = predict_disease(image_path)
63
- print(f'The predicted disease type is: {predicted_label}')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  class_names = ['BacterialBlights', 'Healthy', 'Mosaic', 'RedRot', 'Rust', 'Yellow']
41
 
42
  # Function to predict disease type from an image
43
+ def predict_disease(image):
44
  # Open the image file
45
+ img = Image.open(image)
46
 
47
  # Apply transformations to the image
48
  img_tensor = transform(img).unsqueeze(0) # Add batch dimension
 
57
 
58
  return predicted_label
59
 
60
+ # Gradio interface
61
+ inputs = gr.inputs.Image(type="pil")
62
+ outputs = gr.outputs.Text()
63
+
64
+ EXAMPLES = ["img1.png"]
65
+
66
+ demo_app = gr.Interface(
67
+ fn=predict_disease,
68
+ inputs=inputs,
69
+ outputs=outputs,
70
+ title="Sugarcane Disease Prediction with ViT",
71
+ examples=EXAMPLES,
72
+ live=True,
73
+ theme="huggingface"
74
+ )
75
+
76
+ demo_app.launch(debug=True, enable_queue=True)
77
+