Spaces:
Runtime error
Runtime error
Commit
Β·
dea7ada
1
Parent(s):
88eaa86
Update app.py
Browse files
app.py
CHANGED
@@ -1,51 +1,67 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
gr.Markdown("This app uses YOLOv8s, a powerful object detection model, to detect and classify plant leaves. "
|
21 |
-
"The model can detect various plant leaves and classify them into up to 45 different plant categories, "
|
22 |
-
"whether the leafs are diseased or healthy.")
|
23 |
-
gr.Markdown("If you like this app, don't forget to give it a thumbs up on Hugging Face!πβ€οΈ@ www.Foduu.com")
|
24 |
|
25 |
-
|
26 |
-
with gr.Column():
|
27 |
-
image = gr.Image(label="Input Image")
|
28 |
-
with gr.Column():
|
29 |
-
with gr.Row():
|
30 |
-
with gr.Column():
|
31 |
-
box_color = gr.ColorPicker(label="Box Color", value="#FF8C00")
|
32 |
-
with gr.Column():
|
33 |
-
text_color = gr.ColorPicker(label="Prediction Color", value="#000000")
|
34 |
|
35 |
-
|
36 |
-
btn = gr.Button("Detect")
|
37 |
-
|
38 |
-
with gr.Row():
|
39 |
-
with gr.Box():
|
40 |
-
v8_prediction = gr.Image(label="Leaf Detection and Classification",height=100,width=100) # Display the output image in its original size
|
41 |
|
42 |
-
|
43 |
-
get_predictions,
|
44 |
-
[image, confidence, box_color, text_color],
|
45 |
-
[v8_prediction]
|
46 |
-
)
|
47 |
-
|
48 |
-
with gr.Row():
|
49 |
-
gr.Examples(examples=examples, inputs=[image, confidence])
|
50 |
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from sahi.prediction import ObjectPrediction
|
4 |
+
from sahi.utils.cv import visualize_object_predictions, read_image
|
5 |
+
from ultralyticsplus import YOLO, render_result
|
6 |
|
7 |
+
def yolov8_inference(
|
8 |
+
image: gr.inputs.Image = None,
|
9 |
+
model_path: gr.inputs.Dropdown = None,
|
10 |
+
image_size: gr.inputs.Slider = 640,
|
11 |
+
conf_threshold: gr.inputs.Slider = 0.25,
|
12 |
+
iou_threshold: gr.inputs.Slider = 0.45,
|
13 |
+
):
|
14 |
+
"""
|
15 |
+
YOLOv8 inference function
|
16 |
+
Args:
|
17 |
+
image: Input image
|
18 |
+
model_path: Path to the model
|
19 |
+
image_size: Image size
|
20 |
+
conf_threshold: Confidence threshold
|
21 |
+
iou_threshold: IOU threshold
|
22 |
+
Returns:
|
23 |
+
Rendered image
|
24 |
+
"""
|
25 |
+
model = YOLO(model_path)
|
26 |
+
model.overrides['conf'] = conf_threshold
|
27 |
+
model.overrides['iou']= iou_threshold
|
28 |
+
model.overrides['agnostic_nms'] = False # NMS class-agnostic
|
29 |
+
model.overrides['max_det'] = 1000
|
30 |
+
image = read_image(image)
|
31 |
+
results = model.predict(image)
|
32 |
+
render = render_result(model=model, image=image, result=results[0])
|
33 |
+
|
34 |
+
return render
|
35 |
+
|
36 |
|
37 |
+
inputs = [
|
38 |
+
gr.inputs.Image(type="filepath", label="Input Image"),
|
39 |
+
gr.inputs.Dropdown(["foduucom/plant-leaf-detection-and-classification"],
|
40 |
+
default="foduucom/plant-leaf-detection-and-classification", label="Model"),
|
41 |
+
gr.inputs.Slider(minimum=320, maximum=1280, default=640, step=32, label="Image Size"),
|
42 |
+
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.25, step=0.05, label="Confidence Threshold"),
|
43 |
+
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.45, step=0.05, label="IOU Threshold"),
|
44 |
+
]
|
45 |
|
46 |
+
outputs = gr.outputs.Image(type="filepath", label="Output Image")
|
47 |
+
title = "Leafify: Advanced Plant Leaf Detection and Classification"
|
|
|
|
|
|
|
|
|
48 |
|
49 |
+
description = """Unleash the botanical detective in you with Leafify, powered by the incredible Foduu AI model! π±π¬ Detecting over 45 plant varieties (and counting!), Leafify turns leaf identification into an exciting adventure.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
+
Curious about our secret sauce? The Foduu AI model is like a plant whisperer β it can spot and name plants like a pro. For the juicy deets, swing by the Foduu model page β it's where the AI magic happens!
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
+
Oh, but the excitement doesn't stop there. We're plant enthusiasts, just like you! If you're craving even more plant pals in the AI family, or you're thinking, 'Hey, my plants deserve to be famous too!' β drop us a line at [email protected]. We're all ears, leaves, and stems!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
+
And, hey, if you heart the universe as much as we do, show some love! Just hit that little heart button β because every time you do, a virtual garden blooms. πΌπ§‘ Let's get leafy!"""
|
56 |
+
examples = [['test-images/plant1.jpeg', 'foduucom/plant-leaf-detection-and-classification', 640, 0.25, 0.45], ['test-images/plant2.jpeg', 'foduucom/plant-leaf-detection-and-classification', 640, 0.25, 0.45], ['test-images/plant3.webp', 'foduucom/plant-leaf-detection-and-classification', 1280, 0.25, 0.45]]
|
57 |
+
demo_app = gr.Interface(
|
58 |
+
fn=yolov8_inference,
|
59 |
+
inputs=inputs,
|
60 |
+
outputs=outputs,
|
61 |
+
title=title,
|
62 |
+
description=description,
|
63 |
+
examples=examples,
|
64 |
+
cache_examples=True,
|
65 |
+
theme='huggingface',
|
66 |
+
)
|
67 |
+
demo_app.launch(debug=True, enable_queue=True)
|