subramanyamrekhandar commited on
Commit
f43d06f
Β·
verified Β·
1 Parent(s): 98729e8

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +80 -0
  2. banner.jpeg +0 -0
  3. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import os
4
+ from dotenv import load_dotenv
5
+ import groq # Import Groq API SDK
6
+
7
+ # Load environment variables
8
+ load_dotenv()
9
+
10
+ # Initialize Groq Client
11
+ GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
12
+ client = groq.Client(api_key=GROQ_API_KEY)
13
+
14
+ # Set API key for Financial Modeling Prep (FMP)
15
+ FMP_API_KEY = os.environ.get("FMP_API_KEY")
16
+ # FMP_API_KEY="9oIC7Pv2OyjTcw2QarsR71Ct8D053ced"
17
+
18
+ # Function to fetch stock data from Financial Modeling Prep API
19
+ def get_stock_data(symbol):
20
+ url = f"https://financialmodelingprep.com/api/v3/quote/{symbol}?apikey={FMP_API_KEY}"
21
+ response = requests.get(url)
22
+ if response.status_code == 200 and response.json():
23
+ return response.json()[0]
24
+ return None
25
+
26
+ # Function to generate AI response using Groq
27
+ def get_ai_response(prompt):
28
+ model_name = "llama-3.3-70b-versatile" # More stable model
29
+ messages = [{"role": "user", "content": prompt}]
30
+
31
+ try:
32
+ response = client.chat.completions.create(
33
+ model=model_name,
34
+ messages=messages,
35
+ stream=False # Using non-streaming for reliability
36
+ )
37
+ return response.choices[0].message.content if response.choices else "No response received."
38
+ except Exception as exc:
39
+ return f"❌ Error: {exc}"
40
+
41
+ # Streamlit UI
42
+ st.set_page_config(page_title="AI Financial Assistant", page_icon="πŸ’°", layout="centered")
43
+
44
+ # Sidebar Navigation
45
+ st.sidebar.title("Navigation")
46
+ # page = st.sidebar.radio("Go to", ["Home", "AI Assistant"])
47
+ page = st.sidebar.selectbox('Select a page:',
48
+ ['Home', 'AI Assistant'])
49
+
50
+ if page == "Home":
51
+
52
+ st.title("Welcome to AI Financial Assistant πŸ’°")
53
+ st.write("This tool helps you with stock market insights and financial advice.")
54
+ st.write("Navigate to 'AI Assistant' to get started.")
55
+ st.markdown("---")
56
+ st.write("Developed by **Subramanyam Rekhandar**")
57
+ st.image("banner.jpeg", use_container_width=True) # Add banner image
58
+
59
+ elif page == "AI Assistant":
60
+ st.title("πŸ’° AI Financial Assistant")
61
+ st.write("Ask me about stock prices, market trends, or investment advice!")
62
+
63
+ query = st.text_input("Enter a stock symbol (e.g., AAPL) or a financial question:")
64
+
65
+ if st.button("Get Insights"):
66
+ if query.upper().isalpha(): # Check if input is a stock symbol
67
+ data = get_stock_data(query.upper())
68
+ if data:
69
+ st.write(f"### {data['name']} ({data['symbol']})")
70
+ st.write(f"πŸ“ˆ Price: ${data['price']}")
71
+ st.write(f"πŸ“Š Change: {data['change']} ({data['changesPercentage']}%)")
72
+ else:
73
+ st.write("⚠️ Stock data not found. Try a different symbol.")
74
+ else: # Treat input as a general finance query
75
+ with st.spinner("πŸ’¬ Thinking..."):
76
+ response = get_ai_response(query)
77
+ st.write(response)
78
+
79
+ st.markdown("---")
80
+ st.write("πŸ” Data sourced from Financial Modeling Prep & Groq AI.")
banner.jpeg ADDED
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ groq
2
+ streamlit
3
+ python-dotenv
4
+ requests