Mtemel commited on
Commit
612a2c0
·
verified ·
1 Parent(s): 5f641fa

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import cv2
3
+ import numpy as np
4
+ import gradio as gr
5
+ from ultralytics import YOLO
6
+ from PIL import Image
7
+ from huggingface_hub import hf_hub_download
8
+
9
+ # Hugging Face'ten YOLO modelini indir
10
+ model_path = hf_hub_download("keremberke/yolov8n-pcb-defect-segmentation", "best.pt")
11
+
12
+ # Modeli yükle
13
+ model = YOLO(model_path)
14
+
15
+ def detect_defects(image):
16
+ results = model.predict(image, save=False)
17
+ annotated_image = results[0].plot() # Tahmin sonuçlarını çiz
18
+ return annotated_image
19
+
20
+ iface = gr.Interface(
21
+ fn=detect_defects,
22
+ inputs=gr.Image(type="pil"),
23
+ outputs=gr.Image(type="pil"),
24
+ title="PCB Defect Segmentation"
25
+ )
26
+
27
+ iface.launch()