Rename src/streamlit_app.py to src/app.py
Browse files- src/app.py +74 -0
- src/streamlit_app.py +0 -40
src/app.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
from tensorflow.keras.utils import load_img, img_to_array
|
| 4 |
+
from io import BytesIO
|
| 5 |
+
|
| 6 |
+
st.set_page_config(page_title="Forest Fire Detection", page_icon="π₯", layout="centered")
|
| 7 |
+
|
| 8 |
+
# Custom header with emoji
|
| 9 |
+
st.markdown(
|
| 10 |
+
"""
|
| 11 |
+
<div style='text-align: center; margin-bottom: 20px;'>
|
| 12 |
+
<h1>π₯ Forest Fire Detection Demo π₯</h1>
|
| 13 |
+
<p style='font-size:20px;'>Upload a forest image and let AI detect fire!<br>
|
| 14 |
+
<span style='font-size:40px;'>π²π³π΄</span></p>
|
| 15 |
+
</div>
|
| 16 |
+
""",
|
| 17 |
+
unsafe_allow_html=True
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
st.sidebar.title("About")
|
| 21 |
+
st.sidebar.info(
|
| 22 |
+
"Upload a forest image to detect fire using a deep learning model. "
|
| 23 |
+
"This demo is powered by TensorFlow and Streamlit."
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# Load model only once
|
| 27 |
+
@st.cache_resource
|
| 28 |
+
def load_model():
|
| 29 |
+
return tf.keras.models.load_model('FFD.keras')
|
| 30 |
+
model = load_model()
|
| 31 |
+
|
| 32 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
| 33 |
+
|
| 34 |
+
if uploaded_file is not None:
|
| 35 |
+
with st.spinner("Analyzing image..."):
|
| 36 |
+
img = load_img(BytesIO(uploaded_file.read()), target_size=(150, 150))
|
| 37 |
+
img_array = img_to_array(img) / 255.0
|
| 38 |
+
img_array = img_array.reshape(1, 150, 150, 3)
|
| 39 |
+
prediction = model.predict(img_array)
|
| 40 |
+
confidence = float(prediction[0][0])
|
| 41 |
+
result = 'Fire Detected' if confidence > 0.5 else 'No Fire'
|
| 42 |
+
|
| 43 |
+
# Improved two-column layout with centered content and card-style result
|
| 44 |
+
col1, col2 = st.columns([1.2, 1])
|
| 45 |
+
with col1:
|
| 46 |
+
st.markdown("<div style='display:flex;justify-content:center;'>", unsafe_allow_html=True)
|
| 47 |
+
st.image(img, caption="Uploaded Image", width=260)
|
| 48 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
| 49 |
+
with col2:
|
| 50 |
+
st.markdown(
|
| 51 |
+
f"""
|
| 52 |
+
<div style='background: rgb(38, 39, 48); border-radius: 16px; box-shadow: 0 2px 12px rgba(0,0,0,0.08); padding: 24px; text-align: center; margin-top: 20px;'>
|
| 53 |
+
<h2 style='color:{"red" if result=="Fire Detected" else "green"}; margin-bottom: 10px;'>
|
| 54 |
+
{"π₯" if result=="Fire Detected" else "π²"} {result}
|
| 55 |
+
</h2>
|
| 56 |
+
<div style='margin-bottom: 10px;'>
|
| 57 |
+
<progress value='{confidence:.2f}' max='1' style='width:80%; height:18px;'></progress>
|
| 58 |
+
</div>
|
| 59 |
+
<div style='font-size:18px; margin-bottom: 10px;'><b>Confidence:</b> {confidence:.2f}</div>
|
| 60 |
+
</div>
|
| 61 |
+
""",
|
| 62 |
+
unsafe_allow_html=True
|
| 63 |
+
)
|
| 64 |
+
st.markdown("<br>", unsafe_allow_html=True)
|
| 65 |
+
else:
|
| 66 |
+
st.info("Please upload an image to get started.")
|
| 67 |
+
|
| 68 |
+
# Footer
|
| 69 |
+
st.markdown(
|
| 70 |
+
"<hr><div style='text-align:center;font-size:14px;'>"
|
| 71 |
+
"Made with β€οΈ by CoderKP using Streamlit & TensorFlow"
|
| 72 |
+
"</div>",
|
| 73 |
+
unsafe_allow_html=True
|
| 74 |
+
)
|
src/streamlit_app.py
DELETED
|
@@ -1,40 +0,0 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
-
import streamlit as st
|
| 5 |
-
|
| 6 |
-
"""
|
| 7 |
-
# Welcome to Streamlit!
|
| 8 |
-
|
| 9 |
-
Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
|
| 10 |
-
If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
|
| 11 |
-
forums](https://discuss.streamlit.io).
|
| 12 |
-
|
| 13 |
-
In the meantime, below is an example of what you can do with just a few lines of code:
|
| 14 |
-
"""
|
| 15 |
-
|
| 16 |
-
num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
|
| 17 |
-
num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
|
| 18 |
-
|
| 19 |
-
indices = np.linspace(0, 1, num_points)
|
| 20 |
-
theta = 2 * np.pi * num_turns * indices
|
| 21 |
-
radius = indices
|
| 22 |
-
|
| 23 |
-
x = radius * np.cos(theta)
|
| 24 |
-
y = radius * np.sin(theta)
|
| 25 |
-
|
| 26 |
-
df = pd.DataFrame({
|
| 27 |
-
"x": x,
|
| 28 |
-
"y": y,
|
| 29 |
-
"idx": indices,
|
| 30 |
-
"rand": np.random.randn(num_points),
|
| 31 |
-
})
|
| 32 |
-
|
| 33 |
-
st.altair_chart(alt.Chart(df, height=700, width=700)
|
| 34 |
-
.mark_point(filled=True)
|
| 35 |
-
.encode(
|
| 36 |
-
x=alt.X("x", axis=None),
|
| 37 |
-
y=alt.Y("y", axis=None),
|
| 38 |
-
color=alt.Color("idx", legend=None, scale=alt.Scale()),
|
| 39 |
-
size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
|
| 40 |
-
))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|