rajat5ranjan commited on
Commit
8d310cf
·
verified ·
1 Parent(s): d01f49e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -1
app.py CHANGED
@@ -15,6 +15,11 @@ from langchain.chains.llm import LLMChain
15
  from langchain.chains import StuffDocumentsChain
16
  from langchain_core.messages import HumanMessage
17
  import requests
 
 
 
 
 
18
  st.set_page_config(layout="wide")
19
 
20
  GOOGLE_API_KEY=os.environ['GOOGLE_API_KEY']
@@ -30,6 +35,21 @@ gemini_embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001")
30
 
31
  llm = ChatGoogleGenerativeAI(model="gemini-1.5-pro",google_api_key = GOOGLE_API_KEY)
32
  llm_vis = ChatGoogleGenerativeAI(model="gemini-pro-vision",google_api_key = GOOGLE_API_KEY)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  if ticker_user!="":
34
  url1 = f"https://www.google.com/finance/quote/{ticker_user}:NSE?hl=en"
35
  url2 = f"https://in.tradingview.com/symbols/NSE-{ticker_user}/"
@@ -67,7 +87,40 @@ if ticker_user!="":
67
 
68
  # st.sidebar.subheader('Prompt')
69
  # user_prompt = st.sidebar.text_area("Enter Prompt",llm_prompt_template)
70
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  url = "https://api.chart-img.com/v2/tradingview/advanced-chart"
72
  api_key = "l0iUFRSeqC9z7nDPTd1hnafPh2RrdcEy6rl6tNqV"
73
  headers = {
 
15
  from langchain.chains import StuffDocumentsChain
16
  from langchain_core.messages import HumanMessage
17
  import requests
18
+ from tradingview_ta import TA_Handler, Interval
19
+ import yfinance as yf
20
+ from datetime import datetime, timedelta
21
+ from newsapi import NewsApiClient
22
+
23
  st.set_page_config(layout="wide")
24
 
25
  GOOGLE_API_KEY=os.environ['GOOGLE_API_KEY']
 
35
 
36
  llm = ChatGoogleGenerativeAI(model="gemini-1.5-pro",google_api_key = GOOGLE_API_KEY)
37
  llm_vis = ChatGoogleGenerativeAI(model="gemini-pro-vision",google_api_key = GOOGLE_API_KEY)
38
+
39
+ def get_tradingview_analysis(symbol, exchange, screener, interval):
40
+ try:
41
+ stock = TA_Handler(
42
+ symbol=symbol,
43
+ screener=screener,
44
+ exchange=exchange,
45
+ interval=interval,
46
+ )
47
+ analysis_summary = stock.get_analysis()
48
+ return analysis_summary
49
+ except Exception as e:
50
+ return {"error": str(e)}
51
+
52
+
53
  if ticker_user!="":
54
  url1 = f"https://www.google.com/finance/quote/{ticker_user}:NSE?hl=en"
55
  url2 = f"https://in.tradingview.com/symbols/NSE-{ticker_user}/"
 
87
 
88
  # st.sidebar.subheader('Prompt')
89
  # user_prompt = st.sidebar.text_area("Enter Prompt",llm_prompt_template)
90
+ #https://huggingface.co/spaces/pradeepodela/Stock-Analyser/blob/main/app.py
91
+ interval = Interval.INTERVAL_1_DAY
92
+ analysis_summary = get_tradingview_analysis(
93
+ symbol=ticker_user,
94
+ exchange="NSE",
95
+ screener="india",
96
+ interval=interval,
97
+ )
98
+
99
+ st.title("Analysis Summary")
100
+ st.dataframe(analysis_summary.summary)
101
+ query = f"{symbol} stock"
102
+
103
+ details = {
104
+ "symbol": ticker_user,
105
+ "exchange": "NSE",
106
+ "screener": "india",
107
+ "interval": interval,
108
+ }
109
+ st.title("Details")
110
+ st.dataframe(details)
111
+
112
+ st.title("Oscillator Analysis")
113
+ st.dataframe(analysis_summary.oscillators)
114
+
115
+ st.title("Moving Averages")
116
+ st.dataframe(analysis_summary.moving_averages)
117
+
118
+ st.title("Summary")
119
+ st.dataframe(analysis_summary.summary)
120
+
121
+ st.title("Indicators")
122
+ st.dataframe(analysis_summary.indicators)
123
+
124
  url = "https://api.chart-img.com/v2/tradingview/advanced-chart"
125
  api_key = "l0iUFRSeqC9z7nDPTd1hnafPh2RrdcEy6rl6tNqV"
126
  headers = {