blazingbunny commited on
Commit
c226cf4
·
1 Parent(s): 9d38e3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -18,11 +18,11 @@ def query_knowledge_graph(entity_id):
18
  url = service_url + '?' + urllib.parse.urlencode(params)
19
  response = json.loads(urllib.request.urlopen(url).read())
20
  for element in response['itemListElement']:
21
- st.write(f"Knowledge Graph name: {element['result']}")
 
22
  except Exception as e:
23
  st.write(f"An error occurred while querying the Knowledge Graph: {e}")
24
 
25
-
26
  # Function to count entities with 'mid' that contains '/g/' or '/m/' in their metadata
27
  def count_entities(entities):
28
  count = 0
@@ -81,8 +81,9 @@ def sample_analyze_entities(text_content):
81
  query_knowledge_graph(entity_id)
82
 
83
  if entity.mentions:
84
- st.write("Mentions:")
85
- st.write(', '.join([mention.text.content for mention in entity.mentions]))
 
86
 
87
  st.write("---")
88
 
 
18
  url = service_url + '?' + urllib.parse.urlencode(params)
19
  response = json.loads(urllib.request.urlopen(url).read())
20
  for element in response['itemListElement']:
21
+ google_search_link = f"https://www.google.com/search?kgmid={entity_id}"
22
+ st.markdown(f'[Open in Google Search]({google_search_link})', unsafe_allow_html=True)
23
  except Exception as e:
24
  st.write(f"An error occurred while querying the Knowledge Graph: {e}")
25
 
 
26
  # Function to count entities with 'mid' that contains '/g/' or '/m/' in their metadata
27
  def count_entities(entities):
28
  count = 0
 
81
  query_knowledge_graph(entity_id)
82
 
83
  if entity.mentions:
84
+ mention_count = len(entity.mentions)
85
+ plural = "s" if mention_count > 1 else ""
86
+ st.write(f"Mentions: {mention_count} mention{plural}")
87
 
88
  st.write("---")
89