Spaces:
Sleeping
Sleeping
import streamlit as st | |
import os | |
os.environ['CUDA_VISIBLE_DEVICES'] = '-1' | |
import tensorflow as tf | |
if tf.test.gpu_device_name(): | |
print('GPU found') | |
else: | |
print("No GPU found") | |
from keras.preprocessing import image as ig | |
import numpy as np | |
from PIL import Image | |
st.title("Klasfisikasi Batu Kertas Gunting") | |
st.caption("Untuk data bisa di download disini") | |
st.link_button("Link Berikut", "https://www.kaggle.com/datasets/drgfreeman/rockpaperscissors/download?datasetVersionNumber=2") | |
model_saved = tf.keras.models.load_model('model_cnn_final.h5') | |
labels = ['paper','scissors','rock'] | |
nb = len(labels) | |
def run_data(image): | |
img_tensor = tf.convert_to_tensor(image) | |
size = (150, 150) | |
ds = tf.image.resize(img_tensor, size) | |
x = ig.img_to_array(ds) | |
x = np.expand_dims(x, axis = 0) | |
images = np.vstack([x]) | |
classes = model_saved(images) | |
for j in range(nb): | |
if classes[0][j] == 1. : | |
st.write('Gambar Berikut termasuk Class', labels[j]) | |
break | |
st.write("Silahkan upload gambar disini") | |
file = st.file_uploader("upload gambar Saja", type=["png", "jpg", "jpeg"]) | |
image = [] | |
if file is not None: | |
image = Image.open(file) | |
st.image( | |
image, | |
caption=f"Berhasil upload gambar", | |
use_column_width=True, | |
) | |
image = np.array(image) | |
if st.button('Tampilkan Hasil Klasifikasi'): | |
run_data(image) | |