Spaces:
Runtime error
Runtime error
add option for rearrange prompt
Browse files
app.py
CHANGED
|
@@ -19,7 +19,7 @@ model = Magma.from_checkpoint(
|
|
| 19 |
device = 'cuda:0'
|
| 20 |
)
|
| 21 |
|
| 22 |
-
def generate(image,context, length, temperature, top_k):
|
| 23 |
# context = context.strip()
|
| 24 |
|
| 25 |
# url_regex = r'https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)'
|
|
@@ -33,12 +33,18 @@ def generate(image,context, length, temperature, top_k):
|
|
| 33 |
# return str(e)
|
| 34 |
# else:
|
| 35 |
# inputs.append(line)
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
## returns a tensor of shape: (1, 149, 4096)
|
| 44 |
embeddings = model.preprocess_inputs(inputs)
|
|
@@ -53,7 +59,7 @@ def generate(image,context, length, temperature, top_k):
|
|
| 53 |
|
| 54 |
return output[0]
|
| 55 |
|
| 56 |
-
examples=[["woods_hi.jpeg","Describe the painting:",15,0.7,0]]
|
| 57 |
|
| 58 |
title="MAGMA"
|
| 59 |
description="MAGMA -- Multimodal Augmentation of Generative Models through Adapter-based Finetuning"
|
|
@@ -61,13 +67,14 @@ article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2112.052
|
|
| 61 |
iface = gr.Interface(
|
| 62 |
fn=generate,
|
| 63 |
inputs=[
|
| 64 |
-
gr.inputs.Image(type="filepath"),gr.inputs.Textbox(
|
| 65 |
-
label="Prompt:",
|
| 66 |
default="Describe the painting:",
|
| 67 |
lines=7),
|
| 68 |
gr.inputs.Slider(minimum=1, maximum=100, default=15, step=1, label="Output tokens:"),
|
| 69 |
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.7, label='Temperature'),
|
| 70 |
-
gr.inputs.Slider(minimum=0, maximum=100, default=0, step=1, label='Top K')
|
|
|
|
| 71 |
],
|
| 72 |
outputs=["textbox"],
|
| 73 |
examples=examples,
|
|
|
|
| 19 |
device = 'cuda:0'
|
| 20 |
)
|
| 21 |
|
| 22 |
+
def generate(image,context, length, temperature, top_k,rearrange):
|
| 23 |
# context = context.strip()
|
| 24 |
|
| 25 |
# url_regex = r'https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)'
|
|
|
|
| 33 |
# return str(e)
|
| 34 |
# else:
|
| 35 |
# inputs.append(line)
|
| 36 |
+
if rearrange:
|
| 37 |
+
inputs =[
|
| 38 |
+
## supports urls and path/to/image
|
| 39 |
+
context,
|
| 40 |
+
ImageInput(image)
|
| 41 |
+
]
|
| 42 |
+
else:
|
| 43 |
+
inputs =[
|
| 44 |
+
## supports urls and path/to/image
|
| 45 |
+
ImageInput(image),
|
| 46 |
+
context
|
| 47 |
+
]
|
| 48 |
|
| 49 |
## returns a tensor of shape: (1, 149, 4096)
|
| 50 |
embeddings = model.preprocess_inputs(inputs)
|
|
|
|
| 59 |
|
| 60 |
return output[0]
|
| 61 |
|
| 62 |
+
examples=[["woods_hi.jpeg","Describe the painting:",15,0.7,0,False]]
|
| 63 |
|
| 64 |
title="MAGMA"
|
| 65 |
description="MAGMA -- Multimodal Augmentation of Generative Models through Adapter-based Finetuning"
|
|
|
|
| 67 |
iface = gr.Interface(
|
| 68 |
fn=generate,
|
| 69 |
inputs=[
|
| 70 |
+
gr.inputs.Image(type="filepath",label="Image Prompt"),gr.inputs.Textbox(
|
| 71 |
+
label="Text Prompt:",
|
| 72 |
default="Describe the painting:",
|
| 73 |
lines=7),
|
| 74 |
gr.inputs.Slider(minimum=1, maximum=100, default=15, step=1, label="Output tokens:"),
|
| 75 |
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.7, label='Temperature'),
|
| 76 |
+
gr.inputs.Slider(minimum=0, maximum=100, default=0, step=1, label='Top K'),
|
| 77 |
+
gr.inputs.Checkbox(default=False, label="Rearrange Prompt", optional=False)
|
| 78 |
],
|
| 79 |
outputs=["textbox"],
|
| 80 |
examples=examples,
|