Spaces:
Runtime error
Runtime error
Commit
Β·
a258e87
1
Parent(s):
d4d6143
Add initial changes to run drexel_metadata
Browse filesAdds code to run an app that uses the model from
https://github.com/hdr-bgnn/drexel_metadata/ to generate
images and JSON metadata. A user can upload an image and
generate the resulting output files.
Adds requirements.txt created by running `pipenv requirements`
within an environment created from drexel_metadata Pipfile.
Adds drexel_metadata as a submodule.
- .gitmodules +3 -0
- app.py +58 -0
- app_header.md +3 -0
- drexel_metadata +1 -0
- requirements.txt +106 -0
.gitmodules
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[submodule "drexel_metadata"]
|
| 2 |
+
path = drexel_metadata
|
| 3 |
+
url = https://github.com/hdr-bgnn/drexel_metadata/
|
app.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import json
|
| 3 |
+
import numpy as np
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import cv2
|
| 6 |
+
from drexel_metadata.gen_metadata import gen_metadata
|
| 7 |
+
from PIL import Image
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def create_temp_file_path(prefix, suffix):
|
| 11 |
+
with tempfile.NamedTemporaryFile(prefix=prefix, suffix=suffix, delete=False) as tmpfile:
|
| 12 |
+
return tmpfile.name
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def run_inference(input_img):
|
| 16 |
+
# input_mg: NumPy array with the shape (width, height, 3)
|
| 17 |
+
|
| 18 |
+
# Save input_mg as a temporary file
|
| 19 |
+
tmpfile = create_temp_file_path(prefix="input_", suffix, ".png")
|
| 20 |
+
im = Image.fromarray(input_img)
|
| 21 |
+
im.save(tmpfile)
|
| 22 |
+
|
| 23 |
+
# Create temp filenames for output images
|
| 24 |
+
visfname = create_temp_file_path(prefix="vis_", suffix=".png")
|
| 25 |
+
maskfname = create_temp_file_path(prefix="mask_", suffix=".png")
|
| 26 |
+
|
| 27 |
+
# Run inference
|
| 28 |
+
result = gen_metadata(tmpfile, device='cpu', maskfname=maskfname, visfname=visfname)
|
| 29 |
+
json_metadata = json.dumps(result)
|
| 30 |
+
|
| 31 |
+
# Cleanup
|
| 32 |
+
os.remove(tempfile)
|
| 33 |
+
|
| 34 |
+
return visfname, maskfname, json_metadata
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def read_app_header_markdown():
|
| 38 |
+
with open('app_header.md') as infile:
|
| 39 |
+
return infile.read()
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
dm_app = gr.Interface(
|
| 43 |
+
fn=run_inference,
|
| 44 |
+
# Input shows markdown explaining and app and a single image upload panel
|
| 45 |
+
inputs=[
|
| 46 |
+
gr.Markdown(read_app_header_markdown()),
|
| 47 |
+
gr.Image()
|
| 48 |
+
],
|
| 49 |
+
# Output consists of a visualization image, a masked image, and JSON metadata
|
| 50 |
+
outputs=[
|
| 51 |
+
gr.Image(label='visualization'),
|
| 52 |
+
gr.Image(label='mask'),
|
| 53 |
+
gr.JSON(label="JSON metadata")
|
| 54 |
+
],
|
| 55 |
+
allow_flagging="never" # Do not save user's results or prompt for users to save the results
|
| 56 |
+
)
|
| 57 |
+
dm_app.launch()
|
| 58 |
+
|
app_header.md
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Drexel Metadata
|
| 2 |
+
Generate Metadata for a fish image using the [hdr-bgnn/drexel_metadata model](https://github.com/hdr-bgnn/drexel_metadata).
|
| 3 |
+
The model will create a visualization based on the image, a mask of the fish outline, and JSON metadata.
|
drexel_metadata
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Subproject commit a8720c3bfefcbd5caf7d948fad4ba90c2adc7f3c
|
requirements.txt
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch==1.10.1
|
| 2 |
+
torchvision==0.11.2
|
| 3 |
+
absl-py==1.3.0
|
| 4 |
+
antlr4-python3-runtime==4.9.3
|
| 5 |
+
appdirs==1.4.4
|
| 6 |
+
asttokens==2.0.8
|
| 7 |
+
backcall==0.2.0
|
| 8 |
+
black==21.4b2
|
| 9 |
+
cachetools==5.2.0
|
| 10 |
+
certifi==2022.9.24
|
| 11 |
+
charset-normalizer==2.1.1
|
| 12 |
+
click==8.1.3
|
| 13 |
+
cloudpickle==2.2.0
|
| 14 |
+
contourpy==1.0.5
|
| 15 |
+
cycler==0.11.0
|
| 16 |
+
decorator==5.1.1
|
| 17 |
+
distlib==0.3.6
|
| 18 |
+
executing==1.1.1
|
| 19 |
+
filelock==3.8.0
|
| 20 |
+
fonttools==4.37.4
|
| 21 |
+
future==0.18.2
|
| 22 |
+
fvcore==0.1.5.post20220512
|
| 23 |
+
google-auth==2.13.0
|
| 24 |
+
google-auth-oauthlib==0.4.6
|
| 25 |
+
grpcio==1.50.0
|
| 26 |
+
hydra-core==1.2.0
|
| 27 |
+
idna==3.4
|
| 28 |
+
imageio==2.22.2
|
| 29 |
+
importlib-metadata==5.0.0
|
| 30 |
+
importlib-resources==5.10.0
|
| 31 |
+
imutils==0.5.4
|
| 32 |
+
iopath==0.1.9
|
| 33 |
+
ipython==8.5.0
|
| 34 |
+
jedi==0.17.2
|
| 35 |
+
kiwisolver==1.4.4
|
| 36 |
+
Markdown==3.4.1
|
| 37 |
+
MarkupSafe==2.1.1
|
| 38 |
+
matplotlib==3.6.1
|
| 39 |
+
matplotlib-inline==0.1.6
|
| 40 |
+
mypy-extensions==0.4.3
|
| 41 |
+
networkx==2.8.7
|
| 42 |
+
ninja==1.10.2.4
|
| 43 |
+
nptyping==2.3.1
|
| 44 |
+
numpy==1.23.4
|
| 45 |
+
oauthlib==3.2.2
|
| 46 |
+
omegaconf==2.2.3
|
| 47 |
+
opencv-python==4.6.0.66
|
| 48 |
+
packaging==21.3
|
| 49 |
+
pandas==1.5.1
|
| 50 |
+
parso==0.7.1
|
| 51 |
+
pathspec==0.10.1
|
| 52 |
+
pexpect==4.8.0
|
| 53 |
+
pickleshare==0.7.5
|
| 54 |
+
Pillow==9.2.0
|
| 55 |
+
pipenv==2022.10.12
|
| 56 |
+
platformdirs==2.5.2
|
| 57 |
+
portalocker==2.6.0
|
| 58 |
+
prompt-toolkit==3.0.31
|
| 59 |
+
protobuf==3.19.6
|
| 60 |
+
ptyprocess==0.7.0
|
| 61 |
+
pure-eval==0.2.2
|
| 62 |
+
pyasn1==0.4.8
|
| 63 |
+
pyasn1-modules==0.2.8
|
| 64 |
+
pycallgraph==1.0.1
|
| 65 |
+
pycocotools==2.0.5
|
| 66 |
+
pydot==1.4.2
|
| 67 |
+
pyenchant==3.2.2
|
| 68 |
+
Pygments==2.13.0
|
| 69 |
+
pynrrd==1.0.0
|
| 70 |
+
pyparsing==3.0.9
|
| 71 |
+
PySide6==6.4.0
|
| 72 |
+
PySide6-Addons==6.4.0
|
| 73 |
+
PySide6-Essentials==6.4.0
|
| 74 |
+
pytesseract==0.3.10
|
| 75 |
+
python-dateutil==2.8.2
|
| 76 |
+
pytz==2022.5
|
| 77 |
+
PyWavelets==1.4.1
|
| 78 |
+
PyYAML==6.0
|
| 79 |
+
regex==2022.9.13
|
| 80 |
+
requests==2.28.1
|
| 81 |
+
requests-oauthlib==1.3.1
|
| 82 |
+
rsa==4.9
|
| 83 |
+
scikit-image==0.19.3
|
| 84 |
+
scipy==1.9.2
|
| 85 |
+
shiboken6==6.4.0
|
| 86 |
+
six==1.16.0
|
| 87 |
+
stack-data==0.5.1
|
| 88 |
+
tabulate==0.9.0
|
| 89 |
+
tensorboard==2.10.1
|
| 90 |
+
tensorboard-data-server==0.6.1
|
| 91 |
+
tensorboard-plugin-wit==1.8.1
|
| 92 |
+
termcolor==2.0.1
|
| 93 |
+
tifffile==2022.10.10
|
| 94 |
+
toml==0.10.2
|
| 95 |
+
tqdm==4.64.1
|
| 96 |
+
traitlets==5.5.0
|
| 97 |
+
typing_extensions==4.4.0
|
| 98 |
+
urllib3==1.26.12
|
| 99 |
+
virtualenv==20.16.5
|
| 100 |
+
virtualenv-clone==0.5.7
|
| 101 |
+
wcwidth==0.2.5
|
| 102 |
+
Werkzeug==2.2.2
|
| 103 |
+
yacs==0.1.8
|
| 104 |
+
zipp==3.9.0
|
| 105 |
+
detectron2
|
| 106 |
+
-f https://dl.fbaipublicfiles.com/detectron2/wheels/cpu/torch1.10/index.html
|