ahmadalfian commited on
Commit
f00a6e8
1 Parent(s): b5bf504

Upload 3 files

Browse files
Files changed (3) hide show
  1. best.pt +3 -0
  2. main.py +58 -0
  3. requirements.txt +5 -0
best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:97f016ba6a0fede42dfe3cadc4b0c0fcead6646fa8136e3015f65ec3ab84f8ae
3
+ size 5621807
main.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ from PIL import Image, ImageDraw
4
+ from ultralytics import YOLO
5
+
6
+ # Muat model YOLO
7
+ model = YOLO('best.pt') # Pastikan path ini benar
8
+
9
+ # Fungsi untuk melakukan deteksi jerawat
10
+ def detect_acne(image):
11
+ # Convert image to NumPy array
12
+ img_np = np.array(image)
13
+
14
+ # Deteksi jerawat menggunakan model YOLO
15
+ results = model.predict(source=img_np, imgsz=640)
16
+
17
+ # Menggambar kotak deteksi di gambar asli
18
+ img_np_copy = img_np.copy() # Buat salinan gambar
19
+ img_pil = Image.fromarray(img_np_copy)
20
+ draw = ImageDraw.Draw(img_pil)
21
+
22
+ for result in results:
23
+ boxes = result.boxes
24
+ if boxes is not None and len(boxes.xyxy) > 0:
25
+ for i, box in enumerate(boxes.xyxy):
26
+ x1, y1, x2, y2 = box[:4]
27
+ conf = boxes.conf[i] if boxes.conf is not None and len(boxes.conf) > i else None
28
+
29
+ # Menggambar kotak di gambar asli dengan warna merah
30
+ draw.rectangle([(x1, y1), (x2, y2)], outline="red", width=2)
31
+
32
+ if conf is not None:
33
+ # Menambahkan label dengan confidence score
34
+ draw.text((x1, y1 - 10), f'{conf:.2f}', fill="red")
35
+
36
+ return img_pil
37
+
38
+ # Judul aplikasi
39
+ st.title('Deteksi Jerawat Menggunakan YOLOv8')
40
+
41
+ # Pilihan untuk mengunggah gambar
42
+ uploaded_file = st.file_uploader("Unggah Gambar", type=["jpg", "jpeg", "png"])
43
+
44
+ # Tampilkan gambar asli terlebih dahulu
45
+ if uploaded_file is not None:
46
+ # Membaca gambar
47
+ image = Image.open(uploaded_file)
48
+
49
+ # Tampilkan gambar asli
50
+ st.image(image, caption='Gambar yang Diupload', use_column_width=True)
51
+
52
+ # Tombol untuk melakukan deteksi jerawat
53
+ if st.button('Deteksi Jerawat'):
54
+ # Deteksi jerawat dalam gambar
55
+ detected_image = detect_acne(image)
56
+
57
+ # Tampilkan gambar hasil deteksi
58
+ st.image(detected_image, caption='Hasil Deteksi Jerawat', use_column_width=True)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit==1.39.0
2
+ opencv-python-headless==4.10.0.84
3
+ numpy==2.1.2
4
+ Pillow==10.4.0
5
+ ultralytics==8.3.8