Ujeshhh commited on
Commit
923c242
·
verified ·
1 Parent(s): 8b0f491

Create analysis.py

Browse files
Files changed (1) hide show
  1. analysis.py +24 -0
analysis.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+
3
+ # Load a free model for text generation
4
+ llm_pipeline = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct", device_map="auto")
5
+
6
+ def analyze_spending_pattern(df):
7
+ prompt = f"""
8
+ Here is the user's spending data:
9
+ {df.to_string(index=False)}
10
+
11
+ Identify spending trends, categorize expenses, and highlight areas for cost-saving.
12
+ """
13
+ response = llm_pipeline(prompt, max_length=200, do_sample=True)
14
+ return response[0]['generated_text']
15
+
16
+ def get_financial_advice(df):
17
+ prompt = f"""
18
+ Given the following transaction history:
19
+ {df.to_string(index=False)}
20
+
21
+ Provide personalized recommendations to reduce expenses and improve financial health.
22
+ """
23
+ response = llm_pipeline(prompt, max_length=200, do_sample=True)
24
+ return response[0]['generated_text']