nehulagrawal's picture
Update app.py
2052695
raw
history blame
No virus
2.13 kB
import gradio as gr
from detection import ObjectDetection
examples = [
['test-images/plant1.jpeg', 0.23],
['test-images/plant2.jpeg', 0.45],
['test-images/plant3.webp', 0.43],
]
def get_predictions(img, threshold, box_color, text_color):
v8_results = yolov8_detector.v8_score_frame(img)
v8_frame = yolov8_detector.plot_bboxes(v8_results, img, float(threshold), box_color, text_color)
return v8_frame
# Load the YOLOv8s model for plant leaf detection and classification
yolov8_detector = ObjectDetection('Yolov8')
with gr.Blocks(title="Plant Leaf Detection and Classification", theme=gr.themes.Soft()) as interface:
gr.Markdown("# Plant Leaf Detection and Classification🍃")
gr.Markdown("This app uses YOLOv8s, a powerful object detection model, to detect and classify plant leaves. "
"The model can detect various plant leaves and classify them into up to 45 different plant categories, "
"whether the leafs are diseased or healthy.")
gr.Markdown("If you like this app, don't forget to give it a thumbs up on Hugging Face!😊❤️@ www.Foduu.com")
with gr.Row():
with gr.Column():
image = gr.Image(label="Input Image")
with gr.Column():
with gr.Row():
with gr.Column():
box_color = gr.ColorPicker(label="Box Color", value="#FF8C00")
with gr.Column():
text_color = gr.ColorPicker(label="Prediction Color", value="#000000")
confidence = gr.Slider(maximum=1, step=0.01, value=0.6, label="Confidence Threshold", interactive=True)
btn = gr.Button("Detect")
with gr.Row():
with gr.Box():
v8_prediction = gr.Image(label="Leaf Detection and Classification",height=100,width=100) # Display the output image in its original size
btn.click(
get_predictions,
[image, confidence, box_color, text_color],
[v8_prediction]
)
with gr.Row():
gr.Examples(examples=examples, inputs=[image, confidence])
interface.launch()