Spaces:
Runtime error
Runtime error
Delete app.py
Browse files
app.py
DELETED
@@ -1,60 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
from transformers import pipeline as pip
|
3 |
-
from PIL import Image
|
4 |
-
|
5 |
-
# set page setting
|
6 |
-
st.set_page_config(page_title='Smoke & Fire Detection')
|
7 |
-
|
8 |
-
# set history var
|
9 |
-
if 'history' not in st.session_state:
|
10 |
-
st.session_state.history = []
|
11 |
-
|
12 |
-
@st.cache()
|
13 |
-
def demo_img():
|
14 |
-
demo_img = Image.open("./demo.jpg")
|
15 |
-
compute(demo_img)
|
16 |
-
|
17 |
-
@st.cache(persist=True)
|
18 |
-
def loadModel():
|
19 |
-
pipeline = pip(task="image-classification", model="EdBianchi/vit-fire-detection")
|
20 |
-
return pipeline
|
21 |
-
|
22 |
-
# PROCESSING
|
23 |
-
def compute(image):
|
24 |
-
predictions = pipeline(image)
|
25 |
-
|
26 |
-
with st.container():
|
27 |
-
st.image(image, use_column_width=True)
|
28 |
-
|
29 |
-
with st.container():
|
30 |
-
st.write("### Classification Outputs:")
|
31 |
-
col1, col2, col6 = st.columns(3)
|
32 |
-
col1.metric(predictions[0]['label'], str(round(predictions[0]['score']*100, 1))+"%")
|
33 |
-
col2.metric(predictions[1]['label'], str(round(predictions[1]['score']*100, 1))+"%")
|
34 |
-
col6.metric(predictions[2]['label'], str(round(predictions[2]['score']*100, 1))+"%")
|
35 |
-
return None
|
36 |
-
|
37 |
-
# INIT
|
38 |
-
with st.spinner('Loading the model, this could take some time...'):
|
39 |
-
pipeline = loadModel()
|
40 |
-
|
41 |
-
# TITLE
|
42 |
-
st.write("# 🌲 Smoke and Fire in Forests 🌲")
|
43 |
-
st.write("""Wildfires or forest fires are **unpredictable catastrophic and destructive** events that affect **rural areas**.
|
44 |
-
The impact of these events affects both **vegetation and wildlife**.
|
45 |
-
|
46 |
-
This application showcases the **vit-fire-detection** model, a version of google **vit-base-patch16-224-in21k** vision transformer fine-tuned for **smoke and fire detection**. In particular, we can imagine a setup in which webcams, drones, or other recording devices **take pictures of a wild environment every t seconds or minutes**. The proposed system is then able to classify the current situation as **normal, smoke, or fire**.
|
47 |
-
""")
|
48 |
-
|
49 |
-
st.write("### Upload an image to see the classifier in action")
|
50 |
-
# INPUT IMAGE
|
51 |
-
file_name = st.file_uploader("")
|
52 |
-
if file_name is not None:
|
53 |
-
image = Image.open(file_name)
|
54 |
-
compute(image)
|
55 |
-
|
56 |
-
# DEMO IMAGE
|
57 |
-
demo_img()
|
58 |
-
|
59 |
-
# SIDEBAR
|
60 |
-
#st.sidebar.write("""""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|