pratham2025's picture
v1
38bd503 verified
Raw History Blame Contribute Delete
1.07 kB
import gradio as gr
import cv2
from ultralytics import YOLO
# 1. Load the model (Notice the path is just 'best.pt' now!)
model = YOLO('best.pt')
# 2. Define the prediction function
def predict_insulator(img):
if img is None:
return None
results = model.predict(source=img, conf=0.25)
result = results[0]
annotated_img = result.plot()
annotated_img_rgb = cv2.cvtColor(annotated_img, cv2.COLOR_BGR2RGB)
return annotated_img_rgb
# 3. Build the Interface
demo = gr.Interface(
fn=predict_insulator,
inputs=gr.Image(type="numpy", label="Upload Insulator Image"),
outputs=gr.Image(type="numpy", label="AI Detection Results"),
title="⚡ Power Line Insulator Defect Detector",
description="Upload an image of an electrical transmission insulator. The AI will detect if the insulator has **No issues**, is **Broken**, or has **Flashover damage**.",
theme="default"
)
# 4. Launch (Hugging Face handles the sharing automatically)
if __name__ == "__main__":
demo.launch()