PersonalUPI / analysis.py
Ujeshhh's picture
Update analysis.py
68d7ac2 verified
raw
history blame
1.35 kB
from transformers import pipeline
from huggingface_hub import login
import pandas as pd
# 🔹 OPTIONAL: Authenticate if using a gated/private model
# login(token="your_huggingface_token") # Uncomment and replace if needed
# ✅ Use a Free Model (Mistral-7B-v0.1 OR Gemma-2B)
MODEL_NAME = "tiiuae/falcon-7b-instruct" # Open-source alternative # Publicly available
# MODEL_NAME = "google/gemma-2b" # Alternative (smaller but open-access)
# Load the text generation model
llm_pipeline = pipeline("text-generation", model=MODEL_NAME, device_map="auto")
def analyze_spending_pattern(df):
"""
Analyze the user's spending behavior.
"""
prompt = f"""
Here is the user's spending data:
{df.to_string(index=False)}
Identify spending trends, categorize expenses, and highlight areas for cost-saving.
"""
response = llm_pipeline(prompt, max_length=200, do_sample=True)
return response[0]['generated_text']
def get_financial_advice(df):
"""
Provide personalized financial recommendations.
"""
prompt = f"""
Given the following transaction history:
{df.to_string(index=False)}
Provide personalized recommendations to reduce expenses and improve financial health.
"""
response = llm_pipeline(prompt, max_length=200, do_sample=True)
return response[0]['generated_text']