Spaces:
Sleeping
Sleeping
Commit
·
70d0cfa
1
Parent(s):
7d764e2
added api endpoint for frontend app
Browse files
app.py
CHANGED
|
@@ -1,20 +1,25 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
-
from PIL import Image
|
| 4 |
|
| 5 |
# Load your model
|
| 6 |
model = pipeline("image-classification", model="wellCh4n/tomato-leaf-disease-classification-vit")
|
| 7 |
|
|
|
|
| 8 |
def classify(image):
|
| 9 |
if not isinstance(image, Image.Image):
|
| 10 |
-
image = Image.fromarray(image)
|
| 11 |
result = model(image)
|
| 12 |
-
return result[0]['label'] # return
|
| 13 |
|
| 14 |
-
|
|
|
|
| 15 |
fn=classify,
|
| 16 |
inputs=gr.Image(type="pil"),
|
| 17 |
outputs="label",
|
| 18 |
title="Tomato Leaf Disease Analyzer",
|
| 19 |
description="Upload a tomato leaf image to detect the disease."
|
| 20 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
+
from PIL import Image
|
| 4 |
|
| 5 |
# Load your model
|
| 6 |
model = pipeline("image-classification", model="wellCh4n/tomato-leaf-disease-classification-vit")
|
| 7 |
|
| 8 |
+
# Define the prediction function
|
| 9 |
def classify(image):
|
| 10 |
if not isinstance(image, Image.Image):
|
| 11 |
+
image = Image.fromarray(image)
|
| 12 |
result = model(image)
|
| 13 |
+
return result[0]['label'] # You can also return full result if you want scores
|
| 14 |
|
| 15 |
+
# Define the interface
|
| 16 |
+
app = gr.Interface(
|
| 17 |
fn=classify,
|
| 18 |
inputs=gr.Image(type="pil"),
|
| 19 |
outputs="label",
|
| 20 |
title="Tomato Leaf Disease Analyzer",
|
| 21 |
description="Upload a tomato leaf image to detect the disease."
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# 🚀 Enable both UI and API
|
| 25 |
+
app.launch(show_api=True)
|