Update agents/compare.py
Browse files- agents/compare.py +36 -36
agents/compare.py
CHANGED
|
@@ -1,37 +1,37 @@
|
|
| 1 |
-
import pandas as pd
|
| 2 |
-
import google.generativeai as genai
|
| 3 |
-
import os
|
| 4 |
-
|
| 5 |
-
#function to compare cards
|
| 6 |
-
def compare_selected_cards(selected_names, card_lookup):
|
| 7 |
-
genai.configure(api_key=os.environ.get("api_key_4"))
|
| 8 |
-
model4 = genai.GenerativeModel('gemini-
|
| 9 |
-
print(selected_names)
|
| 10 |
-
if not selected_names or len(selected_names) < 2:
|
| 11 |
-
return "<b style='color:red;'>Please select at least two cards to compare.</b>"
|
| 12 |
-
|
| 13 |
-
comparison_data = "\n\n".join([
|
| 14 |
-
f"{name}: {card_lookup.get(name)}" for name in selected_names
|
| 15 |
-
])
|
| 16 |
-
prompt = (
|
| 17 |
-
f"Do not include extra symbols like (* or #), just generate a textual response maybe with numbers for points."
|
| 18 |
-
f"Compare the following credit cards based on their benefits. "
|
| 19 |
-
f"Keep the output short, structured, and very readable:\n\n"
|
| 20 |
-
f"{comparison_data}\n\n"
|
| 21 |
-
f"Use markdown format with clear section headers like 'Comparison' and 'Recommendation'. "
|
| 22 |
-
f"Present key differences as bullet points without using '*' symbols — use '-' instead. "
|
| 23 |
-
f"Make it crisp and avoid lengthy explanations. "
|
| 24 |
-
f"Conclude with a recommendation on which card suits which type of user."
|
| 25 |
-
f"DO NOT INCLUDE ANY SYMBOLS LIKE # OR *"
|
| 26 |
-
)
|
| 27 |
-
print("comparing")
|
| 28 |
-
try:
|
| 29 |
-
response = model4.generate_content(prompt)
|
| 30 |
-
return f"""
|
| 31 |
-
<div style='background-color: #f9fbe7; padding: 15px; border-radius: 10px; font-family: sans-serif;'>
|
| 32 |
-
<pre style='white-space: pre-wrap; font-size: 13px; color: #333;'>{response.text}</pre>
|
| 33 |
-
</div>
|
| 34 |
-
"""
|
| 35 |
-
except Exception as e:
|
| 36 |
-
print("Comparison Error:", e)
|
| 37 |
return "<b style='color:red;'>Something went wrong while comparing. Please try again.</b>"
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import google.generativeai as genai
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
#function to compare cards
|
| 6 |
+
def compare_selected_cards(selected_names, card_lookup):
|
| 7 |
+
genai.configure(api_key=os.environ.get("api_key_4"))
|
| 8 |
+
model4 = genai.GenerativeModel('gemini-2.0-flash')
|
| 9 |
+
print(selected_names)
|
| 10 |
+
if not selected_names or len(selected_names) < 2:
|
| 11 |
+
return "<b style='color:red;'>Please select at least two cards to compare.</b>"
|
| 12 |
+
|
| 13 |
+
comparison_data = "\n\n".join([
|
| 14 |
+
f"{name}: {card_lookup.get(name)}" for name in selected_names
|
| 15 |
+
])
|
| 16 |
+
prompt = (
|
| 17 |
+
f"Do not include extra symbols like (* or #), just generate a textual response maybe with numbers for points."
|
| 18 |
+
f"Compare the following credit cards based on their benefits. "
|
| 19 |
+
f"Keep the output short, structured, and very readable:\n\n"
|
| 20 |
+
f"{comparison_data}\n\n"
|
| 21 |
+
f"Use markdown format with clear section headers like 'Comparison' and 'Recommendation'. "
|
| 22 |
+
f"Present key differences as bullet points without using '*' symbols — use '-' instead. "
|
| 23 |
+
f"Make it crisp and avoid lengthy explanations. "
|
| 24 |
+
f"Conclude with a recommendation on which card suits which type of user."
|
| 25 |
+
f"DO NOT INCLUDE ANY SYMBOLS LIKE # OR *"
|
| 26 |
+
)
|
| 27 |
+
print("comparing")
|
| 28 |
+
try:
|
| 29 |
+
response = model4.generate_content(prompt)
|
| 30 |
+
return f"""
|
| 31 |
+
<div style='background-color: #f9fbe7; padding: 15px; border-radius: 10px; font-family: sans-serif;'>
|
| 32 |
+
<pre style='white-space: pre-wrap; font-size: 13px; color: #333;'>{response.text}</pre>
|
| 33 |
+
</div>
|
| 34 |
+
"""
|
| 35 |
+
except Exception as e:
|
| 36 |
+
print("Comparison Error:", e)
|
| 37 |
return "<b style='color:red;'>Something went wrong while comparing. Please try again.</b>"
|