Bohui Zhang
commited on
Commit
·
ffc83ec
1
Parent(s):
95a5083
Add markdown render for chatbot
Browse files- app.py +1 -0
- esgen/functions.py +8 -8
- esgen/verbalizer.py +3 -8
app.py
CHANGED
|
@@ -111,6 +111,7 @@ with gr.Blocks() as generate_tab:
|
|
| 111 |
label="Chatbot",
|
| 112 |
value=[[None, None]],
|
| 113 |
height=420,
|
|
|
|
| 114 |
)
|
| 115 |
# chatbot_input = gr.Textbox(placeholder="Type your message here :)")
|
| 116 |
with gr.Row():
|
|
|
|
| 111 |
label="Chatbot",
|
| 112 |
value=[[None, None]],
|
| 113 |
height=420,
|
| 114 |
+
render_markdown=True,
|
| 115 |
)
|
| 116 |
# chatbot_input = gr.Textbox(placeholder="Type your message here :)")
|
| 117 |
with gr.Row():
|
esgen/functions.py
CHANGED
|
@@ -32,7 +32,7 @@ def entity_schema_generation(name, class_id, threshold, property_types):
|
|
| 32 |
|
| 33 |
def input_yes(es_json, history):
|
| 34 |
if not es_json["pending"]:
|
| 35 |
-
es =
|
| 36 |
es.load_es_json(es_json)
|
| 37 |
return str(es), es.__json__(), history
|
| 38 |
# add the pending property to properties
|
|
@@ -44,7 +44,7 @@ def input_yes(es_json, history):
|
|
| 44 |
"comment": init_comment_verbaliser(required_prop["label"], required_prop["frequency"])
|
| 45 |
}
|
| 46 |
es_json["properties"].append(constraint_dict)
|
| 47 |
-
es =
|
| 48 |
es.load_es_json(es_json)
|
| 49 |
try:
|
| 50 |
prop = es.pending[0]
|
|
@@ -60,7 +60,7 @@ def input_yes(es_json, history):
|
|
| 60 |
|
| 61 |
def input_optional(es_json, history):
|
| 62 |
if not es_json["pending"]:
|
| 63 |
-
es =
|
| 64 |
es.load_es_json(es_json)
|
| 65 |
return str(es), es.__json__(), history
|
| 66 |
# add the pending property to optional properties
|
|
@@ -72,7 +72,7 @@ def input_optional(es_json, history):
|
|
| 72 |
"comment": init_comment_verbaliser(optional_prop["label"], optional_prop["frequency"])
|
| 73 |
}
|
| 74 |
es_json["optional"].append(constraint_json)
|
| 75 |
-
es =
|
| 76 |
es.load_es_json(es_json)
|
| 77 |
try:
|
| 78 |
prop = es.pending[0]
|
|
@@ -88,7 +88,7 @@ def input_optional(es_json, history):
|
|
| 88 |
|
| 89 |
def input_no(es_json, history):
|
| 90 |
if not es_json["pending"]:
|
| 91 |
-
es =
|
| 92 |
es.load_es_json(es_json)
|
| 93 |
return str(es), es.__json__(), history
|
| 94 |
# add the pending property to rejected properties
|
|
@@ -100,7 +100,7 @@ def input_no(es_json, history):
|
|
| 100 |
"comment": init_comment_verbaliser(rejected_prop["label"])
|
| 101 |
}
|
| 102 |
es_json["rejected"].append(constraint_json)
|
| 103 |
-
es =
|
| 104 |
es.load_es_json(es_json)
|
| 105 |
try:
|
| 106 |
prop = es.pending[0]
|
|
@@ -116,12 +116,12 @@ def input_no(es_json, history):
|
|
| 116 |
|
| 117 |
def input_skip(es_json, history):
|
| 118 |
if not es_json["pending"]:
|
| 119 |
-
es =
|
| 120 |
es.load_es_json(es_json)
|
| 121 |
return str(es), es.__json__(), history
|
| 122 |
# add the pending property to skip properties
|
| 123 |
es_json["skip"].append(es_json["pending"].pop(0))
|
| 124 |
-
es =
|
| 125 |
es.load_es_json(es_json)
|
| 126 |
try:
|
| 127 |
prop = es.pending[0]
|
|
|
|
| 32 |
|
| 33 |
def input_yes(es_json, history):
|
| 34 |
if not es_json["pending"]:
|
| 35 |
+
es = NestedEntitySchema(name="")
|
| 36 |
es.load_es_json(es_json)
|
| 37 |
return str(es), es.__json__(), history
|
| 38 |
# add the pending property to properties
|
|
|
|
| 44 |
"comment": init_comment_verbaliser(required_prop["label"], required_prop["frequency"])
|
| 45 |
}
|
| 46 |
es_json["properties"].append(constraint_dict)
|
| 47 |
+
es = NestedEntitySchema(name="")
|
| 48 |
es.load_es_json(es_json)
|
| 49 |
try:
|
| 50 |
prop = es.pending[0]
|
|
|
|
| 60 |
|
| 61 |
def input_optional(es_json, history):
|
| 62 |
if not es_json["pending"]:
|
| 63 |
+
es = NestedEntitySchema(name="")
|
| 64 |
es.load_es_json(es_json)
|
| 65 |
return str(es), es.__json__(), history
|
| 66 |
# add the pending property to optional properties
|
|
|
|
| 72 |
"comment": init_comment_verbaliser(optional_prop["label"], optional_prop["frequency"])
|
| 73 |
}
|
| 74 |
es_json["optional"].append(constraint_json)
|
| 75 |
+
es = NestedEntitySchema(name="")
|
| 76 |
es.load_es_json(es_json)
|
| 77 |
try:
|
| 78 |
prop = es.pending[0]
|
|
|
|
| 88 |
|
| 89 |
def input_no(es_json, history):
|
| 90 |
if not es_json["pending"]:
|
| 91 |
+
es = NestedEntitySchema(name="")
|
| 92 |
es.load_es_json(es_json)
|
| 93 |
return str(es), es.__json__(), history
|
| 94 |
# add the pending property to rejected properties
|
|
|
|
| 100 |
"comment": init_comment_verbaliser(rejected_prop["label"])
|
| 101 |
}
|
| 102 |
es_json["rejected"].append(constraint_json)
|
| 103 |
+
es = NestedEntitySchema(name="")
|
| 104 |
es.load_es_json(es_json)
|
| 105 |
try:
|
| 106 |
prop = es.pending[0]
|
|
|
|
| 116 |
|
| 117 |
def input_skip(es_json, history):
|
| 118 |
if not es_json["pending"]:
|
| 119 |
+
es = NestedEntitySchema(name="")
|
| 120 |
es.load_es_json(es_json)
|
| 121 |
return str(es), es.__json__(), history
|
| 122 |
# add the pending property to skip properties
|
| 123 |
es_json["skip"].append(es_json["pending"].pop(0))
|
| 124 |
+
es = NestedEntitySchema(name="")
|
| 125 |
es.load_es_json(es_json)
|
| 126 |
try:
|
| 127 |
prop = es.pending[0]
|
esgen/verbalizer.py
CHANGED
|
@@ -9,14 +9,9 @@ def init_comment_verbaliser(prop_label, freq=None):
|
|
| 9 |
def chatbot_verbaliser(prop_label, freq, examples):
|
| 10 |
message = f"{freq * 100:.2f}% instances within the class use the property '{prop_label}'. Here are examples:\n"
|
| 11 |
# verbalise examples
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
# f"{example['objectLabel']} [https://www.wikidata.org/wiki/{example['object']}]"
|
| 16 |
-
# for example in examples]
|
| 17 |
-
example_lines = [f"{example['subjectLabel']} ({example['subject']}), "
|
| 18 |
-
f"{example['propertyLabel']} ({example['property']}), "
|
| 19 |
-
f"{example['objectLabel']} ({example['object']})"
|
| 20 |
for example in examples]
|
| 21 |
examples_verbalised = '\n'.join([f"- {line}" for line in example_lines])
|
| 22 |
message += examples_verbalised
|
|
|
|
| 9 |
def chatbot_verbaliser(prop_label, freq, examples):
|
| 10 |
message = f"{freq * 100:.2f}% instances within the class use the property '{prop_label}'. Here are examples:\n"
|
| 11 |
# verbalise examples
|
| 12 |
+
example_lines = [f"{example['subjectLabel']} ([{example['subject']}](https://www.wikidata.org/wiki/{example['subject']})), "
|
| 13 |
+
f"{example['propertyLabel']} ([{example['property']}](https://www.wikidata.org/wiki/Property:{example['property']})), "
|
| 14 |
+
f"{example['objectLabel']} ([{example['object']}](https://www.wikidata.org/wiki/{example['object']}))"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
for example in examples]
|
| 16 |
examples_verbalised = '\n'.join([f"- {line}" for line in example_lines])
|
| 17 |
message += examples_verbalised
|