Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
from model import predict
|
| 4 |
+
|
| 5 |
+
def predict_crop(image, crop_name):
|
| 6 |
+
if image is None or not crop_name:
|
| 7 |
+
return {"error": "Image and crop_name are required"}
|
| 8 |
+
|
| 9 |
+
prediction, confidence = predict(image, crop_name)
|
| 10 |
+
|
| 11 |
+
return {
|
| 12 |
+
"prediction": prediction,
|
| 13 |
+
"confidence": confidence
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
gr.Interface(
|
| 17 |
+
fn=predict_crop,
|
| 18 |
+
inputs=[
|
| 19 |
+
gr.Image(type="pil"),
|
| 20 |
+
gr.Textbox(label="Crop Name (banana, tomato, rice)")
|
| 21 |
+
],
|
| 22 |
+
outputs="json",
|
| 23 |
+
api_name="/predict_crop",
|
| 24 |
+
title="LeafBuddy Crop Disease Detection"
|
| 25 |
+
).launch()
|