Spaces:
Sleeping
Sleeping
jhj0517
commited on
Commit
•
64b615e
1
Parent(s):
bc096a1
Add arg parser
Browse files
app.py
CHANGED
@@ -1,25 +1,28 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
from gradio_image_prompter import ImagePrompter
|
3 |
-
from gradio_image_prompter.image_prompter import PromptData
|
4 |
from typing import List, Dict, Optional, Union
|
5 |
import os
|
6 |
import yaml
|
7 |
|
8 |
from modules.sam_inference import SamInference
|
9 |
from modules.model_downloader import DEFAULT_MODEL_TYPE
|
10 |
-
from modules.paths import (OUTPUT_DIR, OUTPUT_PSD_DIR, SAM2_CONFIGS_DIR, TEMP_DIR, OUTPUT_FILTER_DIR)
|
11 |
from modules.utils import open_folder
|
12 |
from modules.constants import (AUTOMATIC_MODE, BOX_PROMPT_MODE, PIXELIZE_FILTER, COLOR_FILTER, DEFAULT_COLOR,
|
13 |
DEFAULT_PIXEL_SIZE, SOUND_FILE_EXT, IMAGE_FILE_EXT, VIDEO_FILE_EXT)
|
14 |
-
from modules.video_utils import
|
15 |
|
16 |
|
17 |
class App:
|
18 |
def __init__(self,
|
19 |
-
args
|
20 |
self.demo = gr.Blocks()
|
21 |
self.args = args
|
22 |
-
self.sam_inf = SamInference(
|
|
|
|
|
|
|
23 |
self.image_modes = [AUTOMATIC_MODE, BOX_PROMPT_MODE]
|
24 |
self.default_mode = BOX_PROMPT_MODE
|
25 |
self.filter_modes = [PIXELIZE_FILTER, COLOR_FILTER]
|
@@ -191,9 +194,23 @@ class App:
|
|
191 |
outputs=[vid_output, output_file])
|
192 |
btn_open_folder.click(fn=lambda: open_folder(OUTPUT_FILTER_DIR), inputs=None, outputs=None)
|
193 |
|
194 |
-
self.demo.queue().launch(
|
|
|
|
|
|
|
195 |
|
196 |
|
197 |
if __name__ == "__main__":
|
198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
demo.launch()
|
|
|
1 |
+
import argparse
|
2 |
import gradio as gr
|
3 |
from gradio_image_prompter import ImagePrompter
|
|
|
4 |
from typing import List, Dict, Optional, Union
|
5 |
import os
|
6 |
import yaml
|
7 |
|
8 |
from modules.sam_inference import SamInference
|
9 |
from modules.model_downloader import DEFAULT_MODEL_TYPE
|
10 |
+
from modules.paths import (OUTPUT_DIR, OUTPUT_PSD_DIR, SAM2_CONFIGS_DIR, TEMP_DIR, OUTPUT_FILTER_DIR, MODELS_DIR)
|
11 |
from modules.utils import open_folder
|
12 |
from modules.constants import (AUTOMATIC_MODE, BOX_PROMPT_MODE, PIXELIZE_FILTER, COLOR_FILTER, DEFAULT_COLOR,
|
13 |
DEFAULT_PIXEL_SIZE, SOUND_FILE_EXT, IMAGE_FILE_EXT, VIDEO_FILE_EXT)
|
14 |
+
from modules.video_utils import get_frames_from_dir
|
15 |
|
16 |
|
17 |
class App:
|
18 |
def __init__(self,
|
19 |
+
args: argparse.Namespace):
|
20 |
self.demo = gr.Blocks()
|
21 |
self.args = args
|
22 |
+
self.sam_inf = SamInference(
|
23 |
+
model_dir=self.args.model_dir,
|
24 |
+
output_dir=self.args.output_dir
|
25 |
+
)
|
26 |
self.image_modes = [AUTOMATIC_MODE, BOX_PROMPT_MODE]
|
27 |
self.default_mode = BOX_PROMPT_MODE
|
28 |
self.filter_modes = [PIXELIZE_FILTER, COLOR_FILTER]
|
|
|
194 |
outputs=[vid_output, output_file])
|
195 |
btn_open_folder.click(fn=lambda: open_folder(OUTPUT_FILTER_DIR), inputs=None, outputs=None)
|
196 |
|
197 |
+
self.demo.queue().launch(
|
198 |
+
inbrowser=self.args.inbrowser,
|
199 |
+
share=self.args.share
|
200 |
+
)
|
201 |
|
202 |
|
203 |
if __name__ == "__main__":
|
204 |
+
parser = argparse.ArgumentParser()
|
205 |
+
parser.add_argument('--model_dir', type=str, default=MODELS_DIR,
|
206 |
+
help='Model directory for segment-anything-2')
|
207 |
+
parser.add_argument('--output_dir', type=str, default=OUTPUT_DIR,
|
208 |
+
help='Output directory for the results')
|
209 |
+
parser.add_argument('--inbrowser', type=bool, default=True, nargs='?', const=True,
|
210 |
+
help='Whether to automatically start Gradio app or not')
|
211 |
+
parser.add_argument('--share', type=bool, default=True, nargs='?', const=False,
|
212 |
+
help='Whether to create a public link for the app or not')
|
213 |
+
args = parser.parse_args()
|
214 |
+
|
215 |
+
demo = App(args=args)
|
216 |
demo.launch()
|