gauri-sharan commited on
Commit
7f6c604
·
verified ·
1 Parent(s): c8c683f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -38
app.py CHANGED
@@ -1,42 +1,17 @@
1
- import yfinance as yf
2
  import gradio as gr
3
- from langchain.chains import LLMChain
4
- from langchain.prompts import PromptTemplate
5
- from langchain.llms import LlamaCpp
6
-
7
- # Define Llama model (you must provide the path to your Llama model)
8
- llama_model = LlamaCpp(model_path="path_to_your_llama_model.bin")
9
-
10
- # Set up Langchain LLM
11
- llm_chain = LLMChain(llm=llama_model)
12
-
13
- # Define the prompt template for querying the LLM about stock details
14
- prompt_template = """
15
- You are a stock market assistant. Please provide detailed information about the stock.
16
- The stock symbol is: {stock_symbol}.
17
- """
18
- stock_prompt = PromptTemplate(input_variables=["stock_symbol"], template=prompt_template)
19
-
20
- # Function to get stock data from Yahoo Finance
21
- def get_stock_data(stock_symbol):
22
- stock = yf.Ticker(stock_symbol)
23
- stock_info = stock.info # Get company info
24
- stock_price = stock_info['currentPrice'] # Get current stock price
25
- company_name = stock_info.get('shortName', 'N/A')
26
- sector = stock_info.get('sector', 'N/A')
27
- market_cap = stock_info.get('marketCap', 'N/A')
28
-
29
- # Generate a response using Langchain LLM
30
- stock_details = llm_chain.run(stock_prompt.format(stock_symbol=stock_symbol))
31
-
32
- return f"Company: {company_name}\nSector: {sector}\nMarket Cap: {market_cap}\nStock Price: ${stock_price}\n\nDetailed Information: {stock_details}"
33
-
34
- # Gradio Interface
35
- def stock_market_agent(stock_symbol):
36
- return get_stock_data(stock_symbol)
37
-
38
- # Set up Gradio UI
39
- iface = gr.Interface(fn=stock_market_agent,
40
  inputs=gr.Textbox(label="Enter Stock Symbol (e.g., AAPL)"),
41
  outputs="text",
42
  title="Stock Market Agent",
 
 
1
  import gradio as gr
2
+ from yahoo_fin import stock_info
3
+
4
+ def get_stock_info(symbol):
5
+ try:
6
+ # Fetch real-time stock price
7
+ price = stock_info.get_live_price(symbol)
8
+ # Fetch company information
9
+ company_info = stock_info.get_quote_table(symbol)
10
+ return f"Company: {company_info['Name']}\nSector: {company_info['Sector']}\nMarket Cap: {company_info['Market Cap']}\nStock Price: ${price:.2f}"
11
+ except Exception as e:
12
+ return f"Error retrieving data: {e}"
13
+
14
+ iface = gr.Interface(fn=get_stock_info,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  inputs=gr.Textbox(label="Enter Stock Symbol (e.g., AAPL)"),
16
  outputs="text",
17
  title="Stock Market Agent",