Spaces:
Sleeping
Sleeping
import gradio as gr | |
import re | |
from detector import AmbguityDetector | |
a=AmbguityDetector() | |
def update_array(array_a, array_b): | |
# Create a dictionary to store the mappings from the first value to the second value | |
mapping = {} | |
# Populate the dictionary using the tuples from array A | |
for a, b in array_a: | |
mapping[a] = b | |
# Iterate through the tuples in array B | |
for i, (a, b) in enumerate(array_b): | |
if b is None and a in mapping: | |
# Replace the tuple in array B with the value from array A | |
array_b[i] = (a, mapping[a]) | |
def amb_texts(text): | |
tokens = re.split(r'(\s+)', text) | |
# tokens = [token for token in tokens if token.strip() != ''] | |
ambs=a.sentence_ambiguity(text) | |
res=list() | |
for i in tokens: | |
res.append((i,None)) | |
update_array(ambs,res) | |
# print(tokens,text) | |
return res | |
def greet(name): | |
return "Hello " + name + "!!" | |
iface = gr.Interface(fn=amb_texts, inputs= [ | |
gr.Textbox( | |
label="Input", | |
info="Find ambiguities in the following", | |
lines=3, | |
value="The test can only continue if it receives all inputs from previous page.", | |
), | |
], outputs= gr.HighlightedText( | |
label="Ambiguity Detection", | |
combine_adjacent=True, | |
show_legend=True, | |
color_map={"lexical": "blue","scope":"yellow","referential":"orange","coordination":"pink","vague":"red"}), | |
theme=gr.themes.Base()) | |
iface.launch() | |