skytnt commited on
Commit
1bdd3b2
1 Parent(s): 63458a6
Files changed (4) hide show
  1. .gitignore +116 -0
  2. README.md +1 -1
  3. app.py +26 -0
  4. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ *.egg-info/
24
+ .installed.cfg
25
+ *.egg
26
+ MANIFEST
27
+
28
+ # PyInstaller
29
+ # Usually these files are written by a python script from a template
30
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
31
+ *.manifest
32
+ *.spec
33
+
34
+ # Installer logs
35
+ pip-log.txt
36
+ pip-delete-this-directory.txt
37
+
38
+ # Unit test / coverage reports
39
+ htmlcov/
40
+ .tox/
41
+ .nox/
42
+ .coverage
43
+ .coverage.*
44
+ .cache
45
+ nosetests.xml
46
+ coverage.xml
47
+ *.cover
48
+ .hypothesis/
49
+ .pytest_cache/
50
+
51
+ # Translations
52
+ *.mo
53
+ *.pot
54
+
55
+ # Django stuff:
56
+ *.log
57
+ local_settings.py
58
+ db.sqlite3
59
+
60
+ # Flask stuff:
61
+ instance/
62
+ .webassets-cache
63
+
64
+ # Scrapy stuff:
65
+ .scrapy
66
+
67
+ # Sphinx documentation
68
+ docs/_build/
69
+
70
+ # PyBuilder
71
+ target/
72
+
73
+ # Jupyter Notebook
74
+ .ipynb_checkpoints
75
+
76
+ # IPython
77
+ profile_default/
78
+ ipython_config.py
79
+
80
+ # pyenv
81
+ .python-version
82
+
83
+ # celery beat schedule file
84
+ celerybeat-schedule
85
+
86
+ # SageMath parsed files
87
+ *.sage.py
88
+
89
+ # Environments
90
+ .env
91
+ .venv
92
+ env/
93
+ venv/
94
+ ENV/
95
+ env.bak/
96
+ venv.bak/
97
+
98
+ # Spyder project settings
99
+ .spyderproject
100
+ .spyproject
101
+
102
+ # Rope project settings
103
+ .ropeproject
104
+
105
+ # mkdocs documentation
106
+ /site
107
+
108
+ # mypy
109
+ .mypy_cache/
110
+ .dmypy.json
111
+ dmypy.json
112
+
113
+ # Pyre type checker
114
+ .pyre/
115
+
116
+ .idea/
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
  title: Best Anime Or Not
3
- emoji: 💻
4
  colorFrom: purple
5
  colorTo: indigo
6
  sdk: gradio
 
1
  ---
2
  title: Best Anime Or Not
3
+ emoji: ❤️🖼️
4
  colorFrom: purple
5
  colorTo: indigo
6
  sdk: gradio
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import numpy as np
3
+ import gradio as gr
4
+ import onnxruntime as rt
5
+ from huggingface_hub import hf_hub_download
6
+
7
+
8
+ def predict(img):
9
+ img = img.astype(np.float32) / 255
10
+ s = 640
11
+ h, w = img.shape[:-1]
12
+ h, w = (s, int(s * w / h)) if h > w else (int(s * h / w), s)
13
+ ph, pw = s - h, s - w
14
+ img_input = np.zeros([s, s, 3], dtype=np.float32)
15
+ img_input[ph // 2:ph // 2 + h, pw // 2:pw // 2 + w] = cv2.resize(img, (w, h))
16
+ img_input = np.transpose(img_input, (2, 0, 1))
17
+ img_input = img_input[np.newaxis, :]
18
+ pred = model.run(None, {"img": img_input})[0][0]
19
+ return {"not best": pred[0].item(), "best": pred[1].item()}
20
+
21
+
22
+ if __name__ == "__main__":
23
+ model_path = hf_hub_download(repo_id="skytnt/anime_quality", filename="classifier.onnx")
24
+ model = rt.InferenceSession(model_path, providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
25
+ app = gr.Interface(predict, gr.Image(label="input image"), gr.Label(label="result"),title="Best Anime or Not", allow_flagging="never")
26
+ app.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ onnxruntime-gpu
2
+ opencv-python
3
+ numpy