eliwill commited on
Commit
edb1e33
·
1 Parent(s): 508039d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -43,15 +43,15 @@ def ask_philosopher(philosopher, question):
43
  return answer
44
 
45
  def get_similar_quotes(philosopher, question):
46
- """ Return top 3 most similar quotes to the question from a philosopher's dataframe """
47
  df = philosopher_dictionary[philosopher]['dataframe']
48
  question_embedding = model.encode(question)
49
  sims = [util.dot_score(question_embedding, quote_embedding) for quote_embedding in df['Embedding']]
50
- ind = np.argpartition(sims, -4)[-4:]
51
  similar_sentences = [df['quote'][i] for i in ind]
52
- top4quotes = pd.DataFrame(data = similar_sentences, columns=["Quotes"], index=range(1,5))
53
- top4quotes['Quotes'] = top4quotes['Quotes'].str[:-1].str[:250] + "..."
54
- return top4quotes
55
 
56
  def main(question, philosopher):
57
  out_image = "marcus-aurelius.jpg"
@@ -76,7 +76,7 @@ with gr.Blocks(css=".gradio-container {background-image: url('file=mountains_res
76
  )
77
 
78
  with gr.Row():
79
- out_image = gr.Image(label="Picture")
80
  out2 = gr.DataFrame(
81
  headers=["Quotes"],
82
  max_rows=5,
 
43
  return answer
44
 
45
  def get_similar_quotes(philosopher, question):
46
+ """ Return top 5 most similar quotes to the question from a philosopher's dataframe """
47
  df = philosopher_dictionary[philosopher]['dataframe']
48
  question_embedding = model.encode(question)
49
  sims = [util.dot_score(question_embedding, quote_embedding) for quote_embedding in df['Embedding']]
50
+ ind = np.argpartition(sims, -5)[-5:]
51
  similar_sentences = [df['quote'][i] for i in ind]
52
+ top5quotes = pd.DataFrame(data = similar_sentences, columns=["Quotes"], index=range(1,6))
53
+ top5quotes['Quotes'] = top4quotes['Quotes'].str[:-1].str[:250] + "..."
54
+ return top5quotes
55
 
56
  def main(question, philosopher):
57
  out_image = "marcus-aurelius.jpg"
 
76
  )
77
 
78
  with gr.Row():
79
+ out_image = gr.Image(label="Picture", image_mode="L")
80
  out2 = gr.DataFrame(
81
  headers=["Quotes"],
82
  max_rows=5,