rajat5ranjan commited on
Commit
7dbcf5d
·
verified ·
1 Parent(s): 552be85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -2
app.py CHANGED
@@ -383,7 +383,7 @@ elif activities=="News Sentiment":
383
  # url6
384
  ])
385
  docs = loader.load()
386
- st.write(docs)
387
  st.divider()
388
 
389
  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:
@@ -425,6 +425,45 @@ elif activities=="News Sentiment":
425
 
426
  # res = stuff_chain.invoke(docs)
427
  res = stuff_chain.invoke({"input_documents": docs})
428
- st.write(res["output_text"])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
429
  else:
430
  pass
 
383
  # url6
384
  ])
385
  docs = loader.load()
386
+ # st.write(docs)
387
  st.divider()
388
 
389
  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:
 
425
 
426
  # res = stuff_chain.invoke(docs)
427
  res = stuff_chain.invoke({"input_documents": docs})
428
+ raw_text = res["output_text"]
429
+ # Remove markdown code block delimiters if present
430
+ if raw_text.startswith("```json"):
431
+ raw_text = raw_text[len("```json"):]
432
+
433
+ if raw_text.endswith("```"):
434
+ raw_text = raw_text[:-3]
435
+
436
+ # Also strip leading/trailing whitespace/newlines
437
+ raw_text = raw_text.strip()
438
+
439
+ # Parse JSON
440
+ parsed_data = json.loads(raw_text)
441
+ top_picks = parsed_data.get("top_picks", [])
442
+
443
+ st.set_page_config(page_title="Stock Insights", layout="wide")
444
+ st.title("📊 Weekly Stock Insights from News")
445
+
446
+ # Layout
447
+ for stock in top_picks:
448
+ col1, col2 = st.columns([3, 1])
449
+ with col1:
450
+ st.subheader(f"{stock['company']} ({stock['ticker']})")
451
+ st.markdown(f"**📰 Critical News:** {stock['critical_news']}")
452
+ st.markdown(f"**📈 Impact Summary:** {stock['impact_summary']}")
453
+ st.markdown(f"**💡 Reason for Top Pick:** {stock['reason']}")
454
+ with col2:
455
+ sentiment_color = {
456
+ "Bullish": "🟢 Bullish",
457
+ "Bearish": "🔴 Bearish",
458
+ "Neutral": "🟡 Neutral"
459
+ }.get(stock["sentiment"], stock["sentiment"])
460
+ st.metric(label="Sentiment", value=sentiment_color)
461
+ st.markdown(f"**🚦 Action:** `{stock['action']}`")
462
+
463
+ st.divider()
464
+ st.caption("Data analyzed using LLM from TradingView India news feed.")
465
+
466
+
467
+
468
  else:
469
  pass