Spaces:
Sleeping
Sleeping
better interface
Browse files
app.py
CHANGED
@@ -12,6 +12,12 @@ model, _, transform = open_clip.create_model_and_transforms(
|
|
12 |
)
|
13 |
model.to(device)
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
def output_generate(image):
|
17 |
im = transform(image).unsqueeze(0).to(device)
|
@@ -34,17 +40,11 @@ def inference_caption(image, decoding_method="Beam search", rep_penalty=1.2, top
|
|
34 |
return open_clip.decode(generated[0].detach()).split("<end_of_text>")[0].replace("<start_of_text>", "")
|
35 |
|
36 |
paths = sorted(pathlib.Path("images").glob("*.jpg"))
|
37 |
-
with gr.Blocks(
|
38 |
-
css="""
|
39 |
-
.message.svelte-w6rprc.svelte-w6rprc.svelte-w6rprc {font-size: 20px; margin-top: 20px}
|
40 |
-
#component-21 > div.wrap.svelte-w6rprc {height: 600px;}
|
41 |
-
"""
|
42 |
-
) as iface:
|
43 |
state = gr.State([])
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
# gr.Markdown(article)
|
48 |
|
49 |
with gr.Row():
|
50 |
with gr.Column(scale=1):
|
@@ -70,7 +70,7 @@ with gr.Blocks(
|
|
70 |
top_p = gr.Slider(
|
71 |
minimum=0.0,
|
72 |
maximum=1.0,
|
73 |
-
value=
|
74 |
step=0.1,
|
75 |
interactive=True,
|
76 |
label="Top p (used with nucleus sampling)",
|
@@ -84,7 +84,7 @@ with gr.Blocks(
|
|
84 |
value=20, label="Maximum Sequence Length", precision=0, interactive=True
|
85 |
)
|
86 |
|
87 |
-
with gr.Column(scale=1
|
88 |
|
89 |
with gr.Column():
|
90 |
caption_output = gr.Textbox(lines=1, label="Caption Output")
|
@@ -116,4 +116,9 @@ with gr.Blocks(
|
|
116 |
# article="""""",
|
117 |
# examples=[path.as_posix() for path in paths],
|
118 |
# )
|
|
|
|
|
|
|
|
|
|
|
119 |
iface.launch()
|
|
|
12 |
)
|
13 |
model.to(device)
|
14 |
|
15 |
+
title="""<h1 align="center">CoCa: Contrastive Captioners</h1>"""
|
16 |
+
description=(
|
17 |
+
"""<br> An open source implementation of <strong>CoCa: Contrastive Captioners are Image-Text Foundation Models</strong> <a href=https://arxiv.org/abs/2205.01917>https://arxiv.org/abs/2205.01917.</a>
|
18 |
+
<br> Built using <a href=https://github.com/mlfoundations/open_clip>open_clip</a> with an effort from <a href=https://laion.ai/>LAION</a>.
|
19 |
+
<br> For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings.<a href="https://huggingface.co/spaces/laion/CoCa?duplicate=true"> <img style="margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>"""
|
20 |
+
)
|
21 |
|
22 |
def output_generate(image):
|
23 |
im = transform(image).unsqueeze(0).to(device)
|
|
|
40 |
return open_clip.decode(generated[0].detach()).split("<end_of_text>")[0].replace("<start_of_text>", "")
|
41 |
|
42 |
paths = sorted(pathlib.Path("images").glob("*.jpg"))
|
43 |
+
with gr.Blocks() as iface:
|
|
|
|
|
|
|
|
|
|
|
44 |
state = gr.State([])
|
45 |
|
46 |
+
gr.Markdown(title)
|
47 |
+
gr.Markdown(description)
|
|
|
48 |
|
49 |
with gr.Row():
|
50 |
with gr.Column(scale=1):
|
|
|
70 |
top_p = gr.Slider(
|
71 |
minimum=0.0,
|
72 |
maximum=1.0,
|
73 |
+
value=0.5,
|
74 |
step=0.1,
|
75 |
interactive=True,
|
76 |
label="Top p (used with nucleus sampling)",
|
|
|
84 |
value=20, label="Maximum Sequence Length", precision=0, interactive=True
|
85 |
)
|
86 |
|
87 |
+
with gr.Column(scale=1):
|
88 |
|
89 |
with gr.Column():
|
90 |
caption_output = gr.Textbox(lines=1, label="Caption Output")
|
|
|
116 |
# article="""""",
|
117 |
# examples=[path.as_posix() for path in paths],
|
118 |
# )
|
119 |
+
|
120 |
+
examples = gr.Examples(
|
121 |
+
examples=[path.as_posix() for path in paths],
|
122 |
+
inputs=[image_input],
|
123 |
+
)
|
124 |
iface.launch()
|