rajat5ranjan commited on
Commit
e09d14e
·
verified ·
1 Parent(s): 8234189

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -57
app.py CHANGED
@@ -40,10 +40,10 @@ llm = ChatGoogleGenerativeAI(model="gemini-2.5-pro",google_api_key = GOOGLE_API_
40
  #llm_vis = ChatGoogleGenerativeAI(model="gemini-pro-vision",google_api_key = GOOGLE_API_KEY)
41
 
42
 
43
- activities = st.sidebar.selectbox("Select",["Symbol Analysis","News Sentiment"])
44
 
45
 
46
- if activities=="Symbol Analysis":
47
  ticker_user = st.text_input("Enter Ticker for NSE Stocks","")
48
  def get_tradingview_analysis(symbol, exchange, screener, interval):
49
  try:
@@ -367,65 +367,65 @@ if activities=="Symbol Analysis":
367
  st.error(f"JSON decode error: {e}")
368
  st.write("Raw text was:")
369
  st.text(res["output_text"])
370
- elif activities=="News Sentiment":
371
- st.subheader("News Action : ")
372
- url1 = f"https://in.tradingview.com/news-flow/?market=stock&market_country=in"
373
- # url2 = f"https://in.tradingview.com/symbols/NSE-{ticker_user}/"
374
- # url3 = f"https://in.tradingview.com/symbols/NSE-{ticker_user}/news/"
375
- # url4 = f"https://in.tradingview.com/symbols/NSE-{ticker_user}/minds/"
 
 
 
376
 
377
- loader = WebBaseLoader([url1])
378
- docs = loader.load()
379
-
380
- st.divider()
381
 
382
- llm_prompt_template = """You are an expert Stock Market Trader specializing in stock market insights derived from fundamental analysis, analytical trends, profit-based evaluations, news indicators from different sites and detailed company financials. You will receive one or more news articles from TradingView’s India stock news feed. For each article, perform the following tasks:
383
 
384
- Context:
385
- {input_documents}
386
 
387
-
388
- 1. **Identify the stock(s)** mentioned (by ticker and company name).
389
- 2. **Sentiment analysis**: classify as Bullish, Bearish, or Neutral.
390
- 3. **Extract critical news**: What is the main event or update? (e.g., earnings beat, regulatory approval, management change, major contract or macro impact).
391
- 4. **Summarize impact**: Briefly explain how this news might affect stock price and investor behavior (e.g., “could boost investor confidence”, “sign indicates profit pressure”, etc.).
392
- 5. **Actionable signal**: Based on the sentiment and news, suggest whether this is a “Buy”, “Sell”, “Hold”, or “Watch” recommendation, and the rationale.
393
- 6. **Overall top picks**: After analyzing all provided articles, rank the top 3–5 stocks to look at this week, including tickers, current sentiment, and why they made the list.
394
-
395
- ***Format your output as JSON*** with the following structure:
396
-
397
- ```json
 
 
398
  {{
399
- "articles": [
400
- {{
401
- "ticker": "TICKER",
402
- "company": "Company Name",
403
- "sentiment": "Bullish|Bearish|Neutral",
404
- "critical_news": "Brief summary of the key event",
405
- "impact_summary": "How this may affect the stock",
406
- "action": "Buy|Sell|Hold|Watch"
407
- }},
408
- ...
409
- ],
410
- "top_picks": [
411
- {{
412
- "ticker": "TICKER",
413
- "company": "Company Name",
414
- "sentiment": "Bullish|Bearish|Neutral",
415
- "reason": "Why this stock ranks among top picks"
416
- }},
417
- ...
418
- ]
419
- }}
420
 
421
- """
422
- llm_prompt = PromptTemplate.from_template(llm_prompt_template)
 
 
 
423
 
424
- llm_chain = LLMChain(llm=llm,prompt=llm_prompt)
425
- stuff_chain = StuffDocumentsChain(llm_chain=llm_chain,document_variable_name="input_documents")
426
-
427
- # res = stuff_chain.invoke(docs)
428
- res = stuff_chain.invoke({"input_documents": docs})
429
- st.write(res["output_text"])
430
- else:
431
- pass
 
40
  #llm_vis = ChatGoogleGenerativeAI(model="gemini-pro-vision",google_api_key = GOOGLE_API_KEY)
41
 
42
 
43
+ activities = st.sidebar.selectbox("Select", ["Symbol Analysis", "News Sentiment"])
44
 
45
 
46
+ if activities == "Symbol Analysis":
47
  ticker_user = st.text_input("Enter Ticker for NSE Stocks","")
48
  def get_tradingview_analysis(symbol, exchange, screener, interval):
49
  try:
 
367
  st.error(f"JSON decode error: {e}")
368
  st.write("Raw text was:")
369
  st.text(res["output_text"])
370
+ elif activities=="News Sentiment":
371
+ st.subheader("News Action : ")
372
+ url1 = f"https://in.tradingview.com/news-flow/?market=stock&market_country=in"
373
+ # url2 = f"https://in.tradingview.com/symbols/NSE-{ticker_user}/"
374
+ # url3 = f"https://in.tradingview.com/symbols/NSE-{ticker_user}/news/"
375
+ # url4 = f"https://in.tradingview.com/symbols/NSE-{ticker_user}/minds/"
376
+
377
+ loader = WebBaseLoader([url1])
378
+ docs = loader.load()
379
 
380
+ st.divider()
 
 
 
381
 
382
+ llm_prompt_template = """You are an expert Stock Market Trader specializing in stock market insights derived from fundamental analysis, analytical trends, profit-based evaluations, news indicators from different sites and detailed company financials. You will receive one or more news articles from TradingView’s India stock news feed. For each article, perform the following tasks:
383
 
384
+ Context:
385
+ {input_documents}
386
 
387
+
388
+ 1. **Identify the stock(s)** mentioned (by ticker and company name).
389
+ 2. **Sentiment analysis**: classify as Bullish, Bearish, or Neutral.
390
+ 3. **Extract critical news**: What is the main event or update? (e.g., earnings beat, regulatory approval, management change, major contract or macro impact).
391
+ 4. **Summarize impact**: Briefly explain how this news might affect stock price and investor behavior (e.g., “could boost investor confidence”, “sign indicates profit pressure”, etc.).
392
+ 5. **Actionable signal**: Based on the sentiment and news, suggest whether this is a “Buy”, “Sell”, “Hold”, or “Watch” recommendation, and the rationale.
393
+ 6. **Overall top picks**: After analyzing all provided articles, rank the top 3–5 stocks to look at this week, including tickers, current sentiment, and why they made the list.
394
+
395
+ ***Format your output as JSON*** with the following structure:
396
+
397
+ ```json
398
+ {{
399
+ "articles": [
400
  {{
401
+ "ticker": "TICKER",
402
+ "company": "Company Name",
403
+ "sentiment": "Bullish|Bearish|Neutral",
404
+ "critical_news": "Brief summary of the key event",
405
+ "impact_summary": "How this may affect the stock",
406
+ "action": "Buy|Sell|Hold|Watch"
407
+ }},
408
+ ...
409
+ ],
410
+ "top_picks": [
411
+ {{
412
+ "ticker": "TICKER",
413
+ "company": "Company Name",
414
+ "sentiment": "Bullish|Bearish|Neutral",
415
+ "reason": "Why this stock ranks among top picks"
416
+ }},
417
+ ...
418
+ ]
419
+ }}
 
 
420
 
421
+ """
422
+ llm_prompt = PromptTemplate.from_template(llm_prompt_template)
423
+
424
+ llm_chain = LLMChain(llm=llm,prompt=llm_prompt)
425
+ stuff_chain = StuffDocumentsChain(llm_chain=llm_chain,document_variable_name="input_documents")
426
 
427
+ # res = stuff_chain.invoke(docs)
428
+ res = stuff_chain.invoke({"input_documents": docs})
429
+ st.write(res["output_text"])
430
+ else:
431
+ pass