Yaswanth56 commited on
Commit
1e3aee8
·
verified ·
1 Parent(s): b2d20ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -10
app.py CHANGED
@@ -1,5 +1,3 @@
1
-
2
-
3
  import cv2
4
  import torch
5
  import gradio as gr
@@ -19,11 +17,10 @@ import piexif
19
  import zipfile
20
  from fpdf import FPDF # PDF generation
21
 
22
- # Rest of your code continues...
23
-
24
-
25
- # Set YOLO config directory
26
- os.environ["YOLO_CONFIG_DIR"] = "/tmp/Ultralytics"
27
 
28
  # Set up logging
29
  logging.basicConfig(
@@ -61,11 +58,11 @@ print(f"Gradio version: {gr.__version__}")
61
  print(f"Ultralytics version: {ultralytics.__version__}")
62
  print(f"CUDA available: {torch.cuda.is_available()}")
63
 
64
- # Load custom YOLO model
65
- device = "cpu" # Force the use of CPU
66
  print(f"Using device: {device}")
67
  model = YOLO('./data/best.pt').to(device) # Model is now moved to the CPU
68
- if device == "cpu": # Optional check, not strictly needed but can help to ensure
69
  model.float() # Ensure model is running on the CPU
70
  print(f"Model classes: {model.names}")
71
 
 
 
 
1
  import cv2
2
  import torch
3
  import gradio as gr
 
17
  import zipfile
18
  from fpdf import FPDF # PDF generation
19
 
20
+ # Set YOLO config directory (ensure settings are created only once)
21
+ settings_path = '/home/user/.config/Ultralytics/settings.json'
22
+ if not os.path.exists(settings_path):
23
+ os.makedirs(os.path.dirname(settings_path), exist_ok=True)
 
24
 
25
  # Set up logging
26
  logging.basicConfig(
 
58
  print(f"Ultralytics version: {ultralytics.__version__}")
59
  print(f"CUDA available: {torch.cuda.is_available()}")
60
 
61
+ # Force CPU mode explicitly for the model
62
+ device = 'cpu' # Ensure we are using CPU
63
  print(f"Using device: {device}")
64
  model = YOLO('./data/best.pt').to(device) # Model is now moved to the CPU
65
+ if device == "cpu": # Optional check
66
  model.float() # Ensure model is running on the CPU
67
  print(f"Model classes: {model.names}")
68