Update app.py
Browse files
app.py
CHANGED
@@ -341,32 +341,32 @@ else:
|
|
341 |
if st.button("Analyze"):
|
342 |
# Ensure full extracted text is used for analysis
|
343 |
text_for_analysis = st.session_state["pdf_text"].strip() if st.session_state["pdf_text"] else example_text.strip()
|
344 |
-
|
345 |
if text_for_analysis:
|
346 |
with st.spinner("Analyzing text..."):
|
347 |
# Extract structured financial data using regex (Now using full text)
|
348 |
extracted_data = {
|
349 |
key: (match.group(1) if match else "N/A")
|
350 |
for key, pattern in patterns.items()
|
351 |
-
|
352 |
-
|
353 |
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
|
358 |
-
|
359 |
-
|
360 |
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
|
365 |
-
|
366 |
-
|
367 |
|
368 |
-
|
369 |
-
|
370 |
|
371 |
# Step 4: Summarization
|
372 |
st.subheader("Summarization")
|
|
|
341 |
if st.button("Analyze"):
|
342 |
# Ensure full extracted text is used for analysis
|
343 |
text_for_analysis = st.session_state["pdf_text"].strip() if st.session_state["pdf_text"] else example_text.strip()
|
344 |
+
|
345 |
if text_for_analysis:
|
346 |
with st.spinner("Analyzing text..."):
|
347 |
# Extract structured financial data using regex (Now using full text)
|
348 |
extracted_data = {
|
349 |
key: (match.group(1) if match else "N/A")
|
350 |
for key, pattern in patterns.items()
|
351 |
+
if (match := re.search(pattern, text_for_analysis, re.IGNORECASE))
|
352 |
+
}
|
353 |
|
354 |
+
# ✅ Correct indentation
|
355 |
+
doc = nlp(text_for_analysis)
|
356 |
+
financial_entities = [(ent.text, ent.label_) for ent in doc.ents if ent.label_ in ["MONEY", "PERCENT", "ORG", "DATE"]]
|
357 |
|
358 |
+
# Store extracted data in a structured dictionary
|
359 |
+
structured_data = {**extracted_data, "Named Entities Extracted": financial_entities}
|
360 |
|
361 |
+
# Display results
|
362 |
+
st.write("Entities Found:")
|
363 |
+
st.write(pd.DataFrame(financial_entities, columns=["Entity", "Label"]))
|
364 |
|
365 |
+
st.write("Structured Data Extracted:")
|
366 |
+
st.write(pd.DataFrame([structured_data]))
|
367 |
|
368 |
+
else:
|
369 |
+
st.error("Please provide some text for analysis.")
|
370 |
|
371 |
# Step 4: Summarization
|
372 |
st.subheader("Summarization")
|