tombryan commited on
Commit
a0a5163
1 Parent(s): f8367ae

Fixing dbpedia

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -19,6 +19,7 @@ for k, v in os.environ.items():
19
 
20
  AVAILABLE_YEARS = ['All Years']
21
 
 
22
 
23
 
24
  def find_sep_token(tokenizer):
@@ -58,6 +59,9 @@ if gr.NO_RELOAD:
58
  embed_mask_tok = find_mask_token(embedding_tokenizer)
59
  embed_sep_tok = find_sep_token(embedding_tokenizer)
60
 
 
 
 
61
  # with open(REF_INDEX_PATH, 'r') as f:
62
  # news_paths = [l.strip() for l in f.readlines()]
63
 
@@ -140,10 +144,13 @@ def query(sentence: str, state: str, years: List[str]) -> List[str]:
140
 
141
  doc = response.json()
142
  article = doc['bboxes'][int(doc['article_id'])]
143
- if len(article['lccn']['dpedia_ids']) == 0:
144
  location = 'Unknown'
145
  else:
146
- location = doc['lccn']['dpedia_ids'][0].replace('%2C_', ', ')
 
 
 
147
  results = {
148
  'newspaper_name': doc['lccn']['title'],
149
  'location': location,
 
19
 
20
  AVAILABLE_YEARS = ['All Years']
21
 
22
+ REQUEST_HEADERS = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/37.0.2062.94 Chrome/37.0.2062.94 Safari/537.36'
23
 
24
 
25
  def find_sep_token(tokenizer):
 
59
  embed_mask_tok = find_mask_token(embedding_tokenizer)
60
  embed_sep_tok = find_sep_token(embedding_tokenizer)
61
 
62
+ img_download_session = requests.Session()
63
+
64
+
65
  # with open(REF_INDEX_PATH, 'r') as f:
66
  # news_paths = [l.strip() for l in f.readlines()]
67
 
 
144
 
145
  doc = response.json()
146
  article = doc['bboxes'][int(doc['article_id'])]
147
+ if len(doc['lccn']['dbpedia_ids']) == 0:
148
  location = 'Unknown'
149
  else:
150
+ location = doc['lccn']['dbpedia_ids'][0].replace('%2C_', ', ')
151
+
152
+ # response = img_download_session.get(ca_url, headers = {'User-Agent': random.choice(USER_HEADERS)})
153
+
154
  results = {
155
  'newspaper_name': doc['lccn']['title'],
156
  'location': location,