import pandas as pd import matplotlib.pyplot as plt def analyze_portfolio(file, risk_profile): if isinstance(file, str): # Example file path df = pd.read_csv(file) else: # Uploaded file df = pd.read_csv(file.name) # Generate pie chart fig, ax = plt.subplots(figsize=(6, 6)) df.groupby('Asset')['Value'].sum().plot.pie( autopct='%1.1f%%', ax=ax, ylabel='', startangle=90 ) plt.title('Current Allocation') # Generate recommendations recs = f"✅ {risk_profile} Portfolio Recommendations:\n" recs += "- Consider adding international stocks (15-20%)\n" recs += "- Reduce tech sector exposure by 5-10%\n" recs += "- Increase bond allocation to 20% for better stability" return fig, recs