ivelin commited on
Commit
dedc746
1 Parent(s): 186c0c1

fix: cleanup

Browse files

Signed-off-by: ivelin <ivelin.eth@gmail.com>

Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -16,13 +16,16 @@ model.to(device)
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,9 +56,9 @@ def process_refexp(image: Image, prompt: str):
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,7 +73,7 @@ def process_refexp(image: Image, prompt: str):
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
 
 
16
 
17
  def process_refexp(image: Image, prompt: str):
18
 
19
+ # extract PIL image from Gradio Image component
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(pil_image, return_tensors="pt").pixel_values
29
 
30
  # prepare decoder inputs
31
  task_prompt = "<s_refexp><s_prompt>{user_input}</s_prompt><s_refexp>"
 
56
  bbox = processor.token2json(sequence)
57
  print(f"predicted bounding box: {bbox}")
58
 
59
+ print(f"image object: {pil_image}")
60
+ print(f"image size: {pil_image.size}")
61
+ width, height = pil_image.size
62
  print(f"image width, height: {width, height}")
63
  print(f"prompt: {sample['prompt']}")
64
 
 
73
  shape = [(xmin, ymin), (xmax, ymax)]
74
 
75
  # create rectangle image
76
+ img1 = ImageDraw.Draw(pil_image)
77
  img1.rectangle(shape, outline="green", width=5)
78
  return image, bbox
79