milwright commited on
Commit
881d511
·
1 Parent(s): 0419853

Fix multiple UI issues: white container under Document Metadata, fullscreen buttons, and PDF preprocessing

Browse files
Files changed (3) hide show
  1. app.py +32 -27
  2. ui/__pycache__/layout.cpython-312.pyc +0 -0
  3. ui/custom.css +67 -4
app.py CHANGED
@@ -365,8 +365,10 @@ def process_file(uploaded_file, use_vision=True, preprocessing_options=None, pro
365
 
366
  # Generate a cache key based on file content, type and settings
367
  import hashlib
 
 
368
  file_hash = hashlib.md5(open(temp_path, 'rb').read()).hexdigest()
369
- cache_key = f"{file_hash}_{file_type}_{use_vision}"
370
 
371
  progress_bar.progress(50)
372
  status_text.markdown('<div class="processing-status-container">Processing document with OCR...</div>', unsafe_allow_html=True)
@@ -947,26 +949,28 @@ with main_tab1:
947
  st.markdown("**Preprocessed Preview**")
948
  try:
949
  processed_bytes = preprocess_image(uploaded_file.getvalue(), preprocessing_options)
950
- # Fixed width parameter to ensure compatibility
951
- st.image(io.BytesIO(processed_bytes), width=300)
952
-
953
- # Show preprocessing metadata next to the image
954
- meta_items = []
955
- if preprocessing_options.get("document_type", "standard") != "standard":
956
- meta_items.append(f"Document type ({preprocessing_options['document_type']})")
957
- if preprocessing_options.get("grayscale", False):
958
- meta_items.append("Grayscale")
959
- if preprocessing_options.get("denoise", False):
960
- meta_items.append("Denoise")
961
- if preprocessing_options.get("contrast", 0) != 0:
962
- meta_items.append(f"Contrast ({preprocessing_options['contrast']})")
963
- if preprocessing_options.get("rotation", 0) != 0:
964
- meta_items.append(f"Rotation ({preprocessing_options['rotation']}°)")
965
-
966
- # Only show "Applied:" if there are actual preprocessing steps
967
- if meta_items:
968
- meta_text = "Applied: " + ", ".join(meta_items)
969
- st.caption(meta_text)
 
 
970
  except Exception as e:
971
  st.error(f"Error in preprocessing: {str(e)}")
972
  st.info("Try using grayscale preprocessing for PNG images with transparency")
@@ -1018,12 +1022,16 @@ with main_tab1:
1018
  temp_path = tmp.name
1019
 
1020
  # Process with NO custom prompt first
 
 
 
1021
  base_result = processor.process_file(
1022
  file_path=temp_path,
1023
  file_type="pdf",
1024
  use_vision=use_vision,
1025
  custom_prompt=None, # No custom prompt in first step
1026
- file_size_mb=len(uploaded_file.getvalue()) / (1024 * 1024)
 
1027
  )
1028
 
1029
  progress_bar.progress(70)
@@ -1131,11 +1139,8 @@ with main_tab1:
1131
 
1132
  # Document Metadata in the top right of the right column
1133
  with right_col:
1134
- # Directly add the subheader without extra container
1135
- st.subheader("Document Metadata")
1136
-
1137
- # Create an inline container with compact styling
1138
- st.markdown('<div class="metadata-container" style="margin-top:0">', unsafe_allow_html=True)
1139
 
1140
  # Display file info
1141
  st.write(f"**File Name:** {result.get('file_name', uploaded_file.name)}")
 
365
 
366
  # Generate a cache key based on file content, type and settings
367
  import hashlib
368
+ # Add pdf_rotation to cache key if present
369
+ pdf_rotation_value = pdf_rotation if 'pdf_rotation' in locals() else 0
370
  file_hash = hashlib.md5(open(temp_path, 'rb').read()).hexdigest()
371
+ cache_key = f"{file_hash}_{file_type}_{use_vision}_{pdf_rotation_value}"
372
 
373
  progress_bar.progress(50)
374
  status_text.markdown('<div class="processing-status-container">Processing document with OCR...</div>', unsafe_allow_html=True)
 
949
  st.markdown("**Preprocessed Preview**")
950
  try:
951
  processed_bytes = preprocess_image(uploaded_file.getvalue(), preprocessing_options)
952
+ # Using a container for better layout control
953
+ with st.container():
954
+ # Fixed width parameter to ensure compatibility
955
+ st.image(io.BytesIO(processed_bytes), width=300, use_column_width=False)
956
+
957
+ # Show preprocessing metadata next to the image
958
+ meta_items = []
959
+ if preprocessing_options.get("document_type", "standard") != "standard":
960
+ meta_items.append(f"Document type ({preprocessing_options['document_type']})")
961
+ if preprocessing_options.get("grayscale", False):
962
+ meta_items.append("Grayscale")
963
+ if preprocessing_options.get("denoise", False):
964
+ meta_items.append("Denoise")
965
+ if preprocessing_options.get("contrast", 0) != 0:
966
+ meta_items.append(f"Contrast ({preprocessing_options['contrast']})")
967
+ if preprocessing_options.get("rotation", 0) != 0:
968
+ meta_items.append(f"Rotation ({preprocessing_options['rotation']}°)")
969
+
970
+ # Only show "Applied:" if there are actual preprocessing steps
971
+ if meta_items:
972
+ meta_text = "Applied: " + ", ".join(meta_items)
973
+ st.caption(meta_text)
974
  except Exception as e:
975
  st.error(f"Error in preprocessing: {str(e)}")
976
  st.info("Try using grayscale preprocessing for PNG images with transparency")
 
1022
  temp_path = tmp.name
1023
 
1024
  # Process with NO custom prompt first
1025
+ # Apply PDF rotation if specified
1026
+ pdf_rotation_value = pdf_rotation if 'pdf_rotation' in locals() else 0
1027
+
1028
  base_result = processor.process_file(
1029
  file_path=temp_path,
1030
  file_type="pdf",
1031
  use_vision=use_vision,
1032
  custom_prompt=None, # No custom prompt in first step
1033
+ file_size_mb=len(uploaded_file.getvalue()) / (1024 * 1024),
1034
+ pdf_rotation=pdf_rotation_value # Pass rotation value to processor
1035
  )
1036
 
1037
  progress_bar.progress(70)
 
1139
 
1140
  # Document Metadata in the top right of the right column
1141
  with right_col:
1142
+ # Directly add the subheader and container without nesting - fix white container
1143
+ st.markdown('<h3 style="margin-bottom:0; padding-bottom:0;">Document Metadata</h3><div class="metadata-container" style="margin-top:0;">', unsafe_allow_html=True)
 
 
 
1144
 
1145
  # Display file info
1146
  st.write(f"**File Name:** {result.get('file_name', uploaded_file.name)}")
ui/__pycache__/layout.cpython-312.pyc CHANGED
Binary files a/ui/__pycache__/layout.cpython-312.pyc and b/ui/__pycache__/layout.cpython-312.pyc differ
 
ui/custom.css CHANGED
@@ -98,6 +98,11 @@
98
  border-left: 3px solid #4285f4;
99
  }
100
 
 
 
 
 
 
101
  /* Fix spacing for headings above metadata container */
102
  .element-container h3 + div .metadata-container,
103
  .element-container h1 + div .metadata-container,
@@ -106,18 +111,74 @@
106
  }
107
 
108
  /* Remove excess space between metadata heading and content */
109
- .stMarkdown + div div.element-container {
 
 
 
110
  margin-top: 0 !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  }
112
 
113
  /* Fix fullscreen button styling */
114
  button[title="View fullscreen"],
115
  button.streamlit-expanderHeader {
116
- z-index: 10 !important;
117
  background-color: rgba(255, 255, 255, 0.8) !important;
118
  visibility: visible !important;
119
  opacity: 1 !important;
120
  display: flex !important;
 
 
 
 
 
 
 
 
 
 
121
  }
122
 
123
  /* Make text visible in Previous Results tab */
@@ -133,7 +194,8 @@ button.streamlit-expanderHeader {
133
  .document-content img,
134
  .markdown-text-container img,
135
  .page-text-content img,
136
- .image-container img {
 
137
  max-width: 100% !important;
138
  height: auto !important;
139
  object-fit: contain !important;
@@ -145,7 +207,8 @@ button.streamlit-expanderHeader {
145
  .document-content img,
146
  .markdown-text-container img,
147
  .page-text-content img,
148
- .image-container img {
 
149
  max-width: 95% !important;
150
  }
151
  }
 
98
  border-left: 3px solid #4285f4;
99
  }
100
 
101
+ /* Direct child styling to prevent nested containers */
102
+ .element-container > .metadata-container {
103
+ margin-top: 0 !important;
104
+ }
105
+
106
  /* Fix spacing for headings above metadata container */
107
  .element-container h3 + div .metadata-container,
108
  .element-container h1 + div .metadata-container,
 
111
  }
112
 
113
  /* Remove excess space between metadata heading and content */
114
+ .stMarkdown + div div.element-container,
115
+ .stMarkdown + div,
116
+ .stHeading + div,
117
+ .stHeading + div div.element-container {
118
  margin-top: 0 !important;
119
+ padding-top: 0 !important;
120
+ }
121
+
122
+ /* PDF container fixes */
123
+ .stExpander .streamlit-expanderContent {
124
+ max-width: 100% !important;
125
+ overflow: visible !important;
126
+ }
127
+
128
+ /* Fix placement of fullscreen buttons, especially in expanders */
129
+ .element-container .stImage .stExpander button[title="View fullscreen"] {
130
+ position: absolute !important;
131
+ top: 5px !important;
132
+ right: 5px !important;
133
+ }
134
+
135
+ /* Fix PDF preview container */
136
+ .stPdfViewerContent,
137
+ .stPdfViewer,
138
+ .stPdfViewerPagesContainer {
139
+ width: 100% !important;
140
+ max-width: 100% !important;
141
+ overflow: visible !important;
142
+ }
143
+
144
+ /* Fix for expandable content */
145
+ .stExpander > div[data-testid="stExpander"] {
146
+ max-width: 100% !important;
147
+ overflow: visible !important;
148
+ }
149
+
150
+ /* Fix for fullscreen and expander buttons in image containers */
151
+ .stImage button[title="View fullscreen"] {
152
+ position: absolute !important;
153
+ top: 5px !important;
154
+ right: 5px !important;
155
+ z-index: 1000 !important;
156
+ visibility: visible !important;
157
+ opacity: 1 !important;
158
+ display: flex !important;
159
+ align-items: center !important;
160
+ justify-content: center !important;
161
+ background-color: rgba(255, 255, 255, 0.8) !important;
162
  }
163
 
164
  /* Fix fullscreen button styling */
165
  button[title="View fullscreen"],
166
  button.streamlit-expanderHeader {
167
+ z-index: 999 !important;
168
  background-color: rgba(255, 255, 255, 0.8) !important;
169
  visibility: visible !important;
170
  opacity: 1 !important;
171
  display: flex !important;
172
+ align-items: center !important;
173
+ justify-content: center !important;
174
+ width: 32px !important;
175
+ height: 32px !important;
176
+ border-radius: 4px !important;
177
+ position: absolute !important;
178
+ top: 5px !important;
179
+ right: 5px !important;
180
+ border: 1px solid rgba(0, 0, 0, 0.1) !important;
181
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1) !important;
182
  }
183
 
184
  /* Make text visible in Previous Results tab */
 
194
  .document-content img,
195
  .markdown-text-container img,
196
  .page-text-content img,
197
+ .image-container img,
198
+ .streamlit-expanderContent img {
199
  max-width: 100% !important;
200
  height: auto !important;
201
  object-fit: contain !important;
 
207
  .document-content img,
208
  .markdown-text-container img,
209
  .page-text-content img,
210
+ .image-container img,
211
+ .streamlit-expanderContent img {
212
  max-width: 95% !important;
213
  }
214
  }