Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,10 @@
|
|
1 |
import streamlit as st
|
2 |
-
import os
|
3 |
from PIL import Image
|
|
|
|
|
|
|
4 |
|
5 |
-
# Define the path to the folder
|
6 |
FIRE_SHOT_FOLDER = os.path.join(os.getcwd(), 'FireShot')
|
7 |
|
8 |
# Ensure the folder exists
|
@@ -11,28 +13,46 @@ if not os.path.exists(FIRE_SHOT_FOLDER):
|
|
11 |
else:
|
12 |
st.success(f"FireShot folder found at {FIRE_SHOT_FOLDER}")
|
13 |
|
14 |
-
# Display a
|
15 |
-
|
16 |
|
17 |
-
#
|
18 |
-
if
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
st.
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
|
|
1 |
import streamlit as st
|
|
|
2 |
from PIL import Image
|
3 |
+
import os
|
4 |
+
import torch
|
5 |
+
from transformers import pipeline # Assuming you use a Hugging Face pipeline
|
6 |
|
7 |
+
# Define the path to the folder where images are stored
|
8 |
FIRE_SHOT_FOLDER = os.path.join(os.getcwd(), 'FireShot')
|
9 |
|
10 |
# Ensure the folder exists
|
|
|
13 |
else:
|
14 |
st.success(f"FireShot folder found at {FIRE_SHOT_FOLDER}")
|
15 |
|
16 |
+
# Display a list of image files in the folder
|
17 |
+
image_files = [f for f in os.listdir(FIRE_SHOT_FOLDER) if f.endswith(('jpg', 'jpeg', 'png'))]
|
18 |
|
19 |
+
# Make sure there are images in the folder
|
20 |
+
if not image_files:
|
21 |
+
st.info("No images found in FireShot folder.")
|
22 |
+
else:
|
23 |
+
st.write("## Select an image to perform object detection:")
|
24 |
+
|
25 |
+
# Display images as clickable thumbnails
|
26 |
+
selected_image = None
|
27 |
+
cols = st.columns(4) # Adjust the number of columns based on your layout preference
|
28 |
+
|
29 |
+
for i, image_file in enumerate(image_files):
|
30 |
+
img_path = os.path.join(FIRE_SHOT_FOLDER, image_file)
|
31 |
+
img = Image.open(img_path)
|
32 |
+
|
33 |
+
# Display thumbnail of the image
|
34 |
+
with cols[i % 4]: # Display images in 4 columns
|
35 |
+
if st.button(image_file):
|
36 |
+
selected_image = img_path # Set the selected image
|
37 |
|
38 |
+
# Once an image is selected, run the object detection model on it
|
39 |
+
if selected_image:
|
40 |
+
st.write(f"### Running object detection on {os.path.basename(selected_image)}")
|
41 |
+
|
42 |
+
img = Image.open(selected_image)
|
43 |
+
st.image(img, caption="Selected Image", use_column_width=True)
|
44 |
+
|
45 |
+
# Load your object detection model from Hugging Face (replace with your model)
|
46 |
+
model = pipeline('object-detection', model='your-huggingface-model') # Load your Hugging Face model
|
47 |
+
|
48 |
+
# Convert the image to the format needed by the model (PIL Image)
|
49 |
+
results = model(selected_image) # Pass image file to model
|
50 |
+
|
51 |
+
# Display results (adjust this depending on the format of model's output)
|
52 |
+
st.write(f"### Detected Objects: {results}")
|
53 |
+
|
54 |
+
# Assuming you're counting trees based on detection
|
55 |
+
tree_count = sum(1 for obj in results if obj['label'] == 'tree')
|
56 |
+
st.success(f"### Number of Trees: {tree_count}")
|
57 |
+
|
58 |
|