Hudda commited on
Commit
05cdc2b
·
verified ·
1 Parent(s): ffd69a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -20
app.py CHANGED
@@ -1,30 +1,38 @@
1
  import streamlit as st
 
2
  from PIL import Image
3
- import numpy as np
4
 
5
- st.title("Tree Counter App")
 
6
 
7
- # Upload image via Streamlit
8
- uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png", "jpeg"])
 
 
 
9
 
 
 
 
 
10
  if uploaded_file is not None:
11
- # Open the image
12
  img = Image.open(uploaded_file)
13
- st.image(img, caption="Uploaded Image.", use_column_width=True)
14
 
15
- # Check image dimensions
16
- width, height = img.size
17
- if width > 1024 or height > 1024:
18
- st.error("Image is too large. Please crop it.")
19
- else:
20
- # Simulate tree detection using random number
21
- trees = np.random.randint(0, 100)
22
- st.success(f"Number of Trees: {trees}")
23
 
24
- # Image cropping functionality
25
- if uploaded_file is not None and st.button("Crop Image to 1024x1024"):
26
- cropped_img = img.crop((0, 0, min(1024, img.width), min(1024, img.height)))
27
- st.image(cropped_img, caption="Cropped Image.", use_column_width=True)
28
- cropped_img.save("cropped_image.jpg")
29
- st.success("Image cropped successfully.")
 
 
 
 
 
30
 
 
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
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
+ # Display a file uploader
15
+ uploaded_file = st.file_uploader("Browse images from FireShot", type=["jpg", "png", "jpeg"])
16
+
17
+ # If the user uploads a file, save it in the FireShot folder
18
  if uploaded_file is not None:
 
19
  img = Image.open(uploaded_file)
20
+ st.image(img, caption="Uploaded Image", use_column_width=True)
21
 
22
+ # Save the image to FireShot folder
23
+ file_path = os.path.join(FIRE_SHOT_FOLDER, uploaded_file.name)
24
+ img.save(file_path)
25
+ st.success(f"Image saved to {file_path}")
 
 
 
 
26
 
27
+ # Optionally, display all images from the FireShot folder
28
+ if st.button("Show all images in FireShot folder"):
29
+ image_files = [f for f in os.listdir(FIRE_SHOT_FOLDER) if f.endswith(('jpg', 'jpeg', 'png'))]
30
+
31
+ if image_files:
32
+ for image_file in image_files:
33
+ img_path = os.path.join(FIRE_SHOT_FOLDER, image_file)
34
+ img = Image.open(img_path)
35
+ st.image(img, caption=image_file, use_column_width=True)
36
+ else:
37
+ st.info("No images found in FireShot folder.")
38