jhj0517 commited on
Commit
e8bad6c
1 Parent(s): b0fa820

Update input with mode dropdown

Browse files
Files changed (1) hide show
  1. app.py +20 -4
app.py CHANGED
@@ -1,10 +1,12 @@
1
  import gradio as gr
 
2
  import os
3
 
4
  from modules.sam_inference import SamInference
5
  from modules.model_downloader import DEFAULT_MODEL_TYPE
6
  from modules.paths import OUTPUT_DIR
7
  from modules.utils import open_folder
 
8
 
9
 
10
  class App:
@@ -13,18 +15,28 @@ class App:
13
  self.app = gr.Blocks()
14
  self.args = args
15
  self.sam_inf = SamInference()
16
- self.image_modes = ["Automatic", "Box Prompt"]
17
- self.default_mode = self.image_modes[0]
 
 
 
 
 
 
 
 
18
 
19
  def launch(self):
20
  with self.app:
21
  with gr.Row():
22
  with gr.Column(scale=5):
23
  img_input = gr.Image(label="Input image here")
 
 
24
 
25
  with gr.Column(scale=5):
26
- dd_modes = gr.Dropdown(label="Mode", value=self.default_mode,
27
- choices=self.image_modes)
28
  dd_models = gr.Dropdown(label="Model", value=DEFAULT_MODEL_TYPE,
29
  choices=self.sam_inf.available_models)
30
 
@@ -64,6 +76,10 @@ class App:
64
  btn_open_folder.click(fn=lambda: open_folder(os.path.join(OUTPUT_DIR)),
65
  inputs=None, outputs=None)
66
 
 
 
 
 
67
  self.app.queue().launch(inbrowser=True)
68
 
69
 
 
1
  import gradio as gr
2
+ from gradio_image_prompter import ImagePrompter
3
  import os
4
 
5
  from modules.sam_inference import SamInference
6
  from modules.model_downloader import DEFAULT_MODEL_TYPE
7
  from modules.paths import OUTPUT_DIR
8
  from modules.utils import open_folder
9
+ from modules.constants import (AUTOMATIC_MODE, BOX_PROMPT_MODE)
10
 
11
 
12
  class App:
 
15
  self.app = gr.Blocks()
16
  self.args = args
17
  self.sam_inf = SamInference()
18
+ self.image_modes = [AUTOMATIC_MODE, BOX_PROMPT_MODE]
19
+ self.default_mode = AUTOMATIC_MODE
20
+
21
+ @staticmethod
22
+ def on_mode_change(mode: str):
23
+ return [
24
+ gr.Image(visible=mode == AUTOMATIC_MODE),
25
+ ImagePrompter(visible=mode == BOX_PROMPT_MODE),
26
+ gr.Accordion(visible=mode == AUTOMATIC_MODE)
27
+ ]
28
 
29
  def launch(self):
30
  with self.app:
31
  with gr.Row():
32
  with gr.Column(scale=5):
33
  img_input = gr.Image(label="Input image here")
34
+ img_input_prompter = ImagePrompter(label="Prompt image with Box & Point",
35
+ visible=self.default_mode == BOX_PROMPT_MODE)
36
 
37
  with gr.Column(scale=5):
38
+ dd_input_modes = gr.Dropdown(label="Image Input Mode", value=self.default_mode,
39
+ choices=self.image_modes)
40
  dd_models = gr.Dropdown(label="Model", value=DEFAULT_MODEL_TYPE,
41
  choices=self.sam_inf.available_models)
42
 
 
76
  btn_open_folder.click(fn=lambda: open_folder(os.path.join(OUTPUT_DIR)),
77
  inputs=None, outputs=None)
78
 
79
+ dd_input_modes.change(fn=self.on_mode_change,
80
+ inputs=[dd_input_modes],
81
+ outputs=[img_input, img_input_prompter, mask_hparams])
82
+
83
  self.app.queue().launch(inbrowser=True)
84
 
85