Download app.py from CBird25/Ldawg: direct link, hf CLI and curl.
- Browser
- Download file 976 Bytes
-
https://huggingface.co/spaces/CBird25/Ldawg/resolve/main/app.py
- Command line
-
hf download hf://spaces/CBird25/Ldawg/app.py
-
curl -L -o app.py https://huggingface.co/spaces/CBird25/Ldawg/resolve/main/app.py
976 Bytes
| 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) | |