Spaces:
Runtime error
Runtime error
nurindahpratiwi
commited on
Commit
•
fcd94fc
1
Parent(s):
954f0b4
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Import library yang dibutuhkan
|
2 |
+
import streamlit as st
|
3 |
+
from transformers import pipeline
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
''' Buat variabel pipeline yang berisi fungsi pipeline dari library transformers
|
7 |
+
Model yang digunakan, merupakan model leaf disease yang telah ditentukan/dicari dari huggingface
|
8 |
+
'''
|
9 |
+
|
10 |
+
pipeline = pipeline(task='image-classification', model='Bazaar/cv_apple_leaf_disease_detection')
|
11 |
+
|
12 |
+
# Buat judul pada web menggunakan st.title
|
13 |
+
st.title("Leaf Disease Detection")
|
14 |
+
|
15 |
+
# Buat button yang meminta user menggunggah gambar daun
|
16 |
+
file_name = st.file_uploader("Upload a leaf candidate image")
|
17 |
+
|
18 |
+
# Cek apakah file_name tidak None, jika True jalankan perintah di bawah
|
19 |
+
if file_name is not None:
|
20 |
+
col1, col2 = st.columns(2) # buat 2 kolom
|
21 |
+
|
22 |
+
image = Image.open(file_name) # Buka file image yang sudah diupload
|
23 |
+
col1.image(image, use_column_width=True) # Menampilkan image di kolom 1
|
24 |
+
predictions = pipeline(image) # Lakukan prediksi input image
|
25 |
+
|
26 |
+
col2.header("Confidence score") # Menampilkan judul di kolom 2
|
27 |
+
for p in predictions:
|
28 |
+
col2.subheader(f"{p['label']}: {round(p['score']*100,1)}%") # Menampilkan angka (dalam persen) confidence score
|