Download data.py from Sulaiman8/Credit-Card-Recommender-Knowledge-graph-implementation: direct link, hf CLI and curl.
- Browser
- Download file 1.94 kB
-
https://huggingface.co/spaces/Sulaiman8/Credit-Card-Recommender-Knowledge-graph-implementation/resolve/main/data.py
- Command line
-
hf download hf://spaces/Sulaiman8/Credit-Card-Recommender-Knowledge-graph-implementation/data.py
-
curl -L -o data.py https://huggingface.co/spaces/Sulaiman8/Credit-Card-Recommender-Knowledge-graph-implementation/resolve/main/data.py
1.94 kB
| import json | |
| import pandas as pd | |
| import os | |
| from neo4j import GraphDatabase | |
| #neo4j credentials | |
| NEO4J_URI = os.environ.get("NEO4J_URI") | |
| NEO4J_USER = os.environ.get("NEO4J_USER") | |
| NEO4J_PASS = os.environ.get("NEO4J_PASS") | |
| _driver=None | |
| def get_driver(): | |
| global _driver | |
| if _driver is None: | |
| _driver = GraphDatabase.driver(NEO4J_URI, auth=(NEO4J_USER, NEO4J_PASS)) | |
| return _driver | |
| #for adding bank name to the cards in the graph | |
| eligibility_df = pd.read_csv("cards_eligibility_updated.csv") | |
| card_to_bank = dict(zip(eligibility_df['Name'], eligibility_df['Bank'])) | |
| # Loading credit card data | |
| df = pd.read_csv("credit_card_data_updated.csv") | |
| card_descriptions = dict(zip(df["name"], df["description"])) | |
| # 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"])) | |
| with open('for_graph_construction_(expanded labels).json') as f: | |
| card_feature_data = json.load(f) | |
| card_features_lookup = { | |
| card['card_name']: set(card['features']) | |
| for card in card_feature_data | |
| } | |
| #function for the chatbot functionality | |
| eligibility_lookup = {} | |
| for _, row in eligibility_df.iterrows(): | |
| card_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[card_name] = eligibility_info.strip() | |
| def get_all_features(): | |
| with get_driver().session() as session: | |
| result = session.run("MATCH (f:Feature) RETURN f.name AS feature") | |
| return [record["feature"] for record in result] | |
| features = get_all_features() | |