blazingbunny commited on
Commit
aa6444a
·
1 Parent(s): 2be4187

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -13
app.py CHANGED
@@ -5,23 +5,15 @@ from google.cloud import language_v1
5
  import urllib.parse
6
  import urllib.request
7
 
 
8
  # Function to query Google's Knowledge Graph API
9
  def query_knowledge_graph(entity_id):
10
  try:
11
- service_url = 'https://kgsearch.googleapis.com/v1/entities:search'
12
- params = {
13
- 'ids': entity_id,
14
- 'limit': 1,
15
- 'indent': True,
16
- 'key': st.secrets["kg_api"],
17
- }
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):
 
5
  import urllib.parse
6
  import urllib.request
7
 
8
+ # Function to query Google's Knowledge Graph API
9
  # Function to query Google's Knowledge Graph API
10
  def query_knowledge_graph(entity_id):
11
  try:
12
+ google_search_link = f"https://www.google.com/search?kgmid={entity_id}"
13
+ st.markdown(f'[Open in Google Search]({google_search_link})', unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
14
  except Exception as e:
15
+ st.write(f"An error occurred: {e}")
16
+
17
 
18
  # Function to count entities with 'mid' that contains '/g/' or '/m/' in their metadata
19
  def count_entities(entities):