Team8848/Automobile-Image-Analysis-DeepLearning-Model
0
1import gradio as gr2import torch3from ultralyticsplus import YOLO, render_result4 5 6# torch.hub.download_url_to_file(7# 'https://mattpearsonaviation.com/wp-content/uploads/2017/12/IMG_0560.jpg', 'one.jpg')8# # torch.hub.download_url_to_file(9# # 'https://cdn.airplane-pictures.net/images/uploaded-images/2011/11/25/169465.jpg', 'two.jpg')10# torch.hub.download_url_to_file(11# 'https://imgproc.airliners.net/photos/airliners/7/1/9/0767917.jpg?v=v40', 'three.jpg')12 13 14def yoloV12_func(image: gr.Image = None,15 image_size: gr.Slider = 640,16 conf_threshold: gr.Slider = 0.4,17 iou_threshold: gr.Slider = 0.50):18 """This function performs YOLOv12 object detection on the given image.19 20 Args:21 image (gr.inputs.Image, optional): Input image to detect objects on. Defaults to None.22 image_size (gr.inputs.Slider, optional): Desired image size for the model. Defaults to 640.23 conf_threshold (gr.inputs.Slider, optional): Confidence threshold for object detection. Defaults to 0.4.24 iou_threshold (gr.inputs.Slider, optional): Intersection over Union threshold for object detection. Defaults to 0.50.25 """26 # Trained dataset27 model_path = "best.pt"28 model = YOLO(model_path)29 30 31 results = model.predict(image,32 conf=conf_threshold,33 iou=iou_threshold,34 imgsz=image_size)35 36 37 box = results[0].boxes38 print("Object type:", box.cls)39 print("Coordinates:", box.xyxy)40 print("Probability:", box.conf)41 42 43 render = render_result(model=model, image=image, result=results[0])44 return render45 46 47inputs = [48 gr.Image(type="filepath", label="Output Image"),49 gr.Slider(minimum=320, maximum=1280, value=640,50 step=32, label="Image Size"),51 gr.Slider(minimum=0.0, maximum=1.0, value=0.25,52 step=0.05, label="Confidence Threshold"),53 gr.Slider(minimum=0.0, maximum=1.0, value=0.45,54 step=0.05, label="IOU Threshold"),55]56 57 58outputs = gr.Image(type="filepath", label="Input Image")59 60title = "π¨βπ»Made By Team 8848(TataSafeguard)π¨βπ»: Aircraft Damage Detection leveraging advanced IOT integration features."61 62# examples = [['one.jpg', 640, 0.5, 0.7],63# ['two.jpg', 800, 0.5, 0.6],64# ['three.jpg', 900, 0.5, 0.8]]65 66yolo_app = gr.Interface(67 fn=yoloV12_func,68 inputs=inputs,69 outputs=outputs,70 title=title,71 # examples=examples,72 # cache_examples=True,73)74 75# Launching Gradio interface 76yolo_app.launch(share=True, debug=True)77 78 79 