EdBianchi commited on
Commit
d8367c2
·
1 Parent(s): be7e9ac

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +47 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
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(persist=True)
13
+ def loadModel():
14
+ pipeline = pipeline(task="image-classification", model="EdBianchi/vit-fire-detection")
15
+ return pipeline
16
+
17
+ # PROCESSING
18
+ def compute(image):
19
+ predictions = pipeline(image)
20
+
21
+ with st.container():
22
+ st.image(image, use_column_width=True)
23
+
24
+ with st.container():
25
+ st.write("#### Different classification outputs at different threshold values:")
26
+ col1, col2, col6 = st.columns(3)
27
+ col1.metric(predictions[0]['label'], round(predictions[0]['score']+100, 1)+"%")
28
+ col2.metric(predictions[1]['label'], round(predictions[1]['score']+100, 1)+"%")
29
+ col6.metric(predictions[2]['label'], round(predictions[2]['score']+100, 1)+"%")
30
+ return None
31
+
32
+ # INIT
33
+ with st.spinner('Loading the model, this could take some time...'):
34
+ pipeline = loadModel()
35
+
36
+ # TITLE
37
+ st.write("# Smoke & Fire Detection in Forest Environments")
38
+ st.write("#### Upload an Image to see the classifier in action")
39
+
40
+ # INPUT IMAGE
41
+ file_name = st.file_uploader("Upload an image")
42
+ if file_name is not None:
43
+ image = Image.open(file_name)
44
+ compute(image)
45
+
46
+ # SIDEBAR
47
+ #st.sidebar.write("""""")
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ transformers
2
+ torch