Spaces:
Runtime error
Runtime error
| import os | |
| import pandas as pd | |
| from neo4j import GraphDatabase | |
| import sys | |
| from datetime import datetime | |
| import re | |
| #neo4j credentials | |
| NEO4J_URI = os.environ.get("NEO4J_URI") | |
| NEO4J_USER = os.environ.get("NEO4J_USER") | |
| NEO4J_PASS = os.environ.get("NEO4J_PASS") | |
| GEMINI_API_KEY=os.environ.get("GEMINI_API_KEY_3") | |
| driver = GraphDatabase.driver(NEO4J_URI, auth=(NEO4J_USER, NEO4J_PASS)) | |
| def debug_print(category, message): | |
| """ | |
| Print a debug message with timestamp and category, flushed immediately. | |
| Args: | |
| category (str): Category of the debug message (e.g., NODE, AGENT, TOOL) | |
| message (str): The message to print | |
| """ | |
| timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") | |
| print(f"[{timestamp}] [{category}] {message}", flush=True, file=sys.stdout) | |
| #for adding bank name to the cards in the graph | |
| eligibility_df = pd.read_csv("cards_eligibility_updated.csv") | |
| # Loading credit card data | |
| df = pd.read_csv("credit_card_data_updated.csv") | |
| card_descriptions = dict(zip(df["name"], df["description"])) | |
| features = ['Fuel Surcharge Waiver', 'Insurance', 'Shopping Benefits', 'Airport Lounge Access', 'Co-Branded', 'Daily Spends (Grocery)', 'Dining Benefits', 'Domestic Travel Benefits', 'Entertainment', 'General Reward Points', 'Movie Benefits', 'Rupay Network Support', 'Student', 'UPI Transaction Support', 'Welcome Bonus', 'International Travel Benefits', 'premium', 'Flight Discounts', 'Hotel Benefits', 'Travel Benefits', 'Railway Benefits', 'Railway Lounge', 'Utility', 'Beginners (Entry Level)', 'E-commerce Platform Benefits', 'Air Miles', 'Jewellery Spends', 'Concierge Services', 'Food Delivery Benefits', 'Lifestyle & Luxury Perks', 'Spa Access Benefits', 'Golf Access & Perks', 'Super Premium', 'Frequent Flyer Benefits', 'Health Benefits', 'Rent Payment Benefits', 'Education', 'Lifetime Free', 'Roadside Assistance', 'EMI Conversion Options', 'No Forex Markup Fee', 'Secured FD Based', 'Cashback', 'Fuel Benefits', 'Business'] | |
| # Loading all 55 cards for comparison feature | |
| df_all_cards = pd.read_csv("credit_card_data_updated.csv") | |
| all_card_names = df_all_cards["name"].tolist() | |
| all_card_lookup = dict(zip(df_all_cards["name"], df_all_cards["description"])) | |
| eligibility_lookup = {} | |
| for _, row in eligibility_df.iterrows(): | |
| name = row["Name"].strip() | |
| eligibility_info = f""" | |
| - Bank: {row['Bank']} | |
| - Age: {row['Minimum Age']} to {row['Maximum Age']} | |
| - Minimum Income: {row['Minimum Income (LPA)']} LPA | |
| - Minimum Credit Score: {row['Minimum Credit Score']} | |
| - Joining Fee: ₹{row['Joining fee']} | |
| - Annual Fee: ₹{row['Annual fee']} | |
| """ | |
| eligibility_lookup[name] = eligibility_info.strip() | |
| def clean_gemini_response(text: str) -> str: | |
| # Remove Markdown headers (#, ##, ###, etc.) | |
| text = re.sub(r'^#+\s*', '', text, flags=re.MULTILINE) | |
| # Remove bold/italic symbols (* and **) | |
| text = re.sub(r'\*\*([^*]+)\*\*', r'\1', text) # Bold | |
| text = re.sub(r'\*([^*]+)\*', r'\1', text) # Italic | |
| # Remove bullets like -, *, etc. from start of lines | |
| text = re.sub(r'^\s*[-*•]\s+', '', text, flags=re.MULTILINE) | |
| # Collapse multiple newlines into 1–2 max | |
| text = re.sub(r'\n{3,}', '\n\n', text) | |
| # Strip leading/trailing whitespace | |
| return text.strip() | |