Spaces:
Paused
Paused
File size: 9,155 Bytes
884c49d c9faec3 884c49d 8595531 884c49d ba8c2bf 884c49d 8595531 884c49d f0573ed 884c49d ba8c2bf 884c49d f0573ed 884c49d 5e866ee aa4d6ec 5e866ee aa4d6ec 5e866ee aa4d6ec 5e866ee aa4d6ec 847ed7f 05fe745 aa4d6ec 5e866ee 884c49d aa4d6ec 592750c 8595531 592750c 884c49d 5e866ee 884c49d 8595531 884c49d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
import gradio as gr
from demo import automask_image_app, automask_video_app, sahi_autoseg_app
def image_app():
with gr.Blocks():
with gr.Row():
with gr.Column():
seg_automask_image_file = gr.Image(type="filepath").style(height=260)
with gr.Row():
with gr.Column():
seg_automask_image_model_type = gr.Dropdown(
choices=[
"vit_h",
"vit_l",
"vit_b",
],
value="vit_l",
label="Model Type",
)
seg_automask_image_points_per_side = gr.Slider(
minimum=0,
maximum=32,
step=2,
value=16,
label="Points per Side",
)
seg_automask_image_points_per_batch = gr.Slider(
minimum=0,
maximum=64,
step=2,
value=64,
label="Points per Batch",
)
seg_automask_image_min_area = gr.Number(
value=0,
label="Min Area",
)
seg_automask_image_predict = gr.Button(value="Generator")
with gr.Column():
output_image = gr.Image()
seg_automask_image_predict.click(
fn=automask_image_app,
inputs=[
seg_automask_image_file,
seg_automask_image_model_type,
seg_automask_image_points_per_side,
seg_automask_image_points_per_batch,
seg_automask_image_min_area,
],
outputs=[output_image],
)
def video_app():
with gr.Blocks():
with gr.Row():
with gr.Column():
seg_automask_video_file = gr.Video().style(height=260)
with gr.Row():
with gr.Column():
seg_automask_video_model_type = gr.Dropdown(
choices=[
"vit_h",
"vit_l",
"vit_b",
],
value="vit_l",
label="Model Type",
)
seg_automask_video_points_per_side = gr.Slider(
minimum=0,
maximum=32,
step=2,
value=16,
label="Points per Side",
)
seg_automask_video_points_per_batch = gr.Slider(
minimum=0,
maximum=64,
step=2,
value=64,
label="Points per Batch",
)
with gr.Row():
with gr.Column():
seg_automask_video_min_area = gr.Number(
value=1000,
label="Min Area",
)
seg_automask_video_predict = gr.Button(value="Generator")
with gr.Column():
output_video = gr.Video()
seg_automask_video_predict.click(
fn=automask_video_app,
inputs=[
seg_automask_video_file,
seg_automask_video_model_type,
seg_automask_video_points_per_side,
seg_automask_video_points_per_batch,
seg_automask_video_min_area,
],
outputs=[output_video],
)
def sahi_app():
with gr.Blocks():
with gr.Row():
with gr.Column():
sahi_image_file = gr.Image(type="filepath").style(height=260)
with gr.Row():
with gr.Column():
sahi_autoseg_model_type = gr.Dropdown(
choices=[
"vit_h",
"vit_l",
"vit_b",
],
value="vit_l",
label="Sam Model Type",
)
sahi_image_size = gr.Slider(
minimum=0,
maximum=1600,
step=32,
value=640,
label="Image Size",
)
sahi_conf_th = gr.Slider(
minimum=0,
maximum=1,
step=0.1,
value=0.2,
label="Confidence Threshold",
)
sahi_slice_width = gr.Slider(
minimum=0,
maximum=640,
step=32,
value=256,
label="Slice Width",
)
sahi_overlap_height = gr.Slider(
minimum=0,
maximum=1,
step=0.1,
value=0.2,
label="Overlap Height",
)
with gr.Row():
with gr.Column():
sahi_model_type = gr.Dropdown(
choices=[
"yolov5",
"yolov8",
],
value="yolov5",
label="Detector Model Type",
)
sahi_model_path = gr.Dropdown(
choices=[
"yolov5l.pt",
"yolov5l6.pt",
"yolov8l.pt",
"yolov8x.pt"
],
value="yolov5m",
label="Detector Model Path",
)
sahi_slice_height = gr.Slider(
minimum=0,
maximum=640,
step=32,
value=256,
label="Slice Height",
)
sahi_overlap_width = gr.Slider(
minimum=0,
maximum=1,
step=0.1,
value=0.2,
label="Overlap Width",
)
sahi_image_predict = gr.Button(value="Generator")
with gr.Column():
output_image = gr.Image()
sahi_image_predict.click(
fn=sahi_autoseg_app,
inputs=[
sahi_image_file,
sahi_autoseg_model_type,
sahi_model_type,
sahi_model_path,
sahi_conf_th,
sahi_image_size,
sahi_slice_height,
sahi_slice_width,
sahi_overlap_height,
sahi_overlap_width,
],
outputs=[output_image],
)
def metaseg_app():
app = gr.Blocks()
with app:
gr.Markdown("# **<h2 align='center'>Segment Anything + Video + SAHI</h2>**")
gr.Markdown(
"""
<h5 style='text-align: center'>
Follow me for more!
<a href='https://twitter.com/kadirnar_ai' target='_blank'>Twitter</a> | <a href='https://github.com/kadirnar' target='_blank'>Github</a> | <a href='https://www.linkedin.com/in/kadir-nar/' target='_blank'>Linkedin</a> |
</h5>
"""
)
with gr.Row():
with gr.Column():
with gr.Tab("Image"):
image_app()
with gr.Tab("Video"):
video_app()
with gr.Tab("SAHI"):
sahi_app()
app.queue(concurrency_count=1)
app.launch(debug=True, enable_queue=True)
if __name__ == "__main__":
metaseg_app()
|