HARSH CHAUDHARY commited on
Commit ·
89e6e5f
1
Parent(s): 3377a25
first up load
Browse files- app.py +39 -0
- m32.h5 +3 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
from tensorflow.keras.models import load_model
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
# Load the trained model
|
| 7 |
+
model = load_model("m32.h5")
|
| 8 |
+
|
| 9 |
+
# Class labels
|
| 10 |
+
class_labels = [
|
| 11 |
+
'Cell', 'Cell-Multi', 'Cracking', 'Diode', 'Diode-Multi',
|
| 12 |
+
'Hot-Spot', 'Hot-Spot-Multi', 'No-Anomaly', 'Offline-Module',
|
| 13 |
+
'Shadowing', 'Soiling', 'Vegetation'
|
| 14 |
+
]
|
| 15 |
+
|
| 16 |
+
# Preprocessing and prediction function
|
| 17 |
+
def predict_image(img: Image.Image):
|
| 18 |
+
img = img.convert("RGB")
|
| 19 |
+
img = img.resize((24, 40)) # Resize to (width=24, height=40)
|
| 20 |
+
img_array = np.array(img)
|
| 21 |
+
img_input = img_array.reshape(1, 40, 24, 3)
|
| 22 |
+
|
| 23 |
+
prediction = model.predict(img_input)
|
| 24 |
+
max_prob = np.max(prediction[0])
|
| 25 |
+
class_ind = np.argmax(prediction[0])
|
| 26 |
+
predicted_class = class_labels[class_ind]
|
| 27 |
+
|
| 28 |
+
return f"Predicted class: {predicted_class} with probability {max_prob:.4f}"
|
| 29 |
+
|
| 30 |
+
# Gradio interface
|
| 31 |
+
interface = gr.Interface(
|
| 32 |
+
fn=predict_image,
|
| 33 |
+
inputs=gr.Image(type="pil"),
|
| 34 |
+
outputs="text",
|
| 35 |
+
title="Solar Module Anomaly Classifier",
|
| 36 |
+
description="Upload an infrared image to detect anomalies in solar modules."
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
interface.launch()
|
m32.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8568c8ecc5dbc2769b27b627fcba40981107ab70520ffb395590f2e7256209f2
|
| 3 |
+
size 22104488
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
tensorflow
|
| 3 |
+
Pillow
|
| 4 |
+
numpy
|