merterbak commited on
Commit
cf3c6a4
·
verified ·
1 Parent(s): bc6d7c7

Remove line for labels

Browse files
Files changed (1) hide show
  1. app.py +4 -7
app.py CHANGED
@@ -80,7 +80,7 @@ def draw_bounding_boxes(image, refs, extract_images=False):
80
  img_draw.paste(overlay, (0, 0), overlay)
81
  return img_draw, crops
82
 
83
- def clean_output(text, include_images=False, remove_labels=False):
84
  if not text:
85
  return ""
86
  pattern = r'(<\|ref\|>(.*?)<\|/ref\|><\|det\|>(.*?)<\|/det\|>)'
@@ -95,10 +95,7 @@ def clean_output(text, include_images=False, remove_labels=False):
95
  else:
96
  text = text.replace(match[0], '', 1)
97
  else:
98
- if remove_labels:
99
- text = text.replace(match[0], '', 1)
100
- else:
101
- text = text.replace(match[0], match[1], 1)
102
 
103
  return text.strip()
104
 
@@ -156,8 +153,8 @@ def process_image(image, mode, task, custom_prompt):
156
  if not result:
157
  return "No text", "", "", None, []
158
 
159
- cleaned = clean_output(result, include_images=False, remove_labels=True)
160
- markdown = clean_output(result, include_images=True, remove_labels=True)
161
 
162
  img_out = None
163
  crops = []
 
80
  img_draw.paste(overlay, (0, 0), overlay)
81
  return img_draw, crops
82
 
83
+ def clean_output(text, include_images=False):
84
  if not text:
85
  return ""
86
  pattern = r'(<\|ref\|>(.*?)<\|/ref\|><\|det\|>(.*?)<\|/det\|>)'
 
95
  else:
96
  text = text.replace(match[0], '', 1)
97
  else:
98
+ text = re.sub(rf'(?m)^[^\n]*{re.escape(match[0])}[^\n]*\n?', '', text)
 
 
 
99
 
100
  return text.strip()
101
 
 
153
  if not result:
154
  return "No text", "", "", None, []
155
 
156
+ cleaned = clean_output(result, False)
157
+ markdown = clean_output(result, True)
158
 
159
  img_out = None
160
  crops = []