Spaces:
Sleeping
Sleeping
File size: 1,353 Bytes
923c242 c75e97c 923c242 c75e97c 68d7ac2 c75e97c 923c242 c75e97c 923c242 c75e97c 923c242 |
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 38 39 |
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'] |