ola13 commited on
Commit
943373e
1 Parent(s): 1bfb876
Files changed (1) hide show
  1. app.py +57 -18
app.py CHANGED
@@ -2,12 +2,15 @@ import http.client as http_client
2
  import json
3
  import logging
4
  import os
 
5
  import re
6
  import string
7
 
8
  import gradio as gr
9
  import requests
10
 
 
 
11
 
12
  def get_docid_html(docid):
13
  data_org, dataset, docid = docid.split("/")
@@ -36,6 +39,53 @@ def process_pii(text):
36
  return text
37
 
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  def process_results(results, highlight_terms):
40
  if len(results) == 0:
41
  return """<br><p style='font-family: Arial; color:Silver; text-align: center;'>
@@ -52,24 +102,10 @@ def process_results(results, highlight_terms):
52
  tokens_html.append(token)
53
  tokens_html = " ".join(tokens_html)
54
  tokens_html = process_pii(tokens_html)
55
- meta_html = (
56
- """
57
- <p class='underline-on-hover' style='font-size:12px; font-family: Arial; color:#585858; text-align: left;'>
58
- <a href='{}' target='_blank'>{}</a></p>""".format(
59
- result["meta"]["url"], result["meta"]["url"]
60
- )
61
- if "meta" in result and result["meta"] is not None and "url" in result["meta"]
62
- else ""
63
- )
64
- docid_html = get_docid_html(result["docid"])
65
- results_html += """{}
66
- <p style='font-size:14px; font-family: Arial; color:#7978FF; text-align: left;'>Document ID: {}</p>
67
- <p style='font-size:12px; font-family: Arial; color:MediumAquaMarine'>Language: {}</p>
68
- <p style='font-family: Arial;'>{}</p>
69
- <br>
70
- """.format(
71
- meta_html, docid_html, result["lang"], tokens_html
72
- )
73
  return results_html + "<hr>"
74
 
75
 
@@ -92,6 +128,8 @@ def scisearch(query, language, num_results=10):
92
 
93
  payload = json.loads(output.text)
94
 
 
 
95
  if "err" in payload:
96
  if payload["err"]["type"] == "unsupported_lang":
97
  detected_lang = payload["err"]["meta"]["detected_lang"]
@@ -143,6 +181,7 @@ def scisearch(query, language, num_results=10):
143
  Check if a relevant discussion already exists in the Community tab. If not, please open a discussion.
144
  </p>
145
  """
 
146
 
147
  return results_html
148
 
 
2
  import json
3
  import logging
4
  import os
5
+ import pprint
6
  import re
7
  import string
8
 
9
  import gradio as gr
10
  import requests
11
 
12
+ pp = pprint.PrettyPrinter(indent=2)
13
+
14
 
15
  def get_docid_html(docid):
16
  data_org, dataset, docid = docid.split("/")
 
39
  return text
40
 
41
 
42
+ def process_meta_roots(result):
43
+ meta_html = (
44
+ """
45
+ <p class='underline-on-hover' style='font-size:12px; font-family: Arial; color:#585858; text-align: left;'>
46
+ <a href='{}' target='_blank'>{}</a></p>""".format(
47
+ result["meta"]["url"], result["meta"]["url"]
48
+ )
49
+ if "meta" in result and result["meta"] is not None and "url" in result["meta"]
50
+ else ""
51
+ )
52
+
53
+
54
+ """
55
+ 'meta': { 'docs': [ { 'TEXT': 'Hello World Example Hello '
56
+ 'World Page Hello World.',
57
+ 'URL': 'http://images.slideplayer.com/8/2335183/slides/slide_6.jpg',
58
+ '_id': 592573973},
59
+ { 'TEXT': 'Hello World Example Hello '
60
+ 'World Page Hello World.',
61
+ 'URL': 'http://images.slideplayer.com/8/2335183/slides/slide_9.jpg',
62
+ '_id': 1807595732},
63
+ { 'TEXT': 'Hello World Example Hello '
64
+ 'World Page Hello World.',
65
+ 'URL': 'http://images.slideplayer.com/8/2335183/slides/slide_10.jpg',
66
+ '_id': 1864921031},
67
+ { 'TEXT': 'Hello World Example Hello '
68
+ 'World Page Hello World!',
69
+ 'URL': 'http://images.slideplayer.com/8/2335183/slides/slide_5.jpg',
70
+ '_id': 1964462104},
71
+ { 'TEXT': 'Hello World Example Hello '
72
+ 'World Page Hello World.',
73
+ 'URL': 'http://images.slideplayer.com/8/2335183/slides/slide_8.jpg',
74
+ '_id': 2167992166}]},
75
+ """
76
+ def process_meta_laion(result):
77
+ meta_html = """"""
78
+ if "meta" not in result:
79
+ return meta_html
80
+ for doc in result["meta"]["docs"]:
81
+ # doc = json.loads(doc)
82
+ print(type(doc), doc)
83
+ print(doc["URL"])
84
+ meta_html += """<p class='underline-on-hover' style='font-size:12px; color:#7978FF; text-align: left;'>
85
+ <a href='{}' target='_blank'>{}</a></p>""".format(doc["URL"], doc["URL"])
86
+
87
+ return meta_html
88
+
89
  def process_results(results, highlight_terms):
90
  if len(results) == 0:
91
  return """<br><p style='font-family: Arial; color:Silver; text-align: center;'>
 
102
  tokens_html.append(token)
103
  tokens_html = " ".join(tokens_html)
104
  tokens_html = process_pii(tokens_html)
105
+ meta_html = process_meta_laion(result)
106
+ docid_html = """<p style='font-size:14px; font-family: Arial; color:#7978FF; text-align: left;'>Document ID: {}</p>""".format(result["docid"]) # get_docid_html(result["docid"])
107
+ language_html = """<p style='font-size:12px; font-family: Arial; color:MediumAquaMarine'>Language: {}</p>""".format(result["lang"])
108
+ results_html += tokens_html + meta_html + "<br>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  return results_html + "<hr>"
110
 
111
 
 
128
 
129
  payload = json.loads(output.text)
130
 
131
+ pp.pprint(payload)
132
+
133
  if "err" in payload:
134
  if payload["err"]["type"] == "unsupported_lang":
135
  detected_lang = payload["err"]["meta"]["detected_lang"]
 
181
  Check if a relevant discussion already exists in the Community tab. If not, please open a discussion.
182
  </p>
183
  """
184
+ print(e)
185
 
186
  return results_html
187