Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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(
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 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])
|