Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
|
|
2 |
from annotated_text import annotated_text
|
3 |
from refined.inference.processor import Refined
|
4 |
import requests
|
|
|
5 |
|
6 |
# Sidebar
|
7 |
st.sidebar.image("logo-wordlift.png")
|
@@ -63,6 +64,13 @@ if text_input:
|
|
63 |
# Prepare a list to hold the final output
|
64 |
final_text = []
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
# Replace each entity in the text with its annotated version
|
67 |
for entity_string, entity_info in entities_map.items():
|
68 |
entity_data = entities_data.get(entity_string, None)
|
@@ -87,6 +95,10 @@ if text_input:
|
|
87 |
|
88 |
entity_annotation = (entity_string, entity_info["id"], color)
|
89 |
text_input = text_input.replace(entity_string, f'{{{str(entity_annotation)}}}', 1)
|
|
|
|
|
|
|
|
|
90 |
|
91 |
# Split the modified text_input into a list
|
92 |
text_list = text_input.split("{")
|
@@ -103,5 +115,8 @@ if text_input:
|
|
103 |
# Pass the final_text to the annotated_text function
|
104 |
annotated_text(*final_text)
|
105 |
|
|
|
|
|
|
|
106 |
with st.expander("See annotations"):
|
107 |
st.write(combined_entity_info_dictionary)
|
|
|
2 |
from annotated_text import annotated_text
|
3 |
from refined.inference.processor import Refined
|
4 |
import requests
|
5 |
+
import json
|
6 |
|
7 |
# Sidebar
|
8 |
st.sidebar.image("logo-wordlift.png")
|
|
|
64 |
# Prepare a list to hold the final output
|
65 |
final_text = []
|
66 |
|
67 |
+
# JSON-LD data
|
68 |
+
json_ld_data = {
|
69 |
+
"@context": "https://schema.org",
|
70 |
+
"@type": "WebPage",
|
71 |
+
"mentions": []
|
72 |
+
}
|
73 |
+
|
74 |
# Replace each entity in the text with its annotated version
|
75 |
for entity_string, entity_info in entities_map.items():
|
76 |
entity_data = entities_data.get(entity_string, None)
|
|
|
95 |
|
96 |
entity_annotation = (entity_string, entity_info["id"], color)
|
97 |
text_input = text_input.replace(entity_string, f'{{{str(entity_annotation)}}}', 1)
|
98 |
+
|
99 |
+
# Add the entity to JSON-LD data
|
100 |
+
entity_json_ld = combined_entity_info_dictionary[entity_string][1]
|
101 |
+
json_ld_data["mentions"].append(entity_json_ld)
|
102 |
|
103 |
# Split the modified text_input into a list
|
104 |
text_list = text_input.split("{")
|
|
|
115 |
# Pass the final_text to the annotated_text function
|
116 |
annotated_text(*final_text)
|
117 |
|
118 |
+
with st.expander("Copy the JSON-LD")
|
119 |
+
st.write(json.dumps(json_ld_data, indent=2)) # Output JSON-LD
|
120 |
+
|
121 |
with st.expander("See annotations"):
|
122 |
st.write(combined_entity_info_dictionary)
|