Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -63,24 +63,24 @@ def get_precautions(label):
|
|
| 63 |
|
| 64 |
# Streamlit UI
|
| 65 |
st.title("🚨 Disaster Detection App")
|
| 66 |
-
st.write("
|
| 67 |
|
| 68 |
-
# Option 1:
|
| 69 |
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
| 70 |
|
| 71 |
-
# Option 2: Manual selection
|
| 72 |
manual_disaster = st.selectbox(
|
| 73 |
-
"
|
| 74 |
["None", "fire", "flood", "landslide", "earthquake", "building_collapse"]
|
| 75 |
)
|
| 76 |
|
| 77 |
disaster_label = None
|
| 78 |
confidence = None
|
| 79 |
|
| 80 |
-
|
|
|
|
| 81 |
img = Image.open(uploaded_file).convert("RGB")
|
| 82 |
st.image(img, caption="Uploaded Image", use_column_width=True)
|
| 83 |
-
|
| 84 |
st.write("Analyzing...")
|
| 85 |
results = classifier(img)
|
| 86 |
predicted_label = results[0]['label']
|
|
@@ -88,12 +88,12 @@ if uploaded_file:
|
|
| 88 |
disaster_label = LABEL_MAP.get(predicted_label, "unknown")
|
| 89 |
st.info(f"Model prediction: {disaster_label} ({confidence:.2%} confidence)")
|
| 90 |
|
| 91 |
-
# If
|
| 92 |
if manual_disaster != "None":
|
| 93 |
disaster_label = manual_disaster
|
| 94 |
confidence = None
|
| 95 |
|
| 96 |
-
# Show precautions
|
| 97 |
if disaster_label and disaster_label != "no disaster":
|
| 98 |
st.subheader(f"Disaster Type: **{disaster_label}**")
|
| 99 |
st.markdown("### Precautionary Measures")
|
|
@@ -102,3 +102,4 @@ if disaster_label and disaster_label != "no disaster":
|
|
| 102 |
elif disaster_label == "no disaster":
|
| 103 |
st.info("No disaster detected in the uploaded image.")
|
| 104 |
|
|
|
|
|
|
| 63 |
|
| 64 |
# Streamlit UI
|
| 65 |
st.title("🚨 Disaster Detection App")
|
| 66 |
+
st.write("You can either upload an image OR manually select a disaster type to get safety tips.")
|
| 67 |
|
| 68 |
+
# Option 1: Image upload
|
| 69 |
uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
| 70 |
|
| 71 |
+
# Option 2: Manual disaster selection
|
| 72 |
manual_disaster = st.selectbox(
|
| 73 |
+
"Select a disaster type manually (optional):",
|
| 74 |
["None", "fire", "flood", "landslide", "earthquake", "building_collapse"]
|
| 75 |
)
|
| 76 |
|
| 77 |
disaster_label = None
|
| 78 |
confidence = None
|
| 79 |
|
| 80 |
+
# If image uploaded, classify it
|
| 81 |
+
if uploaded_file is not None:
|
| 82 |
img = Image.open(uploaded_file).convert("RGB")
|
| 83 |
st.image(img, caption="Uploaded Image", use_column_width=True)
|
|
|
|
| 84 |
st.write("Analyzing...")
|
| 85 |
results = classifier(img)
|
| 86 |
predicted_label = results[0]['label']
|
|
|
|
| 88 |
disaster_label = LABEL_MAP.get(predicted_label, "unknown")
|
| 89 |
st.info(f"Model prediction: {disaster_label} ({confidence:.2%} confidence)")
|
| 90 |
|
| 91 |
+
# If user chooses manual option, override
|
| 92 |
if manual_disaster != "None":
|
| 93 |
disaster_label = manual_disaster
|
| 94 |
confidence = None
|
| 95 |
|
| 96 |
+
# Show precautions
|
| 97 |
if disaster_label and disaster_label != "no disaster":
|
| 98 |
st.subheader(f"Disaster Type: **{disaster_label}**")
|
| 99 |
st.markdown("### Precautionary Measures")
|
|
|
|
| 102 |
elif disaster_label == "no disaster":
|
| 103 |
st.info("No disaster detected in the uploaded image.")
|
| 104 |
|
| 105 |
+
|