rajat5ranjan commited on
Commit
a76ae47
·
verified ·
1 Parent(s): 4a2c0ce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -40
app.py CHANGED
@@ -220,45 +220,8 @@ if activities=="Symbol Analysis":
220
  st.subheader("📝 Summary")
221
  # st.write(analysis_summary.summary)
222
  summary= analysis_summary.summary
223
- counts = {
224
- "BUY": summary["BUY"],
225
- "SELL": summary["SELL"],
226
- "NEUTRAL": summary["NEUTRAL"]
227
- }
228
-
229
- total = sum(counts.values())
230
-
231
- # Calculate percentage widths
232
- percentages = {k: (v / total) * 100 for k, v in counts.items()}
233
-
234
- # Color map
235
- color_map = {
236
- "BUY": "#4CAF50", # Green
237
- "SELL": "#F44336", # Red
238
- "NEUTRAL": "#FFC107" # Amber
239
- }
240
-
241
- # Create the stacked bar using HTML
242
- bar_html = '<div style="display: flex; height: 30px; width: 100%; border: 1px solid #ccc; border-radius: 5px; overflow: hidden;">'
243
- for key in ['BUY', 'SELL', 'NEUTRAL']:
244
- bar_html += f'''
245
- <div style="
246
- width: {percentages[key]}%;
247
- background-color: {color_map[key]};
248
- display: flex;
249
- justify-content: center;
250
- align-items: center;
251
- color: white;
252
- font-size: 12px;
253
- font-weight: bold;">
254
- {key} {counts[key]}
255
- </div>
256
- '''
257
- bar_html += '</div>'
258
-
259
- st.markdown("### Recommendation Summary")
260
- st.markdown(f"**Final Recommendation**: `{summary['RECOMMENDATION']}`")
261
- st.markdown(bar_html, unsafe_allow_html=True)
262
 
263
  # --- Row 2: Oscillators + Moving Averages ---
264
  # col3, col4 = st.columns(2)
@@ -405,4 +368,64 @@ if activities=="Symbol Analysis":
405
  st.write("Raw text was:")
406
  st.text(res["output_text"])
407
  elif activities=="News Sentiment":
408
- st.header("News Action : ")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
220
  st.subheader("📝 Summary")
221
  # st.write(analysis_summary.summary)
222
  summary= analysis_summary.summary
223
+ st.write(summary)
224
+ st.markdown(f"RECOMMENDATION : {summary["RECOMMENDATION"]} \n BUY: {summary["BUY"]} \n SELL : {summary["SELL"]}\n : NEUTRAL: {summary["NEUTRAL"]}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
 
226
  # --- Row 2: Oscillators + Moving Averages ---
227
  # col3, col4 = st.columns(2)
 
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