SakibRumu commited on
Commit
945dab5
·
verified ·
1 Parent(s): cf0ce6b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -13
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
- # Download models from Hugging Face Hub
12
- model_repo_id = "your-username/fire-gas-detection-models" # Replace with your repo ID
13
- rf_model_path = hf_hub_download(repo_id=model_repo_id, filename="model.pkl")
14
- yolo_model_path = hf_hub_download(repo_id=model_repo_id, filename="best.pt")
15
-
16
- # Load the Random Forest model
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(yolo_model_path)
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 "Fire & Gas Leak Detection System",
183
- description "Simulate sensor data and upload an image for vision detection to predict the threat level using a Random Forest model and YOLOv10."
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()