File size: 1,813 Bytes
a722b48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6390a72
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import pandas as pd
import google.generativeai as genai
import os

#function to compare cards
def compare_selected_cards(selected_names, card_lookup):
    genai.configure(api_key=os.environ.get("api_key_4"))  
    model4 = genai.GenerativeModel('gemini-2.0-flash')
    print(selected_names)
    if not selected_names or len(selected_names) < 2:
        return "<b style='color:red;'>Please select at least two cards to compare.</b>"

    comparison_data = "\n\n".join([
            f"{name}: {card_lookup.get(name)}" for name in selected_names
        ])
    prompt = (
            f"Do not include extra symbols like (* or #), just generate a textual response maybe with numbers for points."
            f"Compare the following credit cards based on their benefits. "
            f"Keep the output short, structured, and very readable:\n\n"
            f"{comparison_data}\n\n"
            f"Use markdown format with clear section headers like 'Comparison' and 'Recommendation'. "
            f"Present key differences as bullet points without using '*' symbols — use '-' instead. "
            f"Make it crisp and avoid lengthy explanations. "
            f"Conclude with a recommendation on which card suits which type of user."
            f"DO NOT INCLUDE ANY SYMBOLS LIKE # OR *"
    )
    print("comparing")
    try:
        response = model4.generate_content(prompt)
        return f"""
            <div style='background-color: #f9fbe7; padding: 15px; border-radius: 10px; font-family: sans-serif;'>
                <pre style='white-space: pre-wrap; font-size: 13px; color: #333;'>{response.text}</pre>
            </div>
            """
    except Exception as e:
        print("Comparison Error:", e)
        return "<b style='color:red;'>Something went wrong while comparing. Please try again.</b>"