Spaces:
Runtime error
Runtime error
Commit
Β·
cdadb63
1
Parent(s):
92e9b31
UI imrpovements
Browse files- README.md +1 -1
- app.py +58 -21
- document_processor.py +2 -0
README.md
CHANGED
|
@@ -75,7 +75,7 @@ PDF Upload β LlamaIndex Parser β Vector Index β OpenAI Analysis β Cited
|
|
| 75 |
|
| 76 |
```bash
|
| 77 |
# Clone the repository
|
| 78 |
-
git clone
|
| 79 |
cd investment-screener
|
| 80 |
|
| 81 |
# Install dependencies
|
|
|
|
| 75 |
|
| 76 |
```bash
|
| 77 |
# Clone the repository
|
| 78 |
+
git clone https://huggingface.co/spaces/sukhrobnurali/financial-document-analyzer
|
| 79 |
cd investment-screener
|
| 80 |
|
| 81 |
# Install dependencies
|
app.py
CHANGED
|
@@ -54,12 +54,51 @@ st.markdown("""
|
|
| 54 |
display: inline-block;
|
| 55 |
margin: 0.5rem 0;
|
| 56 |
}
|
| 57 |
-
|
| 58 |
-
background
|
| 59 |
-
border-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
}
|
| 64 |
.metric-card {
|
| 65 |
background-color: #ffffff;
|
|
@@ -67,6 +106,7 @@ st.markdown("""
|
|
| 67 |
border-radius: 0.5rem;
|
| 68 |
border: 1px solid #e0e0e0;
|
| 69 |
margin: 1rem 0;
|
|
|
|
| 70 |
}
|
| 71 |
</style>
|
| 72 |
""", unsafe_allow_html=True)
|
|
@@ -110,9 +150,6 @@ def display_analysis_result(result, criteria_name):
|
|
| 110 |
st.markdown("### Summary")
|
| 111 |
st.info(result['summary'])
|
| 112 |
|
| 113 |
-
# Detailed metrics
|
| 114 |
-
st.markdown("### Detailed Analysis")
|
| 115 |
-
|
| 116 |
# Remove metadata fields for display
|
| 117 |
metrics = {k: v for k, v in result.items()
|
| 118 |
if k not in ['overall_pass', 'summary', 'citations', 'source_nodes_count', 'parse_error', 'raw_response']}
|
|
@@ -129,11 +166,6 @@ def display_analysis_result(result, criteria_name):
|
|
| 129 |
for citation in result['citations'][:5]: # Show top 5 citations
|
| 130 |
display_citation(citation)
|
| 131 |
|
| 132 |
-
# Debug: Show raw response if parse error
|
| 133 |
-
if result.get('parse_error'):
|
| 134 |
-
with st.expander("Raw LLM Response (Debug)"):
|
| 135 |
-
st.text(result.get('raw_response', 'No response'))
|
| 136 |
-
|
| 137 |
|
| 138 |
def display_metric_card(metric_name, metric_data):
|
| 139 |
"""Display a single metric card with citation."""
|
|
@@ -174,13 +206,18 @@ def display_metric_card(metric_name, metric_data):
|
|
| 174 |
|
| 175 |
|
| 176 |
def display_citation(citation):
|
| 177 |
-
"""Display a citation
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
|
| 185 |
|
| 186 |
def main():
|
|
|
|
| 54 |
display: inline-block;
|
| 55 |
margin: 0.5rem 0;
|
| 56 |
}
|
| 57 |
+
div[data-testid="stExpander"] {
|
| 58 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
|
| 59 |
+
border-radius: 12px;
|
| 60 |
+
border: none;
|
| 61 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 62 |
+
margin: 0.75rem 0;
|
| 63 |
+
}
|
| 64 |
+
div[data-testid="stExpander"]:hover {
|
| 65 |
+
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
|
| 66 |
+
}
|
| 67 |
+
div[data-testid="stExpander"] summary {
|
| 68 |
+
background: transparent !important;
|
| 69 |
+
color: white !important;
|
| 70 |
+
font-weight: 500;
|
| 71 |
+
padding: 1rem 1.25rem;
|
| 72 |
+
}
|
| 73 |
+
div[data-testid="stExpander"] summary:hover {
|
| 74 |
+
background: transparent !important;
|
| 75 |
+
}
|
| 76 |
+
div[data-testid="stExpander"][open] summary {
|
| 77 |
+
background: transparent !important;
|
| 78 |
+
}
|
| 79 |
+
div[data-testid="stExpander"] div[role="button"] {
|
| 80 |
+
background: transparent !important;
|
| 81 |
+
}
|
| 82 |
+
div[data-testid="stExpander"] div[role="button"] p {
|
| 83 |
+
color: white !important;
|
| 84 |
+
font-size: 0.95rem;
|
| 85 |
+
}
|
| 86 |
+
div[data-testid="stExpander"] > div > div {
|
| 87 |
+
padding: 0 1.25rem 1.25rem 1.25rem;
|
| 88 |
+
color: white;
|
| 89 |
+
}
|
| 90 |
+
.citation-preview {
|
| 91 |
+
color: white;
|
| 92 |
+
font-size: 0.9rem;
|
| 93 |
+
line-height: 1.6;
|
| 94 |
+
opacity: 0.95;
|
| 95 |
+
margin-top: 0.5rem;
|
| 96 |
+
}
|
| 97 |
+
.citation-full {
|
| 98 |
+
color: white;
|
| 99 |
+
font-size: 0.9rem;
|
| 100 |
+
line-height: 1.6;
|
| 101 |
+
opacity: 0.95;
|
| 102 |
}
|
| 103 |
.metric-card {
|
| 104 |
background-color: #ffffff;
|
|
|
|
| 106 |
border-radius: 0.5rem;
|
| 107 |
border: 1px solid #e0e0e0;
|
| 108 |
margin: 1rem 0;
|
| 109 |
+
color: #212529;
|
| 110 |
}
|
| 111 |
</style>
|
| 112 |
""", unsafe_allow_html=True)
|
|
|
|
| 150 |
st.markdown("### Summary")
|
| 151 |
st.info(result['summary'])
|
| 152 |
|
|
|
|
|
|
|
|
|
|
| 153 |
# Remove metadata fields for display
|
| 154 |
metrics = {k: v for k, v in result.items()
|
| 155 |
if k not in ['overall_pass', 'summary', 'citations', 'source_nodes_count', 'parse_error', 'raw_response']}
|
|
|
|
| 166 |
for citation in result['citations'][:5]: # Show top 5 citations
|
| 167 |
display_citation(citation)
|
| 168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
|
| 170 |
def display_metric_card(metric_name, metric_data):
|
| 171 |
"""Display a single metric card with citation."""
|
|
|
|
| 206 |
|
| 207 |
|
| 208 |
def display_citation(citation):
|
| 209 |
+
"""Display a modern expandable citation card using Streamlit."""
|
| 210 |
+
# Create expander with page, score, and preview in the header
|
| 211 |
+
header = f"π Page {citation['page']} β’ β {citation['score']:.0%} Match\n\n{citation['text_preview']}"
|
| 212 |
+
|
| 213 |
+
with st.expander(header, expanded=False):
|
| 214 |
+
# Show only full text when expanded (no duplicate preview)
|
| 215 |
+
if citation.get('is_truncated', False):
|
| 216 |
+
st.markdown(f"<div class='citation-full'>{citation['full_text']}</div>",
|
| 217 |
+
unsafe_allow_html=True)
|
| 218 |
+
else:
|
| 219 |
+
# If not truncated, preview and full text are the same, so show nothing extra
|
| 220 |
+
st.caption("(Full text shown above)")
|
| 221 |
|
| 222 |
|
| 223 |
def main():
|
document_processor.py
CHANGED
|
@@ -108,6 +108,8 @@ class InvestmentDocumentProcessor:
|
|
| 108 |
"page": page,
|
| 109 |
"score": node.score,
|
| 110 |
"text_preview": node.node.text[:200] + "..." if len(node.node.text) > 200 else node.node.text,
|
|
|
|
|
|
|
| 111 |
"file_name": node.node.metadata.get('file_name', 'Unknown')
|
| 112 |
}
|
| 113 |
citations.append(citation)
|
|
|
|
| 108 |
"page": page,
|
| 109 |
"score": node.score,
|
| 110 |
"text_preview": node.node.text[:200] + "..." if len(node.node.text) > 200 else node.node.text,
|
| 111 |
+
"full_text": node.node.text,
|
| 112 |
+
"is_truncated": len(node.node.text) > 200,
|
| 113 |
"file_name": node.node.metadata.get('file_name', 'Unknown')
|
| 114 |
}
|
| 115 |
citations.append(citation)
|