kevinconka commited on
Commit
5fe653d
·
1 Parent(s): 3460b3c

avoid re-installing pytorch

Browse files
Files changed (3) hide show
  1. app.py +17 -2
  2. install_private_repos.py +2 -3
  3. requirements.txt +3 -1
app.py CHANGED
@@ -4,6 +4,7 @@ Any new model should implement the following functions:
4
  - load_model(model_path, img_size=640)
5
  - inference(model, image)
6
  """
 
7
  import os
8
  import glob
9
  import spaces
@@ -16,8 +17,11 @@ from utils import (
16
  FlaggedCounter,
17
  )
18
  from flagging import HuggingFaceDatasetSaver
 
 
19
  import install_private_repos
20
  from seavision import load_model, AHOY
 
21
 
22
 
23
  TITLE = """
@@ -44,7 +48,15 @@ h1 {
44
  }
45
  """
46
 
47
- model = load_model("ahoy-RGB-b2")
 
 
 
 
 
 
 
 
48
 
49
  @spaces.GPU
50
  def inference(model: AHOY, image):
@@ -52,6 +64,9 @@ def inference(model: AHOY, image):
52
  results = model(image)
53
  return results.draw(image, diameter=4)
54
 
 
 
 
55
  # Flagging
56
  dataset_name = "SEA-AI/crowdsourced-sea-images"
57
  hf_writer = HuggingFaceDatasetSaver(get_token(), dataset_name)
@@ -95,7 +110,7 @@ with gr.Blocks(theme=theme, css=css, title="SEA.AI Vision Demo") as demo:
95
 
96
  # event listeners
97
  img_url.change(load_image_from_url, [img_url], img_input)
98
- submit.click(check_image, [img_input], show_api=False).success(
99
  lambda image: inference(model, image),
100
  [img_input],
101
  img_output,
 
4
  - load_model(model_path, img_size=640)
5
  - inference(model, image)
6
  """
7
+
8
  import os
9
  import glob
10
  import spaces
 
17
  FlaggedCounter,
18
  )
19
  from flagging import HuggingFaceDatasetSaver
20
+ import numpy as np
21
+
22
  import install_private_repos
23
  from seavision import load_model, AHOY
24
+ from seavision.utils.general import LOGGER
25
 
26
 
27
  TITLE = """
 
48
  }
49
  """
50
 
51
+ rng = np.random.default_rng(0xDEADBEEF)
52
+
53
+
54
+ @spaces.GPU
55
+ def load_ahoy() -> AHOY:
56
+ """Load and warmup the model."""
57
+ model = load_model("ahoy-RGB-b2")
58
+ return model
59
+
60
 
61
  @spaces.GPU
62
  def inference(model: AHOY, image):
 
64
  results = model(image)
65
  return results.draw(image, diameter=4)
66
 
67
+
68
+ model = load_ahoy()
69
+
70
  # Flagging
71
  dataset_name = "SEA-AI/crowdsourced-sea-images"
72
  hf_writer = HuggingFaceDatasetSaver(get_token(), dataset_name)
 
110
 
111
  # event listeners
112
  img_url.change(load_image_from_url, [img_url], img_input)
113
+ submit.click(check_image, [img_input], None, show_api=False).success(
114
  lambda image: inference(model, image),
115
  [img_input],
116
  img_output,
install_private_repos.py CHANGED
@@ -3,9 +3,8 @@ import os
3
  GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
4
  if GITHUB_TOKEN is not None:
5
  try:
6
- cmd = f'pip3 install "seavision[inference] @ git+https://{GITHUB_TOKEN}@github.com/SEA-AI/seavision"'
7
- cmd += ' --upgrade-strategy only-if-needed'
8
  os.system(cmd)
9
  except Exception as e:
10
  print(f"Error: {e}")
11
- raise e
 
3
  GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
4
  if GITHUB_TOKEN is not None:
5
  try:
6
+ cmd = f"pip3 install git+https://{GITHUB_TOKEN}@github.com/SEA-AI/seavision.git"
 
7
  os.system(cmd)
8
  except Exception as e:
9
  print(f"Error: {e}")
10
+ raise e
requirements.txt CHANGED
@@ -1,2 +1,4 @@
1
  spaces
2
- pillow
 
 
 
1
  spaces
2
+ pillow
3
+ onnx
4
+ onnx2torch