kritsadaK commited on
Commit
dd19cfd
·
verified ·
1 Parent(s): 5c1bad6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -17
app.py CHANGED
@@ -1,38 +1,50 @@
1
  import streamlit as st
2
-
3
- # Set page configuration first
4
- st.set_page_config(page_title="FinBrief: Financial Document Insights", layout="wide")
5
-
6
  import spacy
7
  import pandas as pd
8
  import re
9
- from transformers import pipeline
10
  import subprocess
 
 
 
11
 
12
- # Load the spaCy model once at the start
 
 
 
13
  try:
14
  nlp = spacy.load("en_core_web_sm")
15
- st.write("spaCy model loaded successfully!")
16
  except OSError:
17
- st.write("Failed to load spaCy model.")
18
  subprocess.run(["python", "-m", "spacy", "download", "en_core_web_sm"])
19
- nlp = spacy.load("en_core_web_sm")
20
-
21
- # Load the summarization model from Hugging Face Model Hub
 
 
 
 
 
 
22
  try:
23
- online_model_path = "kritsadaK/bart-financial-summarization"
24
- summarizer = pipeline("summarization", model=online_model_path, tokenizer=online_model_path)
25
- st.write("Online summarization model loaded successfully!")
 
 
26
  except Exception as e:
27
- summarizer = None # Handle case where model is missing
28
- st.write("Failed to load online summarization model.")
29
 
30
- # Initialize models in session state if not already loaded
31
  if "nlp" not in st.session_state:
32
  st.session_state["nlp"] = nlp
33
  if "summarizer" not in st.session_state:
34
  st.session_state["summarizer"] = summarizer
35
 
 
 
 
36
  # # Load the summarization model locally
37
  # try:
38
  # local_model_path = "./local_models/bart-financial"
 
1
  import streamlit as st
 
 
 
 
2
  import spacy
3
  import pandas as pd
4
  import re
 
5
  import subprocess
6
+ from transformers import pipeline, AutoModelForSeq2SeqLM, AutoTokenizer
7
+
8
+ st.set_page_config(page_title="FinBrief: Financial Document Insights", layout="wide")
9
 
10
+ # Debugging print
11
+ print("===== Starting FinBrief App =====")
12
+
13
+ # Load spaCy model
14
  try:
15
  nlp = spacy.load("en_core_web_sm")
16
+ print("spaCy model loaded successfully!")
17
  except OSError:
18
+ print(" spaCy model not found. Attempting to install...")
19
  subprocess.run(["python", "-m", "spacy", "download", "en_core_web_sm"])
20
+ try:
21
+ nlp = spacy.load("en_core_web_sm")
22
+ print("spaCy model installed and loaded successfully!")
23
+ except Exception as e:
24
+ print("❌ Failed to load spaCy model after installation:", e)
25
+ nlp = None
26
+
27
+ # Load Hugging Face model
28
+ model_name = "kritsadaK/bart-financial-summarization"
29
  try:
30
+ print(f"Attempting to load Hugging Face model: {model_name}")
31
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
32
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
33
+ summarizer = pipeline("summarization", model=model, tokenizer=tokenizer)
34
+ print("Hugging Face model loaded successfully!")
35
  except Exception as e:
36
+ print(f"Failed to load Hugging Face model: {e}")
37
+ summarizer = None
38
 
39
+ # Initialize session state
40
  if "nlp" not in st.session_state:
41
  st.session_state["nlp"] = nlp
42
  if "summarizer" not in st.session_state:
43
  st.session_state["summarizer"] = summarizer
44
 
45
+ # Debugging: Check session state initialization
46
+ print(f"Session State - NLP: {st.session_state['nlp'] is not None}, Summarizer: {st.session_state['summarizer'] is not None}")
47
+
48
  # # Load the summarization model locally
49
  # try:
50
  # local_model_path = "./local_models/bart-financial"