SakibRumu
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -4,25 +4,22 @@ import numpy as np
|
|
4 |
from ultralytics import YOLO
|
5 |
import pandas as pd
|
6 |
import pickle
|
7 |
-
from huggingface_hub import hf_hub_download
|
8 |
import random
|
9 |
import torch.serialization
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
with open(rf_model_path, "rb") as f:
|
18 |
-
rf_model = pickle.load(f)
|
19 |
|
20 |
-
# Load the YOLO model with safe globals
|
21 |
try:
|
22 |
from ultralytics.nn.tasks import DetectionModel
|
23 |
import torch.nn as nn
|
24 |
torch.serialization.add_safe_globals([DetectionModel, nn.Sequential])
|
25 |
-
yolo_model = YOLO(
|
26 |
except Exception as e:
|
27 |
raise Exception(f"Failed to load YOLO model: {str(e)}")
|
28 |
|
@@ -179,6 +176,6 @@ gr.Interface(
|
|
179 |
fn=predict_system,
|
180 |
inputs=inputs,
|
181 |
outputs=outputs,
|
182 |
-
title
|
183 |
-
description
|
184 |
).launch()
|
|
|
4 |
from ultralytics import YOLO
|
5 |
import pandas as pd
|
6 |
import pickle
|
|
|
7 |
import random
|
8 |
import torch.serialization
|
9 |
|
10 |
+
# Load the Random Forest model directly from the Space repository
|
11 |
+
try:
|
12 |
+
with open("model.pkl", "rb") as f:
|
13 |
+
rf_model = pickle.load(f)
|
14 |
+
except Exception as e:
|
15 |
+
raise Exception(f"Failed to load Random Forest model: {str(e)}")
|
|
|
|
|
16 |
|
17 |
+
# Load the YOLO model with safe globals directly from the Space repository
|
18 |
try:
|
19 |
from ultralytics.nn.tasks import DetectionModel
|
20 |
import torch.nn as nn
|
21 |
torch.serialization.add_safe_globals([DetectionModel, nn.Sequential])
|
22 |
+
yolo_model = YOLO("best.pt")
|
23 |
except Exception as e:
|
24 |
raise Exception(f"Failed to load YOLO model: {str(e)}")
|
25 |
|
|
|
176 |
fn=predict_system,
|
177 |
inputs=inputs,
|
178 |
outputs=outputs,
|
179 |
+
title="Fire & Gas Leak Detection System",
|
180 |
+
description="Simulate sensor data and upload an image for vision detection to predict the threat level using a Random Forest model and YOLOv10."
|
181 |
).launch()
|