luciagomez commited on
Commit
f5fb41d
·
verified ·
1 Parent(s): 74ae99d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -39,14 +39,15 @@ def chat_with_model(message, history):
39
  # -------------------------------------------------------------------
40
  # 3. Foundations Retriever function (for UI)
41
  # -------------------------------------------------------------------
42
- def retrieve_foundations(query, top_k):
43
- results = find_similar_foundations(query, top_k=top_k)
44
- output = "\n\n".join(
45
- [f"**{r['rank']}. {r['title']}**\n{r['purpose']}\n(similarity: {r['similarity']:.4f})"
46
- for r in results]
47
- )
48
- return output
49
-
 
50
 
51
  # -------------------------------------------------------------------
52
  # 4. Gradio Interface
@@ -59,7 +60,7 @@ with gr.Blocks() as demo:
59
  label="Enter your philanthropic perspective",
60
  placeholder="e.g. Environmental philanthropist emphasizing animal protection while fostering children's education"
61
  )
62
- chatbot = gr.Chatbot()
63
  msg = gr.Textbox(placeholder="Ask me anything...", show_label=False)
64
  state = gr.State([]) # keeps conversation history
65
  msg.submit(chat_with_model, [msg, state], [chatbot, state])
 
39
  # -------------------------------------------------------------------
40
  # 3. Foundations Retriever function (for UI)
41
  # -------------------------------------------------------------------
42
+ def retrieve_foundations(perspective, top_k=5):
43
+ """
44
+ Find foundations aligned with user-provided perspective.
45
+ """
46
+ results = find_similar_foundations(perspective, top_k=int(top_k))
47
+ display_text = ""
48
+ for i, res in enumerate(results, 1):
49
+ display_text += f"{i}. {res['Title']} - {res['Purpose']} (Score: {res['Score']:.3f})\n"
50
+ return display_text
51
 
52
  # -------------------------------------------------------------------
53
  # 4. Gradio Interface
 
60
  label="Enter your philanthropic perspective",
61
  placeholder="e.g. Environmental philanthropist emphasizing animal protection while fostering children's education"
62
  )
63
+ chatbot = gr.Chatbot(type="messages")
64
  msg = gr.Textbox(placeholder="Ask me anything...", show_label=False)
65
  state = gr.State([]) # keeps conversation history
66
  msg.submit(chat_with_model, [msg, state], [chatbot, state])