Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,12 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
| 3 |
from PIL import Image
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Define the path to the folder where images are stored
|
| 6 |
FIRE_SHOT_FOLDER = os.path.join(os.getcwd(), 'FireShot')
|
| 7 |
|
| 8 |
-
# Ensure the folder exists
|
| 9 |
-
if not os.path.exists(FIRE_SHOT_FOLDER):
|
| 10 |
-
st.error("FireShot folder does not exist!")
|
| 11 |
-
else:
|
| 12 |
-
st.success(f"FireShot folder found at {FIRE_SHOT_FOLDER}")
|
| 13 |
|
| 14 |
# Get list of images from the FireShot folder
|
| 15 |
image_files = [f for f in os.listdir(FIRE_SHOT_FOLDER) if f.endswith(('jpg', 'jpeg', 'png'))]
|
|
@@ -24,5 +21,27 @@ if image_files:
|
|
| 24 |
img = Image.open(img_path)
|
| 25 |
st.image(img, caption=f"Selected Image: {selected_image}", use_column_width=True)
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
else:
|
| 28 |
st.info("No images found in FireShot folder.")
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
| 3 |
from PIL import Image
|
| 4 |
+
from transformers import pipeline # Hugging Face pipeline for object detection
|
| 5 |
+
import time # To simulate a delay (for model processing)
|
| 6 |
|
| 7 |
# Define the path to the folder where images are stored
|
| 8 |
FIRE_SHOT_FOLDER = os.path.join(os.getcwd(), 'FireShot')
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
# Get list of images from the FireShot folder
|
| 12 |
image_files = [f for f in os.listdir(FIRE_SHOT_FOLDER) if f.endswith(('jpg', 'jpeg', 'png'))]
|
|
|
|
| 21 |
img = Image.open(img_path)
|
| 22 |
st.image(img, caption=f"Selected Image: {selected_image}", use_column_width=True)
|
| 23 |
|
| 24 |
+
# Add a button to start the object detection
|
| 25 |
+
if st.button("Run Tree Detection"):
|
| 26 |
+
# Show loading spinner while processing the model
|
| 27 |
+
with st.spinner("Running YOLO model to detect trees..."):
|
| 28 |
+
# Simulate loading time (you can remove this when using an actual model)
|
| 29 |
+
time.sleep(3) # Simulate delay (this line can be removed)
|
| 30 |
+
|
| 31 |
+
# Load YOLO model from Hugging Face
|
| 32 |
+
model = pipeline('object-detection', model="blah-blah-treecounter")
|
| 33 |
+
|
| 34 |
+
# Perform object detection on the selected image
|
| 35 |
+
results = model(img_path)
|
| 36 |
+
|
| 37 |
+
# Simulate counting trees based on the detected objects
|
| 38 |
+
tree_count = sum(1 for obj in results if obj['label'].lower() == 'tree')
|
| 39 |
+
|
| 40 |
+
# Display the results in a button to be clicked
|
| 41 |
+
if st.button("Show Results"):
|
| 42 |
+
st.write(f"### Detected Trees: {tree_count}")
|
| 43 |
+
st.json(results) # Display full detection results in JSON format if needed
|
| 44 |
+
|
| 45 |
else:
|
| 46 |
st.info("No images found in FireShot folder.")
|
| 47 |
+
|