|
|
import gradio as gr |
|
|
import cv2 |
|
|
import torch |
|
|
from PIL import Image |
|
|
import numpy as np |
|
|
|
|
|
|
|
|
|
|
|
model = torch.hub.load('ultralytics/yolov5', 'yolov5s') |
|
|
|
|
|
|
|
|
def detect_objects(image): |
|
|
|
|
|
image = np.array(image) |
|
|
|
|
|
|
|
|
results = model(image) |
|
|
|
|
|
|
|
|
results_image = results.render()[0] |
|
|
|
|
|
return Image.fromarray(results_image) |
|
|
|
|
|
|
|
|
def gradio_interface(): |
|
|
with gr.Blocks() as demo: |
|
|
|
|
|
gr.Markdown( |
|
|
""" |
|
|
<center> |
|
|
<h2>Fermentation Level Classification for Cocoa Beans</h2> |
|
|
</center> |
|
|
""" |
|
|
) |
|
|
|
|
|
|
|
|
gr.Markdown( |
|
|
""" |
|
|
<center> |
|
|
<a href="https://github.com/kebincontreras/cocoa_beans_interfaces" target="_blank" style="text-decoration: none;"> |
|
|
<button style="background-color: #007bff; color: white; padding: 10px 20px; border: none; border-radius: 5px; font-size: 16px;">GitHub</button> |
|
|
</a> |
|
|
</center> |
|
|
""" |
|
|
) |
|
|
|
|
|
|
|
|
with gr.Row(): |
|
|
img_input = gr.Image(label="Upload Image") |
|
|
img_output = gr.Image(label="Image with Detected Objects") |
|
|
|
|
|
|
|
|
btn_detect_upload = gr.Button("Classify Fermentation Level") |
|
|
|
|
|
|
|
|
btn_detect_upload.click(detect_objects, inputs=img_input, outputs=img_output) |
|
|
|
|
|
return demo |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo = gradio_interface() |
|
|
demo.launch() |
|
|
|