Spaces:
Runtime error
Runtime error
Commit ·
f7b9192
1
Parent(s): da66d52
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,7 +38,7 @@ def convert_l2n_n2l(dataset):
|
|
| 38 |
return label_list, id2label, label2id, len(label_list)
|
| 39 |
|
| 40 |
def label_colour(label):
|
| 41 |
-
label2color =
|
| 42 |
if label in label2color:
|
| 43 |
colour = label2color.get(label)
|
| 44 |
else:
|
|
@@ -109,7 +109,15 @@ def predict(image):
|
|
| 109 |
words = text_extraction(image)
|
| 110 |
extracted_words = convert_results(words,true_predictions)
|
| 111 |
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
def text_extraction(image):
|
| 115 |
feature_extractor = LayoutLMv3FeatureExtractor()
|
|
@@ -120,7 +128,7 @@ css = """.output_image, .input_image {height: 600px !important}"""
|
|
| 120 |
|
| 121 |
demo = gr.Interface(fn = predict,
|
| 122 |
inputs = gr.inputs.Image(type="pil"),
|
| 123 |
-
outputs = [gr.outputs.Image(type="pil", label="annotated image"),'text'],
|
| 124 |
css = css,
|
| 125 |
examples = examples,
|
| 126 |
allow_flagging=True,
|
|
|
|
| 38 |
return label_list, id2label, label2id, len(label_list)
|
| 39 |
|
| 40 |
def label_colour(label):
|
| 41 |
+
label2color ={'MENU.PRICE':'blue','MENU.NM':'red','other':None,'MENU.NUM':'orange','TOTAL.TOTAL_PRICE':'green'}
|
| 42 |
if label in label2color:
|
| 43 |
colour = label2color.get(label)
|
| 44 |
else:
|
|
|
|
| 109 |
words = text_extraction(image)
|
| 110 |
extracted_words = convert_results(words,true_predictions)
|
| 111 |
|
| 112 |
+
menu_list = []
|
| 113 |
+
price_list = []
|
| 114 |
+
for idx,item in enumerate(final_result):
|
| 115 |
+
if item[1] == 'MENU.NM':
|
| 116 |
+
menu_list.append(f"item {idx}.{item[0]}")
|
| 117 |
+
if item[1] == 'MENU.PRICE':
|
| 118 |
+
price_list.append(f"item {idx}. ${item[0]}")
|
| 119 |
+
|
| 120 |
+
return image,menu_list,price_list
|
| 121 |
|
| 122 |
def text_extraction(image):
|
| 123 |
feature_extractor = LayoutLMv3FeatureExtractor()
|
|
|
|
| 128 |
|
| 129 |
demo = gr.Interface(fn = predict,
|
| 130 |
inputs = gr.inputs.Image(type="pil"),
|
| 131 |
+
outputs = [gr.outputs.Image(type="pil", label="annotated image"),'text','text'],
|
| 132 |
css = css,
|
| 133 |
examples = examples,
|
| 134 |
allow_flagging=True,
|