kivantium commited on
Commit
9340b8e
β€’
1 Parent(s): f6693d3

Initial commit

Browse files
Files changed (3) hide show
  1. README.md +3 -4
  2. app.py +59 -0
  3. requirements.txt +18 -0
README.md CHANGED
@@ -1,13 +1,12 @@
1
  ---
2
- title: Danbooru Pose Search
3
- emoji: 🏒
4
  colorFrom: purple
5
  colorTo: indigo
6
  sdk: gradio
7
- sdk_version: 3.4.1
8
  app_file: app.py
9
  pinned: false
10
- license: mit
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
1
  ---
2
+ title: Anime Pose Estimator
3
+ emoji: πŸ‘
4
  colorFrom: purple
5
  colorTo: indigo
6
  sdk: gradio
7
+ sdk_version: 3.4
8
  app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ os.system("pip install gradio==3.4")
3
+ import gradio as gr
4
+ os.system("pip install 'git+https://github.com/facebookresearch/detectron2.git'")
5
+ os.system("git clone https://github.com/kivantium/bizarre-pose-estimator.git")
6
+ os.chdir("bizarre-pose-estimator")
7
+
8
+ os.system("wget https://i.imgur.com/IkJzlaE.jpeg")
9
+
10
+ os.system("gdown https://drive.google.com/uc?id=1qhnBmMdDTC_8kmNj4u2f_Htfvg6KuE14")
11
+
12
+
13
+ os.system("unzip bizarre_pose_models.zip")
14
+ os.system("cp -a ./bizarre_pose_models/. .")
15
+
16
+
17
+ import urllib.request
18
+ from urllib.parse import urlparse
19
+ import json
20
+
21
+
22
+ def inference(img):
23
+ os.system("python3 -m _scripts.pose_retrieval "+img)
24
+ with open("./_samples/results.json") as f:
25
+ result = json.load(f)
26
+ html = '''
27
+ <table>
28
+ '''
29
+ chunk_size = 4
30
+ for i in range(0, len(result), chunk_size):
31
+ chunk = result[i:i+chunk_size]
32
+ html += '<tr>\n'
33
+ for row in chunk:
34
+ try:
35
+ data_raw = urllib.request.urlopen(f'https://danbooru.donmai.us/posts/{row["danbooru_id"]}.json')
36
+ data = json.load(data_raw)
37
+ html += f'<td><a href=\"https://danbooru.donmai.us/posts/{row["danbooru_id"]}\" target="_blank" rel="noopener noreferrer"><img src=\"{data["preview_file_url"]}\"></a></td>'
38
+ except Exception as e:
39
+ pass
40
+ html += '</tr>'
41
+ html += '</table>'
42
+ return (html, "./_samples/character_pose_estim.png")
43
+
44
+
45
+ title = "danbooru-pose-search"
46
+ description = "Gradio demo for Danbooru search based on pose similarity"
47
+
48
+ article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2108.01819' target='_blank'>Transfer Learning for Pose Estimation of Illustrated Characters</a> | <a href='https://github.com/ShuhongChen/bizarre-pose-estimator' target='_blank'>Github Repo</a></p>"
49
+
50
+ gr.Interface(
51
+ inference,
52
+ gr.inputs.Image(type="filepath", label="Input"),
53
+ [gr.HTML(label="Result"), gr.outputs.Image(type="file", label="Estimated Pose")],
54
+ title=title,
55
+ description=description,
56
+ article=article,
57
+ allow_flagging="never",
58
+ enable_queue=True
59
+ ).launch()
requirements.txt ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ pytorch-lightning
2
+ kornia
3
+ gdown
4
+ torchvision
5
+ torch
6
+
7
+ matplotlib==3.5.0
8
+ scipy==1.7.1
9
+ scikit-learn==1.0.1
10
+ scikit-image==0.18.3
11
+ imagesize==1.3.0
12
+ flask==2.0.2
13
+
14
+ patool==1.12
15
+ easydict==1.9
16
+ Pillow
17
+
18
+ opencv-python-headless