domenicrosati commited on
Commit
8890bde
β€’
1 Parent(s): a630e82

fix limit and highlighting and empty docs

Browse files
Files changed (2) hide show
  1. README.md +2 -2
  2. app.py +8 -5
README.md CHANGED
@@ -1,7 +1,7 @@
1
  ---
2
  title: CitationQA - Answers from science with citations
3
- emoji: 🐠
4
- colorFrom: pink
5
  colorTo: indigo
6
  sdk: streamlit
7
  sdk_version: 1.10.0
 
1
  ---
2
  title: CitationQA - Answers from science with citations
3
+ emoji: πŸ‘©πŸ½β€πŸ”¬
4
+ colorFrom: blue
5
  colorTo: indigo
6
  sdk: streamlit
7
  sdk_version: 1.10.0
app.py CHANGED
@@ -10,7 +10,7 @@ def remove_html(x):
10
  text = soup.get_text()
11
  return text
12
 
13
- def search(term, limit=10):
14
  search = f"https://api.scite.ai/search?mode=citations&term={term}&limit={limit}&offset=0&user_slug=domenic-rosati-keW5&compute_aggregations=false"
15
  req = requests.get(
16
  search,
@@ -43,7 +43,9 @@ def find_source(text, docs):
43
  'citation_statement': '',
44
  'text': text,
45
  'from': '',
46
- 'supporting': ''
 
 
47
  }
48
 
49
  @st.experimental_singleton
@@ -89,11 +91,11 @@ def run_query(query):
89
  <div class="container-fluid">
90
  <div class="row align-items-start">
91
  <div class="col-md-12 col-sm-12">
92
- Sorry... no results for that question! Try another.
93
  </div>
94
  </div>
95
  </div>
96
- """)
97
 
98
  results = []
99
  model_results = qa_model(question=query, context=context, top_k=10)
@@ -113,11 +115,12 @@ def run_query(query):
113
  sorted_result = list({
114
  result['context']: result for result in sorted_result
115
  }.values())
 
116
 
117
 
118
  for r in sorted_result:
119
  answer = r["answer"]
120
- ctx = r["context"].replace(answer, f"<mark>{answer}</mark>").replace('<cite', '<a').replace('</cite', '</a').replace('data-doi="', 'href="https://scite.ai/reports/')
121
  title = r["title"].replace("_", " ")
122
  score = round(r["score"], 4)
123
  card(title, ctx, score, r['link'])
 
10
  text = soup.get_text()
11
  return text
12
 
13
+ def search(term, limit=25):
14
  search = f"https://api.scite.ai/search?mode=citations&term={term}&limit={limit}&offset=0&user_slug=domenic-rosati-keW5&compute_aggregations=false"
15
  req = requests.get(
16
  search,
 
43
  'citation_statement': '',
44
  'text': text,
45
  'from': '',
46
+ 'supporting': '',
47
+ 'source_title': '',
48
+ 'source_link': ''
49
  }
50
 
51
  @st.experimental_singleton
 
91
  <div class="container-fluid">
92
  <div class="row align-items-start">
93
  <div class="col-md-12 col-sm-12">
94
+ Sorry... no results for that question! Try another...
95
  </div>
96
  </div>
97
  </div>
98
+ """, unsafe_allow_html=True)
99
 
100
  results = []
101
  model_results = qa_model(question=query, context=context, top_k=10)
 
115
  sorted_result = list({
116
  result['context']: result for result in sorted_result
117
  }.values())
118
+ sorted_result = sorted(sorted_result, key=lambda x: x['score'], reverse=True)
119
 
120
 
121
  for r in sorted_result:
122
  answer = r["answer"]
123
+ ctx = remove_html(r["context"]).replace(answer, f"<mark>{answer}</mark>").replace('<cite', '<a').replace('</cite', '</a').replace('data-doi="', 'href="https://scite.ai/reports/')
124
  title = r["title"].replace("_", " ")
125
  score = round(r["score"], 4)
126
  card(title, ctx, score, r['link'])