Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -41,11 +41,8 @@ class_names = ['BacterialBlights', 'Healthy', 'Mosaic', 'RedRot', 'Rust', 'Yello
|
|
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(
|
49 |
|
50 |
# Make prediction
|
51 |
with torch.no_grad():
|
@@ -57,21 +54,23 @@ def predict_disease(image):
|
|
57 |
|
58 |
return predicted_label
|
59 |
|
60 |
-
# Gradio interface
|
61 |
-
inputs = gr.
|
62 |
-
outputs = gr.
|
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
|
71 |
examples=EXAMPLES,
|
|
|
72 |
live=True,
|
73 |
theme="huggingface"
|
74 |
)
|
75 |
|
76 |
demo_app.launch(debug=True, enable_queue=True)
|
77 |
|
|
|
|
41 |
|
42 |
# Function to predict disease type from an image
|
43 |
def predict_disease(image):
|
|
|
|
|
|
|
44 |
# Apply transformations to the image
|
45 |
+
img_tensor = transform(image).unsqueeze(0) # Add batch dimension
|
46 |
|
47 |
# Make prediction
|
48 |
with torch.no_grad():
|
|
|
54 |
|
55 |
return predicted_label
|
56 |
|
57 |
+
# Create Gradio interface
|
58 |
+
inputs = gr.Image(type="pil")
|
59 |
+
outputs = gr.Text()
|
60 |
|
61 |
+
EXAMPLES = ["img1.png", "img2.png", "img3.png", "img4.png"]
|
62 |
|
63 |
demo_app = gr.Interface(
|
64 |
+
fn=predict_disease,
|
65 |
inputs=inputs,
|
66 |
outputs=outputs,
|
67 |
+
title="Sugarcane Disease Detection",
|
68 |
examples=EXAMPLES,
|
69 |
+
cache_example=True,
|
70 |
live=True,
|
71 |
theme="huggingface"
|
72 |
)
|
73 |
|
74 |
demo_app.launch(debug=True, enable_queue=True)
|
75 |
|
76 |
+
|