File size: 976 Bytes
81c9545
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import numpy as np
from PIL import Image
import tensorflow as tf

# Load the model
model = tf.keras.models.load_model("powerline_model.keras")

# Class mapping
label_map = {0: "Damaged", 1: "Good", 2: "No Power Line"}

# Prediction function
def classify_image(img: Image.Image):
    img_resized = img.resize((224, 224))
    img_array = np.array(img_resized) / 255.0
    img_array = np.expand_dims(img_array, axis=0)
    
    prediction = model.predict(img_array)
    label_index = np.argmax(prediction)
    label = label_map[label_index]

    return img, label

# Gradio interface
interface = gr.Interface(
    fn=classify_image,
    inputs=gr.Image(type="pil"),
    outputs=[gr.Image(type="pil"), gr.Label()],
    title="Power Line Condition Classifier",
    description="Upload a photo of a power line to detect whether it's Good, Damaged, or has No Line."
)

# Launch the app
interface.launch(share=True, debug=True)