akazmi commited on
Commit
6c3cb3c
·
verified ·
1 Parent(s): fcc9344

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -61,11 +61,12 @@ if stock_symbol:
61
  for article in news_articles:
62
  st.write(f"- {article}")
63
 
64
- # Key Financial Entities extraction
65
  st.subheader("Extracted Key Financial Entities")
66
  if input_text:
67
  entities = ner(input_text)
68
- for entity in entities:
 
69
  st.write(f"Entity: {entity['word']}, Label: {entity.get('entity', 'N/A')}, Score: {entity['score']:.2f}")
70
 
71
  # Sentiment Analysis
@@ -75,10 +76,11 @@ if input_text:
75
  for result in sentiment:
76
  st.write(f"Sentiment: {result['label']}, Score: {result['score']:.2f}")
77
 
78
- # Investment Advice or Strategy Generation
79
  st.subheader("Investment Advice or Strategy")
80
  if input_text:
81
- advice = text_generator(f"Provide an investment strategy for {selected_example if selected_example != 'Other' else 'the selected stock'}: {input_text}", max_length=50, num_return_sequences=1)
 
82
  st.write(advice[0]['generated_text'])
83
  else:
84
  st.write("No investment advice generated. Please select a stock or enter custom text.")
 
61
  for article in news_articles:
62
  st.write(f"- {article}")
63
 
64
+ # Key Financial Entities extraction with filtering
65
  st.subheader("Extracted Key Financial Entities")
66
  if input_text:
67
  entities = ner(input_text)
68
+ filtered_entities = [entity for entity in entities if entity['score'] > 0.7 and entity['word'].isalpha()] # Filter low-score and non-alphabetic tokens
69
+ for entity in filtered_entities:
70
  st.write(f"Entity: {entity['word']}, Label: {entity.get('entity', 'N/A')}, Score: {entity['score']:.2f}")
71
 
72
  # Sentiment Analysis
 
76
  for result in sentiment:
77
  st.write(f"Sentiment: {result['label']}, Score: {result['score']:.2f}")
78
 
79
+ # Investment Advice or Strategy Generation with better prompt handling
80
  st.subheader("Investment Advice or Strategy")
81
  if input_text:
82
+ prompt = f"Provide a clear and concise investment strategy for {selected_example if selected_example != 'Other' else 'the selected stock'} based on recent news and financial performance. "
83
+ advice = text_generator(prompt + input_text, max_length=80, num_return_sequences=1)
84
  st.write(advice[0]['generated_text'])
85
  else:
86
  st.write("No investment advice generated. Please select a stock or enter custom text.")