Akshayram1 commited on
Commit
71b78e0
·
verified ·
1 Parent(s): 025154e

Upload 2 files

Browse files
Files changed (2) hide show
  1. op.py +104 -0
  2. requirements.txt +4 -0
op.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import yfinance as yf
3
+ import requests
4
+ import json
5
+ import pandas as pd
6
+
7
+ # Setup Google Generative AI
8
+ GOOGLE_API_KEY = "AIzaSyCffMQoYpKJzdk46zTONhlQm6VI21ihWLQ"
9
+ GENERATIVE_MODEL = "gemini-1.5-flash"
10
+
11
+ def get_generative_ai_response(prompt):
12
+ try:
13
+ url = f"https://generativeai.googleapis.com/v1/models/{GENERATIVE_MODEL}:generateText?key={GOOGLE_API_KEY}"
14
+ headers = {
15
+ "Content-Type": "application/json",
16
+ }
17
+ payload = {
18
+ "prompt": prompt
19
+ }
20
+ response = requests.post(url, headers=headers, json=payload)
21
+ response.raise_for_status()
22
+ result = response.json()
23
+ return result.get('candidates', [{}])[0].get('output', 'No response text available')
24
+ except Exception as e:
25
+ st.error(f"Error fetching response from Generative AI: {e}")
26
+ return None
27
+
28
+ # Title
29
+ st.title("Investment Advice App")
30
+
31
+ # User inputs
32
+ monthly_savings = st.number_input("Enter your monthly savings (in Rs):", min_value=0, value=5000, step=100)
33
+ investment_duration = st.number_input("Enter the investment duration (in months):", min_value=1, value=24, step=1)
34
+
35
+ # Calculate total savings
36
+ total_savings = monthly_savings * investment_duration
37
+ st.write(f"Total savings after {investment_duration} months: Rs {total_savings}")
38
+
39
+ # Generate investment advice
40
+ st.header("Investment Advice")
41
+
42
+ # Risk Tolerance
43
+ risk_tolerance = st.selectbox("Select your risk tolerance level:", ["Low", "Moderate", "High"])
44
+
45
+ # User input for custom prompt
46
+ user_input_prompt = st.text_area("Enter your custom prompt for investment advice:", value=f"""
47
+ I am currently in class 11th and have 2 years before joining an engineering college. The total fees for 4 years of college is Rs. 10 lakh. I can save Rs. {monthly_savings} every month, accumulating a total amount of Rs. {total_savings} after {investment_duration} months.
48
+ I want to invest this money on a monthly basis to maximize profit or return with minimal risk, so that I can pay as much of my fees from the investment as possible.
49
+ Please provide specific companies, stocks, or mutual funds suitable for a {risk_tolerance} risk tolerance.
50
+ """)
51
+
52
+ if st.button("Get Investment Advice"):
53
+ response = get_generative_ai_response(user_input_prompt)
54
+ if response:
55
+ st.write(response)
56
+
57
+ # Fetch stock data using yfinance
58
+ def fetch_stock_data(ticker):
59
+ stock = yf.Ticker(ticker)
60
+ hist = stock.history(period="1y")
61
+ return hist
62
+
63
+ # Example stock tickers (you can replace these with your choices)
64
+ stock_tickers = {
65
+ "HDFC Bank": "HDFCBANK.NS",
66
+ "Reliance Industries": "RELIANCE.NS",
67
+ "TCS": "TCS.NS",
68
+ "Infosys": "INFY.NS"
69
+ }
70
+
71
+ # Display stock data
72
+ st.header("Stock Data")
73
+ for company, ticker in stock_tickers.items():
74
+ st.subheader(company)
75
+ data = fetch_stock_data(ticker)
76
+ st.line_chart(data["Close"])
77
+
78
+ # Monthly Savings Plan Table
79
+ st.header("Monthly Savings Plan")
80
+
81
+ # Table data
82
+ table_data = {
83
+ "Expense": ["Hostel Fees", "Mess Fees", "Personal Expenses", "Academic Supplies", "Miscellaneous"],
84
+ "Original Amount (Rs)": [5000, 3000, 2000, 1000, 1000],
85
+ "Savings Strategy": [
86
+ "Shared room or annual payment discount (10%)",
87
+ "Cooking 5 meals a month (saves Rs 50 per meal)",
88
+ "Reducing non-essential expenses by 20%",
89
+ "Buying second-hand or digital books (saves 30%)",
90
+ "Limiting miscellaneous spending by 20%"
91
+ ],
92
+ "New Amount (Rs)": [4500, 2750, 1600, 700, 800],
93
+ "Monthly Savings (Rs)": [500, 250, 400, 300, 200]
94
+ }
95
+
96
+ # Create DataFrame
97
+ df = pd.DataFrame(table_data)
98
+
99
+ # Display table
100
+ st.table(df)
101
+
102
+ # Footer
103
+ st.write("This app provides general investment advice based on your inputs. Please consult with a financial advisor before making any investment decisions.")
104
+
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit==1.21.0
2
+ yfinance==0.2.12
3
+ pandas==1.5.3
4
+ requests==2.28.2