Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,11 +7,48 @@ from PIL import Image
|
|
| 7 |
import io
|
| 8 |
import torch
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
# Load the YOLO model
|
| 11 |
@st.cache_resource
|
| 12 |
def load_model():
|
| 13 |
-
model = YOLO("mosaic_medium_100_tiny_object.pt")
|
| 14 |
-
model.to('cpu')
|
| 15 |
return model
|
| 16 |
|
| 17 |
model = load_model()
|
|
@@ -44,18 +81,52 @@ def process_image(image):
|
|
| 44 |
return cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB)
|
| 45 |
|
| 46 |
def main():
|
| 47 |
-
st.title("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
result_image = process_image(image)
|
| 58 |
-
st.image(result_image, caption="Processed Image", use_column_width=True)
|
| 59 |
|
| 60 |
if __name__ == "__main__":
|
| 61 |
main()
|
|
|
|
| 7 |
import io
|
| 8 |
import torch
|
| 9 |
|
| 10 |
+
# Set page config
|
| 11 |
+
st.set_page_config(page_title="Building Detection App", page_icon="🏢", layout="wide")
|
| 12 |
+
|
| 13 |
+
# Custom CSS
|
| 14 |
+
st.markdown("""
|
| 15 |
+
<style>
|
| 16 |
+
.reportview-container {
|
| 17 |
+
background: #f0f2f6
|
| 18 |
+
}
|
| 19 |
+
.main {
|
| 20 |
+
background-color: #ffffff;
|
| 21 |
+
padding: 2rem;
|
| 22 |
+
border-radius: 10px;
|
| 23 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 24 |
+
}
|
| 25 |
+
.stButton>button {
|
| 26 |
+
background-color: #4CAF50;
|
| 27 |
+
color: white;
|
| 28 |
+
font-weight: bold;
|
| 29 |
+
border: none;
|
| 30 |
+
border-radius: 5px;
|
| 31 |
+
padding: 0.5rem 1rem;
|
| 32 |
+
transition: all 0.3s;
|
| 33 |
+
}
|
| 34 |
+
.stButton>button:hover {
|
| 35 |
+
background-color: #45a049;
|
| 36 |
+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
| 37 |
+
}
|
| 38 |
+
.upload-box {
|
| 39 |
+
border: 2px dashed #4CAF50;
|
| 40 |
+
border-radius: 10px;
|
| 41 |
+
padding: 2rem;
|
| 42 |
+
text-align: center;
|
| 43 |
+
}
|
| 44 |
+
</style>
|
| 45 |
+
""", unsafe_allow_html=True)
|
| 46 |
+
|
| 47 |
# Load the YOLO model
|
| 48 |
@st.cache_resource
|
| 49 |
def load_model():
|
| 50 |
+
model = YOLO("mosaic_medium_100_tiny_object.pt") # Update this to the filename of your model
|
| 51 |
+
model.to('cpu') # Ensure the model is on CPU
|
| 52 |
return model
|
| 53 |
|
| 54 |
model = load_model()
|
|
|
|
| 81 |
return cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB)
|
| 82 |
|
| 83 |
def main():
|
| 84 |
+
st.title("🏢 Building Detection App")
|
| 85 |
+
st.markdown("Upload an image to detect buildings using our advanced AI model.")
|
| 86 |
+
|
| 87 |
+
col1, col2 = st.columns(2)
|
| 88 |
+
|
| 89 |
+
with col1:
|
| 90 |
+
st.markdown("### Upload Image")
|
| 91 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
| 92 |
+
|
| 93 |
+
if uploaded_file is not None:
|
| 94 |
+
image = Image.open(uploaded_file)
|
| 95 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
| 96 |
+
|
| 97 |
+
if st.button("🔍 Detect Buildings"):
|
| 98 |
+
with st.spinner("Processing..."):
|
| 99 |
+
result_image = process_image(image)
|
| 100 |
+
with col2:
|
| 101 |
+
st.markdown("### Detection Results")
|
| 102 |
+
st.image(result_image, caption="Processed Image", use_column_width=True)
|
| 103 |
+
st.success("Detection completed successfully!")
|
| 104 |
+
else:
|
| 105 |
+
st.markdown(
|
| 106 |
+
"""
|
| 107 |
+
<div class="upload-box">
|
| 108 |
+
<h3>📁 Upload an image to get started</h3>
|
| 109 |
+
<p>Supported formats: JPG, JPEG, PNG</p>
|
| 110 |
+
</div>
|
| 111 |
+
""",
|
| 112 |
+
unsafe_allow_html=True
|
| 113 |
+
)
|
| 114 |
|
| 115 |
+
with col2:
|
| 116 |
+
if uploaded_file is None:
|
| 117 |
+
st.markdown("### How it works")
|
| 118 |
+
st.markdown(
|
| 119 |
+
"""
|
| 120 |
+
1. **Upload** an image using the file uploader on the left.
|
| 121 |
+
2. Click the **Detect Buildings** button to process the image.
|
| 122 |
+
3. View the results with bounding boxes around detected buildings.
|
| 123 |
|
| 124 |
+
Our AI model is trained to identify various types of buildings from satellite images.
|
| 125 |
+
"""
|
| 126 |
+
)
|
| 127 |
|
| 128 |
+
st.markdown("---")
|
| 129 |
+
st.markdown("Developed with ❤️ using Streamlit and YOLOv8")
|
|
|
|
|
|
|
| 130 |
|
| 131 |
if __name__ == "__main__":
|
| 132 |
main()
|