crystina-z commited on
Commit
93626b2
·
1 Parent(s): 48bcd5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -38
app.py CHANGED
@@ -117,48 +117,51 @@ def aggregate(list_of_hits):
117
 
118
  return [id2doc[id] for id in y_optimal]
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  aggregated_ranking = aggregate(query2outputs[search_query])
121
  qrels = load_qrels("dl19")
122
 
123
  col1, col2 = st.columns([5, 5])
124
 
 
 
 
 
125
  with col2:
126
  if search_query or button_clicked:
127
-
128
- num_results = None
129
- t_0 = time.time()
130
- # search_results = query2outputs[search_query][0] # first from the 20
131
- search_results = aggregated_ranking
132
-
133
- st.write(
134
- f'<p align=\"right\" style=\"color:grey;\"> Before aggregation for query [{search_query}] ms</p>', unsafe_allow_html=True)
135
-
136
- qid = {result["qid"] for result in search_results}
137
- assert len(qid) == 1
138
- qid = list(qid)[0]
139
-
140
- for i, result in enumerate(search_results):
141
- result_id = result["docid"]
142
- contents = result["content"]
143
-
144
- label = qrels[qid].get(result_id, 0)
145
- if label == 3:
146
- style = "style=\"color:blue;\""
147
- elif label == 2:
148
- style = "style=\"color:green;\""
149
- elif label == 1:
150
- style = "style=\"color:red;\""
151
- else:
152
- style = "style=\"color:grey;\""
153
-
154
- # output = f'<div class="row"> <b>Rank</b>: {i+1} | <b>Document ID</b>: {result_id} | <b>Score</b>:{result_score:.2f}</div>'
155
- output = f'<div class="row" {style}> <b>Rank</b>: {i+1} | <b>Document ID</b>: {result_id}'
156
-
157
- try:
158
- st.write(output, unsafe_allow_html=True)
159
- st.write(
160
- f'<div class="row" {style}>{contents}</div>', unsafe_allow_html=True)
161
-
162
- except:
163
- pass
164
- st.write('---')
 
117
 
118
  return [id2doc[id] for id in y_optimal]
119
 
120
+
121
+ def write_ranking(search_results):
122
+ st.write(
123
+ f'<p align=\"right\" style=\"color:grey;\"> Before aggregation for query [{search_query}] ms</p>', unsafe_allow_html=True)
124
+
125
+ qid = {result["qid"] for result in search_results}
126
+ assert len(qid) == 1
127
+ qid = list(qid)[0]
128
+
129
+ for i, result in enumerate(search_results):
130
+ result_id = result["docid"]
131
+ contents = result["content"]
132
+
133
+ label = qrels[qid].get(result_id, 0)
134
+ if label == 3:
135
+ style = "style=\"color:blue;\""
136
+ elif label == 2:
137
+ style = "style=\"color:green;\""
138
+ elif label == 1:
139
+ style = "style=\"color:red;\""
140
+ else:
141
+ style = "style=\"color:grey;\""
142
+
143
+ print(qid, result_id, label, style)
144
+ # output = f'<div class="row"> <b>Rank</b>: {i+1} | <b>Document ID</b>: {result_id} | <b>Score</b>:{result_score:.2f}</div>'
145
+ output = f'<div class="row" {style}> <b>Rank</b>: {i+1} | <b>Document ID</b>: {result_id}'
146
+
147
+ try:
148
+ st.write(output, unsafe_allow_html=True)
149
+ st.write(
150
+ f'<div class="row" {style}>{contents}</div>', unsafe_allow_html=True)
151
+
152
+ except:
153
+ pass
154
+ st.write('---')
155
+
156
  aggregated_ranking = aggregate(query2outputs[search_query])
157
  qrels = load_qrels("dl19")
158
 
159
  col1, col2 = st.columns([5, 5])
160
 
161
+ with col1:
162
+ if search_query or button_clicked:
163
+ write_ranking(search_results=query2outputs[search_query][0]):
164
+
165
  with col2:
166
  if search_query or button_clicked:
167
+ write_ranking(search_results=aggregated_ranking):