-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathui_components.py
More file actions
157 lines (120 loc) · 4.88 KB
/
ui_components.py
File metadata and controls
157 lines (120 loc) · 4.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
"""
UI components for the Advanced RAG application
"""
import streamlit as st
from config import (
PAGE_TITLE, PAGE_ICON, LAYOUT, SIDEBAR_STATE,
FILE_CATEGORIES, UPLOAD_PLACEHOLDER_TITLE, UPLOAD_PLACEHOLDER_TEXT
)
from utils import format_file_size
def setup_page_config():
"""Sets up Streamlit page settings"""
st.set_page_config(
page_title=PAGE_TITLE,
page_icon=PAGE_ICON,
layout=LAYOUT,
initial_sidebar_state=SIDEBAR_STATE
)
def render_header():
"""Shows the main header section"""
st.title(f"{PAGE_ICON} Advanced RAG System")
st.subheader("Intelligent Document Search & Analysis")
# Feature highlights
col1, col2, col3 = st.columns(3)
with col1:
st.info("🔍 **Smart Search**\n\nAdvanced retrieval with fallback to online sources")
with col2:
st.info("📄 **Multi-Format**\n\nPDF, Word, Excel, Code files supported")
with col3:
st.info("🤖 **LLM-Powered**\n\nLangGraph workflow with hallucination detection")
st.divider()
def render_sidebar(document_loader):
"""Shows the sidebar with app info and file types"""
with st.sidebar:
# App info
st.markdown("""
<div style="background: white; padding: 1rem; border-radius: 8px; margin-bottom: 1rem;">
<h4>🔍 Advanced RAG System</h4>
<p>Upload documents and ask intelligent questions using LLM-powered retrieval.</p>
</div>
""", unsafe_allow_html=True)
st.markdown("### 📋 Supported File Types")
# Organized file type display
for category, formats in FILE_CATEGORIES.items():
with st.expander(category, expanded=False):
for fmt in formats:
st.markdown(f"• {fmt}")
def render_upload_section(document_loader):
"""Shows the document upload section"""
st.markdown("## 📤 Document Upload")
# Upload area with simple styling
st.info("📁 **Drag & Drop Your Document**\n\nSupported: PDF, Word, Excel, Text, Code files")
# Show current supported extensions
with st.expander("ℹ️ View All Supported Formats", expanded=False):
col1, col2 = st.columns(2)
with col1:
st.write(f"**Supported extensions:** {document_loader.get_supported_extensions_display()}")
with col2:
st.write(f"**Total formats:** {len(document_loader.get_supported_extensions())}")
# File uploader
user_file = st.file_uploader(
"Choose a file",
type=document_loader.get_supported_extensions(),
help="Upload any supported document type.",
label_visibility="collapsed"
)
return user_file
def render_file_analysis(file_info):
"""Shows file analysis metrics"""
st.markdown("### 📊 File Analysis")
col1, col2, col3, col4 = st.columns(4)
with col1:
st.markdown("**📄 Filename**")
st.write(file_info['filename'])
with col2:
st.markdown("**📏 Size**")
size_display = format_file_size(file_info['size'])
st.write(size_display)
with col3:
st.markdown("**🏷️ Type**")
st.write(f".{file_info['extension'].upper()}")
with col4:
st.markdown("**📋 Status**")
status_icon = "✅" if file_info['is_supported'] else "❌"
status_text = "Supported" if file_info['is_supported'] else "Unsupported"
st.write(f"{status_icon} {status_text}")
def render_upload_placeholder():
"""Shows placeholder when no file is uploaded"""
st.markdown(f"""
<div style="text-align: center; padding: 3rem; background: #f8fafc; border-radius: 10px; margin: 2rem 0;">
<h3>{UPLOAD_PLACEHOLDER_TITLE}</h3>
<p>{UPLOAD_PLACEHOLDER_TEXT}</p>
</div>
""", unsafe_allow_html=True)
def render_question_section(user_file):
"""Shows the question input section"""
st.markdown("---")
st.markdown("### 💬 Ask Questions About Your Document")
# Display current file info
file_display = f"📄 **Current Document:** {user_file.name}"
if hasattr(user_file, 'type') and user_file.type:
file_display += f" ({user_file.type})"
st.markdown(file_display)
# Question input
col1, col2 = st.columns([4, 1])
with col1:
question = st.text_input(
'Enter your question:',
placeholder="What is the main topic of this document?",
disabled=not user_file,
help="Ask any question about the content of your uploaded document"
)
with col2:
st.markdown("<br>", unsafe_allow_html=True) # Add spacing
ask_button = st.button("Ask", use_container_width=True)
return question, ask_button
def render_answer_section(result):
"""Shows the answer section"""
st.markdown("### 📝 Answer")
st.success(result['solution'])
st.markdown("---")