Spaces:
Running
Running
Synced repo using 'sync_with_huggingface' Github Action
Browse files- gradio_app.py +9 -4
gradio_app.py
CHANGED
@@ -1,9 +1,13 @@
|
|
1 |
import os
|
2 |
import sys
|
3 |
if "APP_PATH" in os.environ:
|
4 |
-
os.chdir(os.environ["APP_PATH"])
|
5 |
# fix sys.path for import
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
# here the subprocess stops loading, because __name__ is NOT '__main__'
|
9 |
# gradio will reload
|
@@ -60,8 +64,9 @@ if '__main__' == __name__:
|
|
60 |
# Load the model from the specified checkpoint
|
61 |
exp_dir = "checkpoints"
|
62 |
json_path = os.path.join(exp_dir, "params.json")
|
63 |
-
ckpt_path = os.
|
64 |
-
|
|
|
65 |
return wam
|
66 |
|
67 |
def image_detect(img_pil: Image.Image, scan_mult: bool=False, timeout_seconds: int=5) -> (torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor):
|
|
|
1 |
import os
|
2 |
import sys
|
3 |
if "APP_PATH" in os.environ:
|
|
|
4 |
# fix sys.path for import
|
5 |
+
os.chdir(os.environ["APP_PATH"])
|
6 |
+
if os.getcwd() not in sys.path:
|
7 |
+
sys.path.append(os.getcwd())
|
8 |
+
|
9 |
+
# remove duplicate gradio_app path from sys.path
|
10 |
+
sys.path = list(dict.fromkeys(sys.path))
|
11 |
|
12 |
# here the subprocess stops loading, because __name__ is NOT '__main__'
|
13 |
# gradio will reload
|
|
|
64 |
# Load the model from the specified checkpoint
|
65 |
exp_dir = "checkpoints"
|
66 |
json_path = os.path.join(exp_dir, "params.json")
|
67 |
+
ckpt_path = os.environ.get("CHECKPOINT_MODEL_PATH", exp_dir)
|
68 |
+
ckpt_file = os.path.join(ckpt_path, 'checkpoint.pth')
|
69 |
+
wam = load_model_from_checkpoint(json_path, ckpt_file).to(device).eval()
|
70 |
return wam
|
71 |
|
72 |
def image_detect(img_pil: Image.Image, scan_mult: bool=False, timeout_seconds: int=5) -> (torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor):
|