Steven C commited on
Commit
8e71bd4
1 Parent(s): b83e09a

Merge secret_model into repo

Browse files
Files changed (4) hide show
  1. app.py +5 -40
  2. captcha.onnx +3 -0
  3. requirements.txt +0 -1
  4. secret_models +0 -1
app.py CHANGED
@@ -4,53 +4,20 @@ import onnx
4
  import onnxruntime as rt
5
  from torchvision import transforms as T
6
  from tokenizer_base import Tokenizer
7
- import pathlib
8
  from PIL import Image
9
- from huggingface_hub import Repository
10
 
11
 
12
  class DocumentParserModel:
13
  def __init__(
14
  self,
15
- repo_path,
16
- model_subpath,
17
  img_size,
18
- charset,
19
- repo_url="stevenchang/captcha",
20
- token=None,
21
  ):
22
- self.repo_path = pathlib.Path(repo_path).resolve()
23
- self.model_path = self.repo_path / model_subpath
24
  self.charset = charset
25
  self.tokenizer_base = Tokenizer(self.charset)
26
- self.initialize_repository(repo_url, token)
27
  self.transform = self.create_transform_pipeline(img_size)
28
- self.ort_session = self.initialize_onnx_model(str(self.model_path))
29
-
30
- def initialize_repository(self, repo_url, token):
31
- if not self.model_path.exists():
32
- if not self.repo_path.exists():
33
- print(
34
- f"Repository does not exist. Cloning from {repo_url} into {self.repo_path}"
35
- )
36
- repo = Repository(
37
- local_dir=str(self.repo_path),
38
- clone_from=repo_url,
39
- use_auth_token=token if token else True,
40
- )
41
- else:
42
- print(
43
- f"Model does not exist, but repository is already cloned. Pulling latest changes in {self.repo_path}"
44
- )
45
- repo = Repository(
46
- local_dir=str(self.repo_path),
47
- use_auth_token=token if token else True,
48
- )
49
- repo.git_pull()
50
- else:
51
- print(
52
- f"Model {self.model_path} already exists, skipping repository update."
53
- )
54
 
55
  def create_transform_pipeline(self, img_size):
56
  transforms = [
@@ -82,14 +49,12 @@ class DocumentParserModel:
82
  if __name__ == "__main__":
83
  import sys
84
 
85
- repo_path = "secret_models"
86
- model_subpath = "captcha.onnx"
87
  img_size = (32, 128)
88
  charset = r"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
89
 
90
  doc_parser = DocumentParserModel(
91
- repo_path=repo_path,
92
- model_subpath=model_subpath,
93
  img_size=img_size,
94
  charset=charset,
95
  )
 
4
  import onnxruntime as rt
5
  from torchvision import transforms as T
6
  from tokenizer_base import Tokenizer
 
7
  from PIL import Image
 
8
 
9
 
10
  class DocumentParserModel:
11
  def __init__(
12
  self,
13
+ model_path,
 
14
  img_size,
15
+ charset
 
 
16
  ):
 
 
17
  self.charset = charset
18
  self.tokenizer_base = Tokenizer(self.charset)
 
19
  self.transform = self.create_transform_pipeline(img_size)
20
+ self.ort_session = self.initialize_onnx_model(str(model_path))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  def create_transform_pipeline(self, img_size):
23
  transforms = [
 
49
  if __name__ == "__main__":
50
  import sys
51
 
52
+ model_path = "captcha.onnx"
 
53
  img_size = (32, 128)
54
  charset = r"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
55
 
56
  doc_parser = DocumentParserModel(
57
+ model_path=model_path,
 
58
  img_size=img_size,
59
  charset=charset,
60
  )
captcha.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2a672587ee82eb010dbef54dd0a38e99625293608ed4068c4bd20ebe467fede4
3
+ size 95401304
requirements.txt CHANGED
@@ -3,4 +3,3 @@ torchvision==0.12.0
3
  onnx==1.14.0
4
  onnxruntime==1.15.1
5
  Pillow==10.0.0
6
- huggingface-hub==0.21.4
 
3
  onnx==1.14.0
4
  onnxruntime==1.15.1
5
  Pillow==10.0.0
 
secret_models DELETED
@@ -1 +0,0 @@
1
- Subproject commit 99c2c60ac74ca2b4a90613ccec0685e416dff0a8