Commit
·
a95b8e3
1
Parent(s):
0a35ca9
Update app.py
Browse files
app.py
CHANGED
@@ -26,7 +26,7 @@ st.sidebar.markdown("""
|
|
26 |
# Header and intro
|
27 |
st.title("Google Cloud NLP Entity Analyzer")
|
28 |
st.write("This tool analyzes text to identify entities such as people, locations, organizations, and events")
|
29 |
-
st.write("Entity salience scores are always relative to the analysed text. In natural language processing, a salience score is always a prediction of what a human would consider to be the most important entities in the same text.
|
30 |
|
31 |
def sample_analyze_entities(text_content):
|
32 |
service_account_info = json.loads(st.secrets["google_nlp"])
|
@@ -51,18 +51,25 @@ def sample_analyze_entities(text_content):
|
|
51 |
st.write(f"Name: {entity.name}")
|
52 |
st.write(f"Type: {language_v1.Entity.Type(entity.type_).name}")
|
53 |
st.write(f"Salience Score: {entity.salience}")
|
54 |
-
|
55 |
if entity.metadata:
|
56 |
st.write("Metadata:")
|
57 |
st.write(entity.metadata)
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
if entity.mentions:
|
60 |
st.write("Mentions:")
|
61 |
-
st.write(entity.mentions)
|
|
|
62 |
st.write("---")
|
63 |
|
64 |
# User input for text analysis
|
65 |
-
user_input = st.text_area("Enter text to analyze", max_chars=
|
66 |
|
67 |
if st.button("Analyze"):
|
68 |
if user_input:
|
|
|
26 |
# Header and intro
|
27 |
st.title("Google Cloud NLP Entity Analyzer")
|
28 |
st.write("This tool analyzes text to identify entities such as people, locations, organizations, and events")
|
29 |
+
st.write("Entity salience scores are always relative to the analysed text. In natural language processing, a salience score is always a prediction of what a human would consider to be the most important entities in the same text.")
|
30 |
|
31 |
def sample_analyze_entities(text_content):
|
32 |
service_account_info = json.loads(st.secrets["google_nlp"])
|
|
|
51 |
st.write(f"Name: {entity.name}")
|
52 |
st.write(f"Type: {language_v1.Entity.Type(entity.type_).name}")
|
53 |
st.write(f"Salience Score: {entity.salience}")
|
54 |
+
|
55 |
if entity.metadata:
|
56 |
st.write("Metadata:")
|
57 |
st.write(entity.metadata)
|
58 |
+
|
59 |
+
if 'mid' in entity.metadata and ('/g/' in entity.metadata['mid'] or '/m/' in entity.metadata['mid']):
|
60 |
+
entity_id = entity.metadata['mid']
|
61 |
+
ahref_link = f"https://kgsearch.googleapis.com/v1/entities:search?ids={entity_id}&key={st.secrets['google_nlp']}&limit=1&indent=True"
|
62 |
+
st.markdown(f'<a href="{ahref_link}" target="_blank">Google Entity Link</a>', unsafe_allow_html=True)
|
63 |
+
|
64 |
+
|
65 |
if entity.mentions:
|
66 |
st.write("Mentions:")
|
67 |
+
st.write(', '.join([mention.text.content for mention in entity.mentions]))
|
68 |
+
|
69 |
st.write("---")
|
70 |
|
71 |
# User input for text analysis
|
72 |
+
user_input = st.text_area("Enter text to analyze", max_chars=5000)
|
73 |
|
74 |
if st.button("Analyze"):
|
75 |
if user_input:
|