kivantium's picture
Update model URL
24487b3
import os
os.system("pip install gradio==3.4")
import gradio as gr
os.system("pip install 'git+https://github.com/facebookresearch/detectron2.git'")
os.system("git clone https://github.com/kivantium/bizarre-pose-estimator.git")
os.chdir("bizarre-pose-estimator")
os.system("wget https://i.imgur.com/IkJzlaE.jpeg")
os.system("gdown https://drive.google.com/uc?id=1rA6w77ww3u97C8lHgEdHFUkk8h45Wyfk")
os.system("unzip bizarre_pose_models.zip")
os.system("cp -a ./bizarre_pose_models/. .")
import urllib.request
from urllib.parse import urlparse
import json
def inference(img):
os.system("python3 -m _scripts.pose_retrieval "+img)
with open("./_samples/results.json") as f:
result = json.load(f)
html = '''
<table>
'''
chunk_size = 4
for i in range(0, len(result), chunk_size):
chunk = result[i:i+chunk_size]
html += '<tr>\n'
for row in chunk:
try:
data_raw = urllib.request.urlopen(f'https://danbooru.donmai.us/posts/{row["danbooru_id"]}.json')
data = json.load(data_raw)
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>'
except Exception as e:
pass
html += '</tr>'
html += '</table>'
return (html, "./_samples/character_pose_estim.png")
title = "danbooru-pose-search"
description = "Gradio demo for Danbooru search based on pose similarity"
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>"
gr.Interface(
inference,
gr.inputs.Image(type="filepath", label="Input"),
[gr.HTML(label="Result"), gr.outputs.Image(type="file", label="Estimated Pose")],
title=title,
description=description,
article=article,
allow_flagging="never",
enable_queue=True
).launch()