Spaces:
Runtime error
Runtime error
File size: 1,164 Bytes
c82d9a3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | import gradio as gr
import tensorflow as tf
import numpy as np
from PIL import Image
import json
# --- Load metadata (class names) ---
with open("metadata.json") as f:
metadata = json.load(f)
labels = metadata["labels"]
# --- Load Teachable Machine TensorFlow.js model ---
import tensorflowjs as tfjs
print("Loading model...")
model = tfjs.converters.load_keras_model("model.json")
print("✅ Model loaded successfully!")
# --- Prediction function ---
def predict_image(img):
img = img.resize((224, 224))
img = np.array(img) / 255.0
img = np.expand_dims(img, axis=0)
preds = model.predict(img)[0]
confidences = {labels[i]: float(preds[i]) for i in range(len(labels))}
return confidences
# --- Gradio Web Interface ---
demo = gr.Interface(
fn=predict_image,
inputs=gr.Image(type="pil", label="Upload Solar Panel Image"),
outputs=gr.Label(num_top_classes=3, label="Predictions"),
title="🔆 Solar Panel Condition Classifier",
description="Upload an image to check if the solar panel is Clean, Dusty, Bird-drop, Electrical Damage, Physical Damage, or Snow-Covered."
)
if __name__ == "__main__":
demo.launch()
|