Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -113,45 +113,45 @@ if text_input:
|
|
113 |
|
114 |
combined_entity_info_dictionary = dict([(k, [entities_map[k], entities_data[k] if k in entities_data else None]) for k in entities_map])
|
115 |
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
|
120 |
-
|
121 |
-
|
122 |
"@context": "https://schema.org",
|
123 |
"@type": "WebPage",
|
124 |
"mentions": []
|
125 |
}
|
126 |
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
|
149 |
-
|
150 |
-
|
151 |
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
|
156 |
# Split the modified text_input into a list
|
157 |
text_list = text_input.split("{")
|
|
|
113 |
|
114 |
combined_entity_info_dictionary = dict([(k, [entities_map[k], entities_data[k] if k in entities_data else None]) for k in entities_map])
|
115 |
|
116 |
+
if submit_button:
|
117 |
+
# Prepare a list to hold the final output
|
118 |
+
final_text = []
|
119 |
|
120 |
+
# JSON-LD data
|
121 |
+
json_ld_data = {
|
122 |
"@context": "https://schema.org",
|
123 |
"@type": "WebPage",
|
124 |
"mentions": []
|
125 |
}
|
126 |
|
127 |
+
# Replace each entity in the text with its annotated version
|
128 |
+
for entity_string, entity_info in entities_map.items():
|
129 |
+
entity_data = entities_data.get(entity_string, None)
|
130 |
+
entity_type = None
|
131 |
+
if entity_data is not None:
|
132 |
+
entity_type = entity_data.get("@type", None)
|
133 |
|
134 |
+
# Use different colors based on the entity's type
|
135 |
+
color = "#8ef" # Default color
|
136 |
+
if entity_type == "Place":
|
137 |
+
color = "#8AC7DB"
|
138 |
+
elif entity_type == "Organization":
|
139 |
+
color = "#ADD8E6"
|
140 |
+
elif entity_type == "Person":
|
141 |
+
color = "#67B7D1"
|
142 |
+
elif entity_type == "Product":
|
143 |
+
color = "#2ea3f2"
|
144 |
+
elif entity_type == "CreativeWork":
|
145 |
+
color = "#00BFFF"
|
146 |
+
elif entity_type == "Event":
|
147 |
+
color = "#1E90FF"
|
148 |
|
149 |
+
entity_annotation = (entity_string, entity_info["id"], color)
|
150 |
+
text_input = text_input.replace(entity_string, f'{{{str(entity_annotation)}}}', 1)
|
151 |
|
152 |
+
# Add the entity to JSON-LD data
|
153 |
+
entity_json_ld = combined_entity_info_dictionary[entity_string][1]
|
154 |
+
json_ld_data["mentions"].append(entity_json_ld)
|
155 |
|
156 |
# Split the modified text_input into a list
|
157 |
text_list = text_input.split("{")
|