Update app.py
Browse files
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 |
-
#
|
|
|
|
|
|
|
|
|
|
| 13 |
try:
|
| 14 |
nlp = spacy.load("en_core_web_sm")
|
| 15 |
-
|
| 16 |
except OSError:
|
| 17 |
-
|
| 18 |
subprocess.run(["python", "-m", "spacy", "download", "en_core_web_sm"])
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
try:
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
except Exception as e:
|
| 27 |
-
|
| 28 |
-
|
| 29 |
|
| 30 |
-
# Initialize
|
| 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"
|