-
Notifications
You must be signed in to change notification settings - Fork 881
/
Copy pathgradio_helper.py
33 lines (28 loc) · 1.07 KB
/
gradio_helper.py
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
from pathlib import Path
from typing import Callable
import gradio as gr
ground_dino_dir = Path("GroundingDINO")
def make_demo(fn: Callable):
with gr.Accordion("Advanced options", open=False) as advanced:
box_threshold = gr.Slider(label="Box Threshold", minimum=0.0, maximum=1.0, value=0.3, step=0.05)
text_threshold = gr.Slider(label="Text Threshold", minimum=0.0, maximum=1.0, value=0.25, step=0.05)
demo = gr.Interface(
fn=fn,
inputs=[
gr.Image(),
gr.Dropdown(["det", "seg"], value="seg", label="task_type"),
gr.Textbox(value="bears", label="Text Prompt"),
],
additional_inputs=[
box_threshold,
text_threshold,
],
outputs=gr.Gallery(preview=True, object_fit="scale-down"),
examples=[
[f"{ground_dino_dir}/.asset/demo2.jpg", "seg", "dog, forest"],
[f"{ground_dino_dir}/.asset/demo7.jpg", "seg", "horses and clouds"],
],
additional_inputs_accordion=advanced,
allow_flagging="never",
)
return demo