Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import numpy as np | |
| from PIL import Image | |
| import tensorflow as tf | |
| model = tf.keras.models.load_model("Educell_Garbage.keras", compile=False) | |
| class_names = ['cardboard', 'glass', 'metal', 'paper', 'plastic', 'trash'] | |
| def classify_image(img): | |
| img = img.resize((124, 124)) | |
| img_array = np.array(img, dtype=np.float32) | |
| img_array = np.expand_dims(img_array, axis=0) | |
| prediction = model.predict(img_array)[0] | |
| predicted_class = class_names[np.argmax(prediction)] | |
| confidence = float(np.max(prediction)) * 100 | |
| return f"📁 **Predicted Class:** `{predicted_class.upper()}`\n🎯 **Confidence:** `{confidence:.2f}%`" | |
| # Dark mode CSS | |
| custom_css = """ | |
| body, .gradio-container { | |
| background-color: #1f1f1f !important; | |
| color: #f2f2f2 !important; | |
| font-family: 'Segoe UI', sans-serif; | |
| } | |
| #output_textbox { | |
| background-color: #2b2b2b !important; | |
| color: #ffffff !important; | |
| padding: 20px; | |
| border-radius: 12px; | |
| box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3); | |
| font-size: 18px; | |
| font-weight: 500; | |
| } | |
| h1, .gr-markdown { | |
| text-align: center; | |
| color: #00ffcc !important; | |
| } | |
| """ | |
| # Interface layout | |
| with gr.Blocks(css=custom_css) as demo: | |
| gr.Markdown("## ♻️ Garbage Classification AI") | |
| gr.Markdown("Upload an image of waste and the AI will classify it as **Plastic**, **Glass**, **Paper**, etc.") | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| image_input = gr.Image(label="Upload Image", type="pil", height=300) | |
| submit_btn = gr.Button("🔍 Classify", size="lg") | |
| with gr.Column(scale=1): | |
| prediction_output = gr.Markdown(elem_id="output_textbox", show_label=False) | |
| submit_btn.click(fn=classify_image, inputs=image_input, outputs=prediction_output) | |
| gr.Markdown("---") | |
| gr.Markdown("Made with ❤️ for smart waste segregation") | |
| if __name__ == "__main__": | |
| demo.launch(share=True) | |