Spaces:
Running
on
Zero
Running
on
Zero
change layout
Browse files
app.py
CHANGED
@@ -41,7 +41,7 @@ def infer(
|
|
41 |
##### Also returns bounding boxes with their labels
|
42 |
|
43 |
def parse_segmentation(input_image, input_text):
|
44 |
-
out = infer(input_image, input_text, max_new_tokens=
|
45 |
objs = extract_objs(out.lstrip("\n"), input_image.size[0], input_image.size[1], unique_labels=True)
|
46 |
labels = set(obj.get('name') for obj in objs if obj.get('name'))
|
47 |
color_map = {l: COLORS[i % len(COLORS)] for i, l in enumerate(labels)}
|
@@ -83,20 +83,21 @@ for detailed information how to use and fine-tune PaliGemma models.
|
|
83 |
"""
|
84 |
|
85 |
|
86 |
-
with gr.Blocks(css="style.css") as demo:
|
87 |
gr.Markdown(INTRO_TEXT)
|
88 |
with gr.Tab("Text Generation"):
|
89 |
-
with gr.
|
90 |
-
|
|
|
91 |
text_input = gr.Text(label="Input Text")
|
92 |
-
|
93 |
text_output = gr.Text(label="Text Output")
|
94 |
-
|
95 |
-
|
96 |
label="Max New Tokens",
|
97 |
info="Set to larger for longer generation.",
|
98 |
minimum=10,
|
99 |
-
maximum=
|
100 |
value=20,
|
101 |
step=10,
|
102 |
)
|
@@ -134,15 +135,19 @@ with gr.Blocks(css="style.css") as demo:
|
|
134 |
inputs=chat_inputs,
|
135 |
)
|
136 |
with gr.Tab("Segment/Detect"):
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
|
|
|
|
|
|
141 |
|
142 |
-
examples = [["./examples/
|
|
|
143 |
["./examples/bee.jpg", "detect bee"],
|
144 |
["./examples/barsik.jpg", "segment cat"],
|
145 |
-
|
146 |
gr.Markdown("Example images are licensed CC0 by [akolesnikoff@](https://github.com/akolesnikoff), [mbosnjak@](https://github.com/mbosnjak), [maximneumann@](https://github.com/maximneumann) and [merve](https://huggingface.co/merve).")
|
147 |
gr.Examples(
|
148 |
examples=examples,
|
|
|
41 |
##### Also returns bounding boxes with their labels
|
42 |
|
43 |
def parse_segmentation(input_image, input_text):
|
44 |
+
out = infer(input_image, input_text, max_new_tokens=200)
|
45 |
objs = extract_objs(out.lstrip("\n"), input_image.size[0], input_image.size[1], unique_labels=True)
|
46 |
labels = set(obj.get('name') for obj in objs if obj.get('name'))
|
47 |
color_map = {l: COLORS[i % len(COLORS)] for i, l in enumerate(labels)}
|
|
|
83 |
"""
|
84 |
|
85 |
|
86 |
+
with gr.Blocks(theme=gr.themes.Soft(),css="style.css") as demo:
|
87 |
gr.Markdown(INTRO_TEXT)
|
88 |
with gr.Tab("Text Generation"):
|
89 |
+
with gr.Row():
|
90 |
+
with gr.Column():
|
91 |
+
image = gr.Image(type="pil", width=512, height=512)
|
92 |
text_input = gr.Text(label="Input Text")
|
93 |
+
with gr.Column():
|
94 |
text_output = gr.Text(label="Text Output")
|
95 |
+
chat_btn = gr.Button()
|
96 |
+
tokens = gr.Slider(
|
97 |
label="Max New Tokens",
|
98 |
info="Set to larger for longer generation.",
|
99 |
minimum=10,
|
100 |
+
maximum=200,
|
101 |
value=20,
|
102 |
step=10,
|
103 |
)
|
|
|
135 |
inputs=chat_inputs,
|
136 |
)
|
137 |
with gr.Tab("Segment/Detect"):
|
138 |
+
with gr.Row():
|
139 |
+
with gr.Column():
|
140 |
+
image = gr.Image(type="pil")
|
141 |
+
seg_input = gr.Text(label="Entities to Segment/Detect")
|
142 |
+
seg_btn = gr.Button("Submit")
|
143 |
+
with gr.Column():
|
144 |
+
annotated_image = gr.AnnotatedImage(label="Output")
|
145 |
|
146 |
+
examples = [["./examples/venice.jpg", "detect bird"],
|
147 |
+
["./examples/cats.png", "segment cats"],
|
148 |
["./examples/bee.jpg", "detect bee"],
|
149 |
["./examples/barsik.jpg", "segment cat"],
|
150 |
+
]
|
151 |
gr.Markdown("Example images are licensed CC0 by [akolesnikoff@](https://github.com/akolesnikoff), [mbosnjak@](https://github.com/mbosnjak), [maximneumann@](https://github.com/maximneumann) and [merve](https://huggingface.co/merve).")
|
152 |
gr.Examples(
|
153 |
examples=examples,
|