PUSHPENDAR commited on
Commit
52ea23b
·
verified ·
1 Parent(s): 5b7e125

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -7
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import gradio as gr
2
  import cv2
3
  import numpy as np
@@ -12,24 +13,28 @@ import os
12
  # DOWNLOAD MODEL FILES FROM HF HUB
13
  # ==============================
14
 
15
- REPO_ID = os.getenv("MODEL_REPO_ID", "PUSHPENDAR/hrsid-ship-detection") # ← change this
16
 
17
  # Download model_final.pth and config.yaml from your HF repo if not already present
18
- if not os.path.exists("model_final.pth"):
 
 
 
 
19
  print("Downloading model_final.pth from HuggingFace...")
20
  hf_hub_download(
21
  repo_id=REPO_ID,
22
  filename="model_final.pth",
23
- local_dir=".",
24
  )
25
  print("Downloaded model_final.pth ✅")
26
 
27
- if not os.path.exists("config.yaml"):
28
  print("Downloading config.yaml from HuggingFace...")
29
  hf_hub_download(
30
  repo_id=REPO_ID,
31
  filename="config.yaml",
32
- local_dir=".",
33
  )
34
  print("Downloaded config.yaml ✅")
35
 
@@ -39,8 +44,8 @@ if not os.path.exists("config.yaml"):
39
 
40
  print("Loading Faster R-CNN model...")
41
  cfg = get_cfg()
42
- cfg.merge_from_file("config.yaml")
43
- cfg.MODEL.WEIGHTS = "model_final.pth"
44
  cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5
45
  cfg.MODEL.DEVICE = "cpu" # HF Spaces free tier is CPU
46
 
 
1
+
2
  import gradio as gr
3
  import cv2
4
  import numpy as np
 
13
  # DOWNLOAD MODEL FILES FROM HF HUB
14
  # ==============================
15
 
16
+ REPO_ID = os.getenv("MODEL_REPO_ID", "PUSHPENDAR/hrsid-ship-detection")
17
 
18
  # Download model_final.pth and config.yaml from your HF repo if not already present
19
+ # Download to /tmp — writable by non-root user
20
+ MODEL_PATH = "/tmp/model_final.pth"
21
+ CONFIG_PATH = "/tmp/config.yaml"
22
+
23
+ if not os.path.exists(MODEL_PATH):
24
  print("Downloading model_final.pth from HuggingFace...")
25
  hf_hub_download(
26
  repo_id=REPO_ID,
27
  filename="model_final.pth",
28
+ local_dir="/tmp",
29
  )
30
  print("Downloaded model_final.pth ✅")
31
 
32
+ if not os.path.exists(CONFIG_PATH):
33
  print("Downloading config.yaml from HuggingFace...")
34
  hf_hub_download(
35
  repo_id=REPO_ID,
36
  filename="config.yaml",
37
+ local_dir="/tmp",
38
  )
39
  print("Downloaded config.yaml ✅")
40
 
 
44
 
45
  print("Loading Faster R-CNN model...")
46
  cfg = get_cfg()
47
+ cfg.merge_from_file(CONFIG_PATH)
48
+ cfg.MODEL.WEIGHTS = MODEL_PATH
49
  cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5
50
  cfg.MODEL.DEVICE = "cpu" # HF Spaces free tier is CPU
51