Spaces:
Runtime error
Runtime error
ivelin
commited on
Commit
·
a432919
1
Parent(s):
dedc746
fix: cleanup
Browse filesSigned-off-by: ivelin <ivelin.eth@gmail.com>
app.py
CHANGED
|
@@ -16,16 +16,13 @@ model.to(device)
|
|
| 16 |
|
| 17 |
def process_refexp(image: Image, prompt: str):
|
| 18 |
|
| 19 |
-
|
| 20 |
-
pil_image = image.value
|
| 21 |
-
|
| 22 |
-
print(f"(image, prompt): {pil_image}, {prompt}")
|
| 23 |
|
| 24 |
# trim prompt to 80 characters and normalize to lowercase
|
| 25 |
prompt = prompt[:80].lower()
|
| 26 |
|
| 27 |
# prepare encoder inputs
|
| 28 |
-
pixel_values = processor(
|
| 29 |
|
| 30 |
# prepare decoder inputs
|
| 31 |
task_prompt = "<s_refexp><s_prompt>{user_input}</s_prompt><s_refexp>"
|
|
@@ -56,9 +53,9 @@ def process_refexp(image: Image, prompt: str):
|
|
| 56 |
bbox = processor.token2json(sequence)
|
| 57 |
print(f"predicted bounding box: {bbox}")
|
| 58 |
|
| 59 |
-
print(f"image object: {
|
| 60 |
-
print(f"image size: {
|
| 61 |
-
width, height =
|
| 62 |
print(f"image width, height: {width, height}")
|
| 63 |
print(f"prompt: {sample['prompt']}")
|
| 64 |
|
|
@@ -73,7 +70,7 @@ def process_refexp(image: Image, prompt: str):
|
|
| 73 |
shape = [(xmin, ymin), (xmax, ymax)]
|
| 74 |
|
| 75 |
# create rectangle image
|
| 76 |
-
img1 = ImageDraw.Draw(
|
| 77 |
img1.rectangle(shape, outline="green", width=5)
|
| 78 |
return image, bbox
|
| 79 |
|
|
@@ -85,8 +82,8 @@ examples = [["example_1.jpg", "select the setting icon from top right corner"],
|
|
| 85 |
["example_2.jpg", "enter the text field next to the name"]]
|
| 86 |
|
| 87 |
demo = gr.Interface(fn=process_refexp,
|
| 88 |
-
inputs=["
|
| 89 |
-
outputs=["
|
| 90 |
title=title,
|
| 91 |
description=description,
|
| 92 |
article=article,
|
|
|
|
| 16 |
|
| 17 |
def process_refexp(image: Image, prompt: str):
|
| 18 |
|
| 19 |
+
print(f"(image, prompt): {image}, {prompt}")
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# trim prompt to 80 characters and normalize to lowercase
|
| 22 |
prompt = prompt[:80].lower()
|
| 23 |
|
| 24 |
# prepare encoder inputs
|
| 25 |
+
pixel_values = processor(image, return_tensors="pt").pixel_values
|
| 26 |
|
| 27 |
# prepare decoder inputs
|
| 28 |
task_prompt = "<s_refexp><s_prompt>{user_input}</s_prompt><s_refexp>"
|
|
|
|
| 53 |
bbox = processor.token2json(sequence)
|
| 54 |
print(f"predicted bounding box: {bbox}")
|
| 55 |
|
| 56 |
+
print(f"image object: {image}")
|
| 57 |
+
print(f"image size: {image.size}")
|
| 58 |
+
width, height = image.size
|
| 59 |
print(f"image width, height: {width, height}")
|
| 60 |
print(f"prompt: {sample['prompt']}")
|
| 61 |
|
|
|
|
| 70 |
shape = [(xmin, ymin), (xmax, ymax)]
|
| 71 |
|
| 72 |
# create rectangle image
|
| 73 |
+
img1 = ImageDraw.Draw(image)
|
| 74 |
img1.rectangle(shape, outline="green", width=5)
|
| 75 |
return image, bbox
|
| 76 |
|
|
|
|
| 82 |
["example_2.jpg", "enter the text field next to the name"]]
|
| 83 |
|
| 84 |
demo = gr.Interface(fn=process_refexp,
|
| 85 |
+
inputs=[gr.Image(type="pil"), "text"],
|
| 86 |
+
outputs=[gr.Image(type="pil"), "json"],
|
| 87 |
title=title,
|
| 88 |
description=description,
|
| 89 |
article=article,
|