| import streamlit as st |
| from transformers import pipeline |
| from PIL import Image |
|
|
| |
| st.title("Concrete Crack Detection") |
| st.write("Upload an image of a concrete surface, and the AI will predict if there is a crack.") |
|
|
| |
| |
| |
| MODEL_ID = "Guna-M/concrete-crack-ai" |
|
|
| try: |
| classifier = pipeline("image-classification", model=MODEL_ID) |
| except Exception as e: |
| st.error(f"Error loading model: {e}") |
| st.stop() |
|
|
| |
| uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"]) |
|
|
| if uploaded_file is not None: |
| image = Image.open(uploaded_file) |
| st.image(image, caption='Uploaded Image', use_container_width=True) |
| st.write("Analyzing...") |
| |
| |
| results = classifier(image) |
| |
| st.subheader("Prediction Results:") |
| |
| |
| top_result = results[0] |
| label = top_result['label'] |
| score = top_result['score'] * 100 |
| |
| if "crack" in label.lower() and "no" not in label.lower(): |
| st.error(f"Prediction: CRACK DETECTED (Confidence: {score:.2f}%)") |
| else: |
| st.success(f"Prediction: NO CRACK (Confidence: {score:.2f}%)") |
|
|
| |
| with st.expander("See all probabilities"): |
| for res in results: |
| st.write(f"- {res['label']}: {res['score']*100:.2f}%") |