Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- README.md +7 -8
- app.py +112 -46
- best.pt +3 -0
- data_exploration.ipynb +0 -0
- requirements.txt +5 -5
README.md
CHANGED
@@ -1,14 +1,13 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
colorFrom: yellow
|
5 |
-
colorTo:
|
6 |
-
sdk:
|
7 |
-
sdk_version:
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
license:
|
11 |
-
short_description: csrs in colorado
|
12 |
---
|
13 |
|
14 |
-
|
|
|
1 |
---
|
2 |
+
title: Fire And Smoke
|
3 |
+
emoji: 🐢
|
4 |
colorFrom: yellow
|
5 |
+
colorTo: red
|
6 |
+
sdk: streamlit
|
7 |
+
sdk_version: 1.28.2
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
license: mit
|
|
|
11 |
---
|
12 |
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
@@ -1,48 +1,114 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
import
|
5 |
-
import
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
return handle_pdf(input_data["name"])
|
19 |
-
else:
|
20 |
-
return "Unsupported input type."
|
21 |
-
|
22 |
-
def handle_text(text):
|
23 |
-
inputs = tokenizer(text, return_tensors="pt")
|
24 |
-
outputs = model.generate(**inputs, max_new_tokens=100)
|
25 |
-
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
26 |
-
|
27 |
-
def handle_image(image):
|
28 |
-
return "Image processing not implemented yet."
|
29 |
-
|
30 |
-
def handle_pdf(pdf_path):
|
31 |
-
with pdfplumber.open(pdf_path) as pdf:
|
32 |
-
text = "\n".join([page.extract_text() for page in pdf.pages if page.extract_text()])
|
33 |
-
return handle_text(text)
|
34 |
-
|
35 |
-
# Create Gradio app
|
36 |
-
iface = gr.Interface(
|
37 |
-
fn=process_input,
|
38 |
-
inputs=[
|
39 |
-
gr.Textbox(label="Enter text"),
|
40 |
-
gr.Image(label="Upload image"),
|
41 |
-
gr.File(label="Upload PDF")
|
42 |
-
],
|
43 |
-
outputs=gr.Textbox(),
|
44 |
-
title="Multimodal Chatbot",
|
45 |
-
description="Handles text, images, and PDFs with the same entry point."
|
46 |
)
|
47 |
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Import required libraries
|
2 |
+
import PIL
|
3 |
+
import cv2
|
4 |
+
import streamlit as st
|
5 |
+
from ultralytics import YOLO
|
6 |
+
import tempfile
|
7 |
+
|
8 |
+
|
9 |
+
# Replace the relative path to your weight file
|
10 |
+
model_path = 'https://huggingface.co/spaces/ankitkupadhyay/fire_and_smoke/blob/main/best.pt'
|
11 |
+
|
12 |
+
# Setting page layout
|
13 |
+
st.set_page_config(
|
14 |
+
page_title="WildfireWatch", # Setting page title
|
15 |
+
page_icon="🔥", # Setting page icon
|
16 |
+
layout="wide", # Setting layout to wide
|
17 |
+
initial_sidebar_state="expanded" # Expanding sidebar by default
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
)
|
19 |
|
20 |
+
# Creating sidebar
|
21 |
+
with st.sidebar:
|
22 |
+
st.header("IMAGE/VIDEO UPLOAD") # Adding header to sidebar
|
23 |
+
# Adding file uploader to sidebar for selecting images and videos
|
24 |
+
source_file = st.file_uploader(
|
25 |
+
"Choose an image or video...", type=("jpg", "jpeg", "png", 'bmp', 'webp', 'mp4'))
|
26 |
+
|
27 |
+
# Model Options
|
28 |
+
confidence = float(st.slider(
|
29 |
+
"Select Model Confidence", 25, 100, 40)) / 100
|
30 |
+
|
31 |
+
# Creating main page heading
|
32 |
+
st.title("WildfireWatch: Detecting Wildfire using AI")
|
33 |
+
|
34 |
+
# Adding informative pictures and description about the motivation for the app
|
35 |
+
col1, col2 = st.columns(2)
|
36 |
+
with col1:
|
37 |
+
st.image("https://huggingface.co/spaces/ankitkupadhyay/fire_and_smoke/resolve/main/Fire_1.jpeg", use_column_width=True)
|
38 |
+
with col2:
|
39 |
+
st.image("https://huggingface.co/spaces/ankitkupadhyay/fire_and_smoke/resolve/main/Fire_2.jpeg", use_column_width=True)
|
40 |
+
|
41 |
+
st.markdown("""
|
42 |
+
Wildfires are a major environmental issue, causing substantial losses to ecosystems, human livelihoods, and potentially leading to loss of life. Early detection of wildfires can prevent these losses. Our application, WildfireWatch, uses state-of-the-art YOLOv8 model for real-time wildfire and smoke detection in images and videos.
|
43 |
+
""")
|
44 |
+
|
45 |
+
st.markdown("---") # Adding a horizontal line
|
46 |
+
|
47 |
+
st.header("Let's Detect Wildfire")
|
48 |
+
|
49 |
+
# Creating two columns on the main page
|
50 |
+
col1, col2 = st.columns(2)
|
51 |
+
|
52 |
+
# Adding image to the first column if image is uploaded
|
53 |
+
with col1:
|
54 |
+
if source_file:
|
55 |
+
# Check if the file is an image
|
56 |
+
if source_file.type.split('/')[0] == 'image':
|
57 |
+
# Opening the uploaded image
|
58 |
+
uploaded_image = PIL.Image.open(source_file)
|
59 |
+
# Adding the uploaded image to the page with a caption
|
60 |
+
st.image(source_file,
|
61 |
+
caption="Uploaded Image",
|
62 |
+
use_column_width=True
|
63 |
+
)
|
64 |
+
else:
|
65 |
+
tfile = tempfile.NamedTemporaryFile(delete=False)
|
66 |
+
tfile.write(source_file.read())
|
67 |
+
vidcap = cv2.VideoCapture(tfile.name)
|
68 |
+
|
69 |
+
try:
|
70 |
+
model = YOLO(model_path)
|
71 |
+
except Exception as ex:
|
72 |
+
st.error(
|
73 |
+
f"Unable to load model. Check the specified path: {model_path}")
|
74 |
+
st.error(ex)
|
75 |
+
|
76 |
+
if st.sidebar.button('Let\'s Detect Wildfire'):
|
77 |
+
if source_file.type.split('/')[0] == 'image':
|
78 |
+
res = model.predict(uploaded_image,
|
79 |
+
conf=confidence
|
80 |
+
)
|
81 |
+
boxes = res[0].boxes
|
82 |
+
res_plotted = res[0].plot()[:, :, ::-1]
|
83 |
+
with col2:
|
84 |
+
st.image(res_plotted,
|
85 |
+
caption='Detected Image',
|
86 |
+
use_column_width=True
|
87 |
+
)
|
88 |
+
try:
|
89 |
+
with st.expander("Detection Results"):
|
90 |
+
for box in boxes:
|
91 |
+
st.write(box.xywh)
|
92 |
+
except Exception as ex:
|
93 |
+
st.write("No image is uploaded yet!")
|
94 |
+
else:
|
95 |
+
# Open the video file
|
96 |
+
success, image = vidcap.read()
|
97 |
+
while success:
|
98 |
+
res = model.predict(image,
|
99 |
+
conf=confidence
|
100 |
+
)
|
101 |
+
boxes = res[0].boxes
|
102 |
+
res_plotted = res[0].plot()[:, :, ::-1]
|
103 |
+
with col2:
|
104 |
+
st.image(res_plotted,
|
105 |
+
caption='Detected Frame',
|
106 |
+
use_column_width=True
|
107 |
+
)
|
108 |
+
try:
|
109 |
+
with st.expander("Detection Results"):
|
110 |
+
for box in boxes:
|
111 |
+
st.write(box.xywh)
|
112 |
+
except Exception as ex:
|
113 |
+
st.write("No video is uploaded yet!")
|
114 |
+
success, image = vidcap.read()
|
best.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:05a5e990d1bcb3e4f2b6f38d48baffba4418baf65f3d426af0cecce43ecd4eab
|
3 |
+
size 6236761
|
data_exploration.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
requirements.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
-
|
2 |
-
torch
|
3 |
-
|
4 |
-
|
5 |
-
|
|
|
1 |
+
streamlit==1.29.0
|
2 |
+
torch==2.1.0
|
3 |
+
Pillow==9.4.0
|
4 |
+
opencv-python-headless==4.8.0.76
|
5 |
+
ultralytics==8.0.221
|