sujitb commited on
Commit
5694f59
1 Parent(s): 405501e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -191,12 +191,15 @@ if QUESTION:
191
 
192
  title=resp[0]['metadata']['title']
193
  #+ '\n*************\n'+ resp[1]['metadata']['text'] + '\n*************\n'+ resp[2]['metadata']['text']
 
 
194
  d={}
195
  d['id']=1
196
  d['content']=resp[0]['metadata']['data']
197
  d['url']=url
198
  meta_score= get_meta_score(url,question_embedding)
199
  score=.5* resp[0]['score'] + .5*meta_score
 
200
 
201
  if len(resp)>1:
202
  d['id']=2
@@ -204,14 +207,16 @@ if QUESTION:
204
  d['url']=url
205
  meta_score= get_meta_score(url,question_embedding)
206
  score=.5* resp[0]['score'] + .5*meta_score
 
207
 
 
208
 
209
  # Get the elements with the top 2 highest values
210
- top_2 = sorted(d.items(), key=lambda x: x[3], reverse=True)[:2]
211
 
212
  # covert to array
213
- json_array = [{'id': key, 'content': value} for key, value in top_2.items()]
214
- json_data = json.dumps(json_array)
215
 
216
  st.write(json_data)
217
 
 
191
 
192
  title=resp[0]['metadata']['title']
193
  #+ '\n*************\n'+ resp[1]['metadata']['text'] + '\n*************\n'+ resp[2]['metadata']['text']
194
+ matches=[]
195
+
196
  d={}
197
  d['id']=1
198
  d['content']=resp[0]['metadata']['data']
199
  d['url']=url
200
  meta_score= get_meta_score(url,question_embedding)
201
  score=.5* resp[0]['score'] + .5*meta_score
202
+ matches.append(d)
203
 
204
  if len(resp)>1:
205
  d['id']=2
 
207
  d['url']=url
208
  meta_score= get_meta_score(url,question_embedding)
209
  score=.5* resp[0]['score'] + .5*meta_score
210
+ matches.append(d)
211
 
212
+ sorted_indices = sorted(range(len(objects)), key=lambda i: objects[i]['score'], reverse=True)
213
 
214
  # Get the elements with the top 2 highest values
215
+ top_2 = [objects[i] for i in sorted_indices[:2]]
216
 
217
  # covert to array
218
+
219
+ json_data = json.dumps(top_2)
220
 
221
  st.write(json_data)
222