Spaces:
Runtime error
Runtime error
add input image component
Browse files
app.py
CHANGED
|
@@ -19,20 +19,26 @@ model = Magma.from_checkpoint(
|
|
| 19 |
device = 'cuda:0'
|
| 20 |
)
|
| 21 |
|
| 22 |
-
def generate(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()@:%_\+.~#?&//=]*)'
|
| 26 |
-
lines = context.split('\n')
|
| 27 |
-
inputs = []
|
| 28 |
-
for line in lines:
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
## returns a tensor of shape: (1, 149, 4096)
|
| 38 |
embeddings = model.preprocess_inputs(inputs)
|
|
@@ -50,10 +56,10 @@ def generate(context, length, temperature, top_k):
|
|
| 50 |
iface = gr.Interface(
|
| 51 |
fn=generate,
|
| 52 |
inputs=[
|
| 53 |
-
gr.inputs.Textbox(
|
| 54 |
-
label="Prompt
|
| 55 |
-
default="
|
| 56 |
-
lines=7),
|
| 57 |
gr.inputs.Slider(minimum=1, maximum=100, default=15, step=1, label="Output tokens:"),
|
| 58 |
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.7, label='Temperature'),
|
| 59 |
gr.inputs.Slider(minimum=0, maximum=100, default=0, step=1, label='Top K')
|
|
|
|
| 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()@:%_\+.~#?&//=]*)'
|
| 26 |
+
# lines = context.split('\n')
|
| 27 |
+
# inputs = []
|
| 28 |
+
# for line in lines:
|
| 29 |
+
# if re.match(url_regex, line):
|
| 30 |
+
# try:
|
| 31 |
+
# inputs.append(ImageInput(line))
|
| 32 |
+
# except Exception as e:
|
| 33 |
+
# return str(e)
|
| 34 |
+
# else:
|
| 35 |
+
# inputs.append(line)
|
| 36 |
+
|
| 37 |
+
inputs =[
|
| 38 |
+
## supports urls and path/to/image
|
| 39 |
+
ImageInput(image),
|
| 40 |
+
context
|
| 41 |
+
]
|
| 42 |
|
| 43 |
## returns a tensor of shape: (1, 149, 4096)
|
| 44 |
embeddings = model.preprocess_inputs(inputs)
|
|
|
|
| 56 |
iface = gr.Interface(
|
| 57 |
fn=generate,
|
| 58 |
inputs=[
|
| 59 |
+
[gr.inputs.Image(type="filepath"),gr.inputs.Textbox(
|
| 60 |
+
label="Prompt:",
|
| 61 |
+
default="Describe the painting:",
|
| 62 |
+
lines=7)],
|
| 63 |
gr.inputs.Slider(minimum=1, maximum=100, default=15, step=1, label="Output tokens:"),
|
| 64 |
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.7, label='Temperature'),
|
| 65 |
gr.inputs.Slider(minimum=0, maximum=100, default=0, step=1, label='Top K')
|