Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -50,10 +50,48 @@ def predict_fire(image):
|
|
50 |
severity_pred = xception_model.predict(xception_img_array)
|
51 |
severity_level = np.argmax(severity_pred[0])
|
52 |
severity = ["Mild", "Moderate", "Severe"][severity_level]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
else:
|
54 |
severity = "N/A"
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
-
return fire_status, severity
|
57 |
|
58 |
|
59 |
# Gradio interface
|
@@ -65,7 +103,7 @@ interface = gr.Interface(
|
|
65 |
gr.Textbox(label="Severity Level"),
|
66 |
],
|
67 |
title="Fire Prediction and Severity Classification",
|
68 |
-
description="Upload an image to predict fire and its severity level (Mild, Moderate, Severe).",
|
69 |
)
|
70 |
|
71 |
if __name__ == "__main__":
|
|
|
50 |
severity_pred = xception_model.predict(xception_img_array)
|
51 |
severity_level = np.argmax(severity_pred[0])
|
52 |
severity = ["Mild", "Moderate", "Severe"][severity_level]
|
53 |
+
|
54 |
+
# Static rule-based recommendations with detailed instructions
|
55 |
+
if severity == "Mild":
|
56 |
+
recommendation = (
|
57 |
+
"Fire detected is mild and manageable. "
|
58 |
+
"For the Fire Department: Ensure continuous monitoring of the fire. "
|
59 |
+
"Deploy fire trucks and extinguishing equipment if necessary to prevent escalation. "
|
60 |
+
"For the Public: Stay alert and stay indoors. Evacuate only if advised by authorities. "
|
61 |
+
"Ensure clear access routes for emergency services. "
|
62 |
+
"Keep fire safety equipment such as fire extinguishers readily available."
|
63 |
+
)
|
64 |
+
elif severity == "Moderate":
|
65 |
+
recommendation = (
|
66 |
+
"Fire detected is moderate and poses a significant risk. "
|
67 |
+
"For the Fire Department: Immediate response is needed. "
|
68 |
+
"Deploy sufficient fire trucks, helicopters (if possible), and personnel to contain the fire. "
|
69 |
+
"Establish firebreaks and coordinate with neighboring departments. "
|
70 |
+
"For the Public: Evacuate the area promptly as the fire might spread. "
|
71 |
+
"Follow evacuation routes and do not return to the area until authorities deem it safe. "
|
72 |
+
"Be cautious of smoke inhalation, and wear protective masks if available."
|
73 |
+
)
|
74 |
+
else: # Severe
|
75 |
+
recommendation = (
|
76 |
+
"Severe fire detected with rapid spread potential. Immediate action is critical. "
|
77 |
+
"For the Fire Department: Prioritize evacuation operations. "
|
78 |
+
"Deploy all available resources, including specialized teams and air support. "
|
79 |
+
"Set up perimeters around the affected area and prevent access. "
|
80 |
+
"Coordinate with national agencies for additional resources and backup. "
|
81 |
+
"For the Public: Evacuate immediately. Leave all belongings behind and proceed to designated safe zones. "
|
82 |
+
"Avoid smoke exposure and keep away from fire zones. Follow all official instructions and do not attempt to return to the area until clearance is given by emergency services. "
|
83 |
+
"Remain in contact with local authorities for further updates."
|
84 |
+
)
|
85 |
+
|
86 |
else:
|
87 |
severity = "N/A"
|
88 |
+
recommendation = (
|
89 |
+
"No fire detected. However, always be cautious of any unusual smoke or smells in your environment. "
|
90 |
+
"Ensure that fire alarms are functioning, and regularly check fire extinguishers. "
|
91 |
+
"Stay prepared by familiarizing yourself with fire evacuation routes and emergency contact numbers."
|
92 |
+
)
|
93 |
|
94 |
+
return fire_status, severity, recommendation
|
95 |
|
96 |
|
97 |
# Gradio interface
|
|
|
103 |
gr.Textbox(label="Severity Level"),
|
104 |
],
|
105 |
title="Fire Prediction and Severity Classification",
|
106 |
+
description="Upload an image to predict fire and its severity level (Mild, Moderate, Severe), and get recommendations.",
|
107 |
)
|
108 |
|
109 |
if __name__ == "__main__":
|