skytnt commited on
Commit
1d049c7
1 Parent(s): 9d365b6

update model

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -7,7 +7,7 @@ from huggingface_hub import hf_hub_download
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
@@ -15,14 +15,14 @@ def predict(img):
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
  examples = [[f"examples/{x:02d}.jpg"] for x in range(0, 2)]
26
- app = gr.Interface(predict, gr.Image(label="input image"), gr.Label(label="result"),title="Best Anime or Not",
27
  allow_flagging="never", examples=examples)
28
  app.launch()
 
7
 
8
  def predict(img):
9
  img = img.astype(np.float32) / 255
10
+ s = 768
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
 
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].item()
19
+ return f"{pred}"
20
 
21
 
22
  if __name__ == "__main__":
23
+ model_path = hf_hub_download(repo_id="skytnt/anime-aesthetic", filename="model.onnx")
24
  model = rt.InferenceSession(model_path, providers=['CUDAExecutionProvider', 'CPUExecutionProvider'])
25
  examples = [[f"examples/{x:02d}.jpg"] for x in range(0, 2)]
26
+ app = gr.Interface(predict, gr.Image(label="input image"), gr.Textbox(label="score"),title="Anime Aesthetic Predict",
27
  allow_flagging="never", examples=examples)
28
  app.launch()