| import gradio as gr |
| import tensorflow as tf |
| from tensorflow.keras.models import load_model |
| import numpy as np |
| from tensorflow.keras.preprocessing import image |
|
|
| |
| model_keenam = load_model('hasil_model.h5') |
|
|
| |
| def predict_image(img): |
| |
| img = img.resize((128, 128)) |
| |
| |
| img_array = np.array(img) / 255.0 |
| |
| |
| img_array = np.expand_dims(img_array, axis=0) |
| |
| |
| predictions = model_keenam.predict(img_array) |
| |
| |
| class_names = ['Cardboard','Food Organics','Glass','Metal','Miscellaneous Trash','Paper','Plastic','Textile Trash','Vegetation'] |
| predicted_class = class_names[np.argmax(predictions)] |
| |
| return predicted_class, np.max(predictions) |
|
|
| |
| iface = gr.Interface( |
| fn=predict_image, |
| inputs=gr.Image(type='pil'), |
| outputs=[gr.Label(num_top_classes=1), gr.Textbox()], |
| live=True, |
| title="Prediksi Klasifikasi Sampah", |
| description="Upload gambar sampah untuk mendapatkan prediksi klasifikasi berdasarkan model." |
| ) |
|
|
| |
| iface.launch() |