Hudda commited on
Commit
303526c
·
verified ·
1 Parent(s): 81f6fc3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -24
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 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
 
 
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