Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,9 @@
|
|
1 |
import streamlit as st
|
2 |
-
from PIL import Image
|
3 |
import os
|
4 |
-
import
|
5 |
-
|
6 |
-
|
7 |
-
# Define the path to the folder
|
8 |
FIRE_SHOT_FOLDER = os.path.join(os.getcwd(), 'FireShot')
|
9 |
|
10 |
# Ensure the folder exists
|
@@ -13,46 +12,32 @@ if not os.path.exists(FIRE_SHOT_FOLDER):
|
|
13 |
else:
|
14 |
st.success(f"FireShot folder found at {FIRE_SHOT_FOLDER}")
|
15 |
|
16 |
-
# Display a
|
17 |
-
|
18 |
|
19 |
-
#
|
20 |
-
if not
|
21 |
-
st.info("No images found in FireShot folder.")
|
22 |
-
else:
|
23 |
-
st.write("## Select an image to perform object detection:")
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
|
|
2 |
import os
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
|
6 |
+
# Define the path to the folder
|
7 |
FIRE_SHOT_FOLDER = os.path.join(os.getcwd(), 'FireShot')
|
8 |
|
9 |
# Ensure the folder exists
|
|
|
12 |
else:
|
13 |
st.success(f"FireShot folder found at {FIRE_SHOT_FOLDER}")
|
14 |
|
15 |
+
# Display a file uploader
|
16 |
+
uploaded_file = st.file_uploader("Browse images from FireShot", type=["jpg", "png", "jpeg"])
|
17 |
|
18 |
+
# If the user uploads a file, save it in the FireShot folder
|
19 |
+
if uploaded_file is not None:
|
|
|
|
|
|
|
20 |
|
21 |
+
img = Image.open(uploaded_file)
|
22 |
+
st.image(img, caption="Uploaded Image", use_column_width=True)
|
23 |
+
|
24 |
+
# Save the image to FireShot folder
|
25 |
+
file_path = os.path.join(FIRE_SHOT_FOLDER, uploaded_file.name)
|
26 |
+
img.save(file_path)
|
27 |
+
st.success(f"Image saved to {file_path}")
|
28 |
|
|
|
|
|
|
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
|
32 |
+
|
33 |
+
# Optionally, display all images from the FireShot folder
|
34 |
+
if st.button("Show all images in FireShot folder"):
|
35 |
+
image_files = [f for f in os.listdir(FIRE_SHOT_FOLDER) if f.endswith(('jpg', 'jpeg', 'png'))]
|
36 |
+
|
37 |
+
if image_files:
|
38 |
+
for image_file in image_files:
|
39 |
+
img_path = os.path.join(FIRE_SHOT_FOLDER, image_file)
|
40 |
+
img = Image.open(img_path)
|
41 |
+
st.image(img, caption=image_file, use_column_width=True)
|
42 |
+
else:
|
43 |
+
st.info("No images found in FireShot folder.")
|