Spaces:
Sleeping
Sleeping
adding "fluency-version output"
Browse files
app.py
CHANGED
|
@@ -60,10 +60,24 @@ def ner(text):
|
|
| 60 |
for entity in output:
|
| 61 |
entity['entity'] = entity.pop('entity_group')
|
| 62 |
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
-
return {'text': text, 'entities': output}
|
| 67 |
|
| 68 |
examples = ['Tôi cần thuê à tôi muốn bay một chuyến khứ hồi từ Đà Nẵng đến Đà Lạt',
|
| 69 |
'Giá vé một chiều à không khứ hồi từ Đà Nẵng đến Vinh dưới 2 triệu đồng giá vé khứ hồi từ Quy Nhơn đến Vinh dưới 3 triệu đồng giá vé khứ hồi từ Buôn Ma Thuột đến Quy Nhơn à đến Vinh dưới 4 triệu rưỡi',
|
|
@@ -74,19 +88,11 @@ examples = ['Tôi cần thuê à tôi muốn bay một chuyến khứ hồi từ
|
|
| 74 |
|
| 75 |
demo = gr.Interface(ner,
|
| 76 |
gr.Textbox(label='Sentence', placeholder="Enter your sentence here..."),
|
| 77 |
-
outputs=gr.HighlightedText(label='Highlighted Output'),
|
| 78 |
examples=examples,
|
| 79 |
title="Disfluency Detection",
|
| 80 |
description="This is an easy-to-use built in Gradio for desmontrating a NER System that identifies disfluency-entities in \
|
| 81 |
Vietnamese utterances",
|
| 82 |
theme=gr.themes.Soft())
|
| 83 |
|
| 84 |
-
demo.launch()
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
|
|
|
| 60 |
for entity in output:
|
| 61 |
entity['entity'] = entity.pop('entity_group')
|
| 62 |
|
| 63 |
+
# Remove Disfluency-entities to return a sentence with "Fluency" version
|
| 64 |
+
list_str = list(text)
|
| 65 |
+
|
| 66 |
+
for entity in output[::-1]: # if we use default order of output list, we will shorten the length of the sentence, so the words later are not in the correct start and end index
|
| 67 |
+
start = max(0, entity['start'] - 1)
|
| 68 |
+
end = min(len(list_str), entity['end'] + 1)
|
| 69 |
+
|
| 70 |
+
list_str[start:end] = ' '
|
| 71 |
+
|
| 72 |
+
fluency_sentence = "".join(list_str).strip().capitalize() # use strip() in case we need to remove entity at the beginning or the end of sentence
|
| 73 |
+
# (without strip(): "Giá vé khứ hồi à nhầm giá vé một chiều ..." -> " giá vé một chiều ...")
|
| 74 |
|
| 75 |
+
# Replace words like "Đà_Nẵng" to "Đà Nẵng"
|
| 76 |
+
text = text.replace("_", " ")
|
| 77 |
+
fluency_sentence = fluency_sentence.replace("_", " ")
|
| 78 |
+
|
| 79 |
|
| 80 |
+
return {'text': text, 'entities': output}, fluency_sentence
|
| 81 |
|
| 82 |
examples = ['Tôi cần thuê à tôi muốn bay một chuyến khứ hồi từ Đà Nẵng đến Đà Lạt',
|
| 83 |
'Giá vé một chiều à không khứ hồi từ Đà Nẵng đến Vinh dưới 2 triệu đồng giá vé khứ hồi từ Quy Nhơn đến Vinh dưới 3 triệu đồng giá vé khứ hồi từ Buôn Ma Thuột đến Quy Nhơn à đến Vinh dưới 4 triệu rưỡi',
|
|
|
|
| 88 |
|
| 89 |
demo = gr.Interface(ner,
|
| 90 |
gr.Textbox(label='Sentence', placeholder="Enter your sentence here..."),
|
| 91 |
+
outputs=[gr.HighlightedText(label='Highlighted Output'), gr.Textbox(label='"Fluency" version')],
|
| 92 |
examples=examples,
|
| 93 |
title="Disfluency Detection",
|
| 94 |
description="This is an easy-to-use built in Gradio for desmontrating a NER System that identifies disfluency-entities in \
|
| 95 |
Vietnamese utterances",
|
| 96 |
theme=gr.themes.Soft())
|
| 97 |
|
| 98 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|