Spaces:
Running
Running
Update UI components based on feedback: remove performance mode, make preprocessing sections collapsible, reduce title size, decenter Mistral AI credit
Browse files- ui_components.py +50 -62
ui_components.py
CHANGED
@@ -72,11 +72,6 @@ def create_sidebar_options():
|
|
72 |
st.subheader("Model Selection")
|
73 |
use_vision = st.toggle("Use Vision Model", value=True, help="Use vision model for better understanding of document structure")
|
74 |
|
75 |
-
# Performance mode
|
76 |
-
perf_mode = st.radio("Performance Mode", PERFORMANCE_MODES,
|
77 |
-
horizontal=True,
|
78 |
-
help="Quality: Best results but slower. Speed: Faster but may be less accurate.")
|
79 |
-
|
80 |
# Document type selection
|
81 |
st.subheader("Document Type")
|
82 |
doc_type = st.selectbox("Document Type", DOCUMENT_TYPES,
|
@@ -107,74 +102,67 @@ def create_sidebar_options():
|
|
107 |
help="Customize the instructions for processing this document",
|
108 |
height=100)
|
109 |
|
110 |
-
# Image preprocessing options
|
111 |
-
st.
|
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 |
-
# Rotation
|
138 |
-
rotation = st.slider("Rotation",
|
139 |
-
min_value=-45,
|
140 |
-
max_value=45,
|
141 |
-
value=0,
|
142 |
-
step=5,
|
143 |
-
help="Rotate image if needed")
|
144 |
|
145 |
# Create preprocessing options dictionary
|
146 |
preprocessing_options = {
|
147 |
-
"document_type":
|
148 |
"grayscale": grayscale,
|
149 |
"denoise": denoise,
|
150 |
"contrast": contrast,
|
151 |
"rotation": rotation
|
152 |
}
|
153 |
|
154 |
-
# PDF-specific options
|
155 |
-
st.
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
|
174 |
# Create options dictionary
|
175 |
options = {
|
176 |
"use_vision": use_vision,
|
177 |
-
"perf_mode":
|
178 |
"pdf_dpi": pdf_dpi,
|
179 |
"max_pages": max_pages,
|
180 |
"pdf_rotation": pdf_rotation,
|
@@ -189,8 +177,8 @@ def create_file_uploader():
|
|
189 |
# Add app description
|
190 |
favicon_path = os.path.join(os.path.dirname(__file__), "static/favicon.png")
|
191 |
favicon_base64 = get_base64_from_image(favicon_path)
|
192 |
-
st.markdown(f'<div style="display: flex; align-items: center; gap: 10px;"><img src="data:image/png;base64,{favicon_base64}" width="36" height="36" alt="Scroll Icon"/> <div><
|
193 |
-
st.
|
194 |
|
195 |
# Add project framing
|
196 |
st.markdown("""
|
|
|
72 |
st.subheader("Model Selection")
|
73 |
use_vision = st.toggle("Use Vision Model", value=True, help="Use vision model for better understanding of document structure")
|
74 |
|
|
|
|
|
|
|
|
|
|
|
75 |
# Document type selection
|
76 |
st.subheader("Document Type")
|
77 |
doc_type = st.selectbox("Document Type", DOCUMENT_TYPES,
|
|
|
102 |
help="Customize the instructions for processing this document",
|
103 |
height=100)
|
104 |
|
105 |
+
# Image preprocessing options in an expandable section
|
106 |
+
with st.expander("Image Preprocessing"):
|
107 |
+
# Grayscale conversion
|
108 |
+
grayscale = st.checkbox("Convert to Grayscale",
|
109 |
+
value=False,
|
110 |
+
help="Convert color images to grayscale for better OCR")
|
111 |
+
|
112 |
+
# Denoise
|
113 |
+
denoise = st.checkbox("Denoise Image",
|
114 |
+
value=False,
|
115 |
+
help="Remove noise from the image")
|
116 |
+
|
117 |
+
# Contrast adjustment
|
118 |
+
contrast = st.slider("Contrast Adjustment",
|
119 |
+
min_value=-50,
|
120 |
+
max_value=50,
|
121 |
+
value=0,
|
122 |
+
step=10,
|
123 |
+
help="Adjust image contrast")
|
124 |
+
|
125 |
+
# Rotation
|
126 |
+
rotation = st.slider("Rotation",
|
127 |
+
min_value=-45,
|
128 |
+
max_value=45,
|
129 |
+
value=0,
|
130 |
+
step=5,
|
131 |
+
help="Rotate image if needed")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
|
133 |
# Create preprocessing options dictionary
|
134 |
preprocessing_options = {
|
135 |
+
"document_type": "standard", # Use standard as default, removed duplicate option
|
136 |
"grayscale": grayscale,
|
137 |
"denoise": denoise,
|
138 |
"contrast": contrast,
|
139 |
"rotation": rotation
|
140 |
}
|
141 |
|
142 |
+
# PDF-specific options in an expandable section
|
143 |
+
with st.expander("PDF Options"):
|
144 |
+
pdf_dpi = st.slider("PDF Resolution (DPI)",
|
145 |
+
min_value=MIN_PDF_DPI,
|
146 |
+
max_value=MAX_PDF_DPI,
|
147 |
+
value=DEFAULT_PDF_DPI,
|
148 |
+
step=25,
|
149 |
+
help="Higher DPI gives better quality but slower processing")
|
150 |
+
|
151 |
+
max_pages = st.number_input("Maximum Pages to Process",
|
152 |
+
min_value=1,
|
153 |
+
max_value=20,
|
154 |
+
value=DEFAULT_MAX_PAGES,
|
155 |
+
help="Limit the number of pages to process (for multi-page PDFs)")
|
156 |
+
|
157 |
+
pdf_rotation = st.radio("PDF Rotation", ROTATION_OPTIONS,
|
158 |
+
horizontal=True,
|
159 |
+
format_func=lambda x: f"{x}°",
|
160 |
+
help="Rotate PDF pages if needed")
|
161 |
|
162 |
# Create options dictionary
|
163 |
options = {
|
164 |
"use_vision": use_vision,
|
165 |
+
"perf_mode": "Quality", # Default to Quality, removed performance mode option
|
166 |
"pdf_dpi": pdf_dpi,
|
167 |
"max_pages": max_pages,
|
168 |
"pdf_rotation": pdf_rotation,
|
|
|
177 |
# Add app description
|
178 |
favicon_path = os.path.join(os.path.dirname(__file__), "static/favicon.png")
|
179 |
favicon_base64 = get_base64_from_image(favicon_path)
|
180 |
+
st.markdown(f'<div style="display: flex; align-items: center; gap: 10px;"><img src="data:image/png;base64,{favicon_base64}" width="36" height="36" alt="Scroll Icon"/> <div><h2 style="margin: 0; padding: 10px 0 0 0;">Historical Document OCR</h2></div></div>', unsafe_allow_html=True)
|
181 |
+
st.markdown("<p style='font-size: 0.8em; color: #666; text-align: right;'>Made possible by Mistral AI</p>", unsafe_allow_html=True)
|
182 |
|
183 |
# Add project framing
|
184 |
st.markdown("""
|