SkalskiP commited on
Commit
f6e3ce8
1 Parent(s): 9a267de

:tada: initial commit

Browse files
Files changed (4) hide show
  1. .gitignore +2 -0
  2. README.md +3 -3
  3. app.py +98 -0
  4. requirements.txt +7 -0
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ .idea/
2
+ venv/
README.md CHANGED
@@ -1,10 +1,10 @@
1
  ---
2
  title: SoM
3
- emoji: 🐠
4
- colorFrom: purple
5
  colorTo: yellow
6
  sdk: gradio
7
- sdk_version: 4.4.1
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
1
  ---
2
  title: SoM
3
+ emoji: 👁
4
+ colorFrom: pink
5
  colorTo: yellow
6
  sdk: gradio
7
+ sdk_version: 3.50.2
8
  app_file: app.py
9
  pinned: false
10
  license: mit
app.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from detectron2.data import MetadataCatalog
4
+ from segment_anything import SamAutomaticMaskGenerator
5
+
6
+
7
+ metadata = MetadataCatalog.get('coco_2017_train_panoptic')
8
+ print(metadata)
9
+
10
+
11
+ class ImageMask(gr.components.Image):
12
+ """
13
+ Sets: source="canvas", tool="sketch"
14
+ """
15
+
16
+ is_template = True
17
+
18
+ def __init__(self, **kwargs):
19
+ super().__init__(source="upload", tool="sketch", interactive=True, **kwargs)
20
+
21
+ def preprocess(self, x):
22
+ return super().preprocess(x)
23
+
24
+
25
+ demo = gr.Blocks()
26
+ image = ImageMask(
27
+ label="Input",
28
+ type="pil",
29
+ brush_radius=20.0,
30
+ brush_color="#FFFFFF")
31
+ slider = gr.Slider(
32
+ minimum=1,
33
+ maximum=3,
34
+ value=2,
35
+ label="Granularity",
36
+ info="Choose in [1, 1.5), [1.5, 2.5), [2.5, 3] for [seem, semantic-sam (multi-level), sam]")
37
+ mode = gr.Radio(
38
+ choices=['Automatic', 'Interactive', ],
39
+ value='Automatic',
40
+ label="Segmentation Mode")
41
+ image_out = gr.Image(label="Auto generation", type="pil")
42
+ slider_alpha = gr.Slider(
43
+ minimum=0,
44
+ maximum=1,
45
+ value=0.1,
46
+ label="Mask Alpha",
47
+ info="Choose in [0, 1]")
48
+ label_mode = gr.Radio(
49
+ choices=['Number', 'Alphabet'],
50
+ value='Number',
51
+ label="Mark Mode")
52
+ anno_mode = gr.CheckboxGroup(
53
+ choices=["Mask", "Box", "Mark"],
54
+ value=['Mask', 'Mark'],
55
+ label="Annotation Mode")
56
+ runBtn = gr.Button("Run")
57
+
58
+ title = "Set-of-Mark (SoM) Prompting for Visual Grounding in GPT-4V"
59
+ description = "This is a demo for SoM Prompting to unleash extraordinary visual grounding in GPT-4V. Please upload an image and them click the 'Run' button to get the image with marks. Then try it on <a href='https://chat.openai.com/'>GPT-4V<a>!"
60
+
61
+ with demo:
62
+ gr.Markdown(f"<h1 style='text-align: center;'>{title}</h1>")
63
+ gr.Markdown("<h3 style='text-align: center; margin-bottom: 1rem'>project: <a href='https://som-gpt4v.github.io/'>link</a>, arXiv: <a href='https://arxiv.org/abs/2310.11441'>link</a>, code: <a href='https://github.com/microsoft/SoM'>link</a></h3>")
64
+ gr.Markdown(f"<h3 style='margin-bottom: 1rem'>{description}</h3>")
65
+ with gr.Row():
66
+ with gr.Column():
67
+ image.render()
68
+ slider.render()
69
+ with gr.Row():
70
+ mode.render()
71
+ anno_mode.render()
72
+ with gr.Row():
73
+ slider_alpha.render()
74
+ label_mode.render()
75
+ with gr.Column():
76
+ image_out.render()
77
+ runBtn.render()
78
+ # with gr.Row():
79
+ # example = gr.Examples(
80
+ # examples=[
81
+ # ["examples/ironing_man.jpg"],
82
+ # ],
83
+ # inputs=image,
84
+ # cache_examples=False,
85
+ # )
86
+ # example = gr.Examples(
87
+ # examples=[
88
+ # ["examples/ironing_man_som.png"],
89
+ # ],
90
+ # inputs=image,
91
+ # cache_examples=False,
92
+ # label='Marked Examples',
93
+ # )
94
+
95
+ # runBtn.click(inference, inputs=[image, slider, mode, slider_alpha, label_mode, anno_mode],
96
+ # outputs = image_out)
97
+
98
+ demo.queue().launch()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ torch
2
+ torchvision
3
+ supervision
4
+
5
+ gradio==3.50.2
6
+ git+https://github.com/facebookresearch/segment-anything.git
7
+ # git+https://github.com/facebookresearch/detectron2.git