Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from ultralytics import YOLO | |
| from PIL import Image | |
| import cv2 | |
| import numpy as np | |
| # Model load karein | |
| model = YOLO("best.pt") | |
| def predict_image(img): | |
| if img is None: | |
| return None | |
| # Model prediction | |
| results = model(img, conf=0.2) | |
| # Annotated image (BGR colors) | |
| res_plotted = results[0].plot() | |
| # RGB Conversion (Blue skin fix) | |
| res_rgb = cv2.cvtColor(res_plotted, cv2.COLOR_BGR2RGB) | |
| return Image.fromarray(res_rgb) | |
| # Gradio interface setup (Gradio 5/6 syntax) | |
| demo = gr.Interface( | |
| fn=predict_image, | |
| # 'source' ko remove kar diya hai, 'type' numpy rakha hai | |
| inputs=gr.Image(type="numpy", label="Live Webcam Feed"), | |
| outputs=gr.Image(type="pil", label="Result"), | |
| title="Face Mask Detection (YOLOv8)", | |
| description="Webcam icon par click karein ya photo upload karein." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |