Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
# Copyright (C) 2024-present Naver Corporation. All rights reserved.
|
| 3 |
+
# Licensed under CC BY-NC-SA 4.0 (non-commercial use only).
|
| 4 |
+
#
|
| 5 |
+
# --------------------------------------------------------
|
| 6 |
+
# gradio demo executable
|
| 7 |
+
# --------------------------------------------------------
|
| 8 |
+
import os
|
| 9 |
+
import torch
|
| 10 |
+
import tempfile
|
| 11 |
+
from contextlib import nullcontext
|
| 12 |
+
|
| 13 |
+
from mast3r.demo import get_args_parser, main_demo
|
| 14 |
+
|
| 15 |
+
from mast3r.model import AsymmetricMASt3R
|
| 16 |
+
from mast3r.utils.misc import hash_md5
|
| 17 |
+
|
| 18 |
+
import matplotlib.pyplot as pl
|
| 19 |
+
pl.ion()
|
| 20 |
+
|
| 21 |
+
torch.backends.cuda.matmul.allow_tf32 = True # for gpu >= Ampere and pytorch >= 1.12
|
| 22 |
+
|
| 23 |
+
if __name__ == '__main__':
|
| 24 |
+
parser = get_args_parser()
|
| 25 |
+
args = parser.parse_args()
|
| 26 |
+
|
| 27 |
+
if args.server_name is not None:
|
| 28 |
+
server_name = args.server_name
|
| 29 |
+
else:
|
| 30 |
+
server_name = '0.0.0.0' if args.local_network else '127.0.0.1'
|
| 31 |
+
|
| 32 |
+
if args.weights is not None:
|
| 33 |
+
weights_path = args.weights
|
| 34 |
+
else:
|
| 35 |
+
weights_path = "naver/" + args.model_name
|
| 36 |
+
|
| 37 |
+
model = AsymmetricMASt3R.from_pretrained(weights_path).to(args.device)
|
| 38 |
+
chkpt_tag = hash_md5(weights_path)
|
| 39 |
+
|
| 40 |
+
def get_context(tmp_dir):
|
| 41 |
+
return tempfile.TemporaryDirectory(suffix='_mast3r_gradio_demo') if tmp_dir is None \
|
| 42 |
+
else nullcontext(tmp_dir)
|
| 43 |
+
with get_context(args.tmp_dir) as tmpdirname:
|
| 44 |
+
cache_path = os.path.join(tmpdirname, chkpt_tag)
|
| 45 |
+
os.makedirs(cache_path, exist_ok=True)
|
| 46 |
+
main_demo(cache_path, model, args.device, args.image_size, server_name, args.server_port, silent=args.silent,
|
| 47 |
+
share=args.share, gradio_delete_cache=args.gradio_delete_cache)
|