ashwinpatti commited on
Commit
7a39fe4
·
1 Parent(s): 5c00573

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -26,12 +26,14 @@ def search_bi_encoder(query,top_k=15):
26
  resultlist = []
27
 
28
  hlist = []
 
29
  for r in results.index:
30
  if results.title[r] not in hlist:
31
  resultlist.append(
32
  {
33
  "name":results.title[r],
34
  "bi_encoder_score": results.bi_similarity[r][0],
 
35
  "year": results.year[r],
36
  "language": results.language[r],
37
  "cast":results.cast[r],
@@ -39,6 +41,8 @@ def search_bi_encoder(query,top_k=15):
39
  "link":results.link[r]
40
  })
41
  hlist.append(results.title[r])
 
 
42
  return resultlist
43
 
44
 
@@ -46,7 +50,9 @@ def search_cross_encoder(query,candidates):
46
  cross_inp = [[query, candidate['plot']] for candidate in candidates]
47
  cross_scores = cross_encoder.predict(cross_inp)
48
  for idx in range(len(cross_scores)):
49
- candidates[idx]['cross-score'] = cross_scores[idx]
 
 
50
 
51
  sortedResult = sorted(candidates, key=lambda x: x['cross-score'], reverse=True)
52
  return sortedResult
@@ -61,12 +67,12 @@ def search(query,top_k=15):
61
 
62
  def displayResults(results, container):
63
  for result in results:
64
- container.header(result.name)
65
- container.caption(f"Language:{result.language}, Released in:{result.year}")
66
- cast = ",".join(result.cast)
67
  container.caption(f"Cast:{cast}")
68
  container.text(result.plot)
69
- container.markdown(f"![{result.name}](https://en.wikipedia.org/{result.link}")
70
  with container.expander("Movie result internals"):
71
  container.json(result)
72
 
 
26
  resultlist = []
27
 
28
  hlist = []
29
+ rank=1
30
  for r in results.index:
31
  if results.title[r] not in hlist:
32
  resultlist.append(
33
  {
34
  "name":results.title[r],
35
  "bi_encoder_score": results.bi_similarity[r][0],
36
+ "retrieval_rank":rank,
37
  "year": results.year[r],
38
  "language": results.language[r],
39
  "cast":results.cast[r],
 
41
  "link":results.link[r]
42
  })
43
  hlist.append(results.title[r])
44
+ rank = rank+1
45
+
46
  return resultlist
47
 
48
 
 
50
  cross_inp = [[query, candidate['plot']] for candidate in candidates]
51
  cross_scores = cross_encoder.predict(cross_inp)
52
  for idx in range(len(cross_scores)):
53
+ candidates[idx]['cross-score'] = cross_scores[idx]
54
+ candidates[idx]['re-rank'] = idx+1
55
+
56
 
57
  sortedResult = sorted(candidates, key=lambda x: x['cross-score'], reverse=True)
58
  return sortedResult
 
67
 
68
  def displayResults(results, container):
69
  for result in results:
70
+ container.header(result['name'])
71
+ container.caption(f"Language:{result['language']}, Released in:{result['year']}")
72
+ cast = ",".join(result['cast'])
73
  container.caption(f"Cast:{cast}")
74
  container.text(result.plot)
75
+ container.markdown(f"![{result['name']}](https://en.wikipedia.org/{result['link']}")
76
  with container.expander("Movie result internals"):
77
  container.json(result)
78