Spaces:
Running
Running
Improve image preprocessing and layout for better performance
Browse files- Simplified preprocessing preview to show only processed image instead of side-by-side comparison
- Added preprocessing metadata to show which filters were applied
- Reorganized layout with metadata at top right and document contents below
- Added new metadata container with improved styling
- Removed duplicate metadata display in left column
- app.py +52 -41
- ui/custom.css +9 -0
app.py
CHANGED
@@ -928,25 +928,30 @@ with main_tab1:
|
|
928 |
with left_col:
|
929 |
process_button = st.button("Process Document")
|
930 |
|
931 |
-
# Image preprocessing preview
|
932 |
if any(preprocessing_options.values()) and uploaded_file.type.startswith('image/'):
|
933 |
-
|
934 |
-
|
|
|
|
|
|
|
935 |
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
940 |
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
processed_bytes = preprocess_image(uploaded_file.getvalue(), preprocessing_options)
|
945 |
-
# Fixed width parameter to ensure compatibility
|
946 |
-
st.image(io.BytesIO(processed_bytes), width=300)
|
947 |
-
except Exception as e:
|
948 |
-
st.error(f"Error in preprocessing: {str(e)}")
|
949 |
-
st.info("Try using grayscale preprocessing for PNG images with transparency")
|
950 |
|
951 |
# Empty container for progress indicators - will be filled during processing
|
952 |
progress_placeholder = st.empty()
|
@@ -1111,8 +1116,37 @@ with main_tab1:
|
|
1111 |
# Standard processing without custom prompt
|
1112 |
result = process_file(uploaded_file, use_vision, preprocessing_options, progress_container=progress_placeholder)
|
1113 |
|
1114 |
-
#
|
1115 |
with right_col:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1116 |
st.subheader("Document Contents")
|
1117 |
# Start document content div with consistent styling class
|
1118 |
st.markdown('<div class="document-content">', unsafe_allow_html=True)
|
@@ -1528,33 +1562,10 @@ with main_tab1:
|
|
1528 |
# Close document content div
|
1529 |
st.markdown('</div>', unsafe_allow_html=True)
|
1530 |
|
1531 |
-
#
|
1532 |
with metadata_placeholder.container():
|
1533 |
-
st.subheader("Document Metadata")
|
1534 |
st.success("**Document processed successfully**")
|
1535 |
|
1536 |
-
# Display file info
|
1537 |
-
st.write(f"**File Name:** {result.get('file_name', uploaded_file.name)}")
|
1538 |
-
|
1539 |
-
# Display info if only limited pages were processed
|
1540 |
-
if 'limited_pages' in result:
|
1541 |
-
st.info(f"Processed {result['limited_pages']['processed']} of {result['limited_pages']['total']} pages")
|
1542 |
-
|
1543 |
-
# Display languages if available
|
1544 |
-
if 'languages' in result:
|
1545 |
-
languages = [lang for lang in result['languages'] if lang is not None]
|
1546 |
-
if languages:
|
1547 |
-
st.write(f"**Languages:** {', '.join(languages)}")
|
1548 |
-
|
1549 |
-
# Display topics if available
|
1550 |
-
if 'topics' in result and result['topics']:
|
1551 |
-
st.write(f"**Topics:** {', '.join(result['topics'])}")
|
1552 |
-
|
1553 |
-
# Processing time if available
|
1554 |
-
if 'processing_time' in result:
|
1555 |
-
proc_time = result['processing_time']
|
1556 |
-
st.write(f"**Processing Time:** {proc_time:.1f}s")
|
1557 |
-
|
1558 |
# Store the result in the previous results list
|
1559 |
# Add timestamp to result for history tracking
|
1560 |
result_copy = result.copy()
|
|
|
928 |
with left_col:
|
929 |
process_button = st.button("Process Document")
|
930 |
|
931 |
+
# Image preprocessing preview - automatically show only the preprocessed version
|
932 |
if any(preprocessing_options.values()) and uploaded_file.type.startswith('image/'):
|
933 |
+
st.markdown("**Preprocessed Preview**")
|
934 |
+
try:
|
935 |
+
processed_bytes = preprocess_image(uploaded_file.getvalue(), preprocessing_options)
|
936 |
+
# Fixed width parameter to ensure compatibility
|
937 |
+
st.image(io.BytesIO(processed_bytes), width=300)
|
938 |
|
939 |
+
# Show preprocessing metadata next to the image
|
940 |
+
meta_text = "Applied: "
|
941 |
+
if preprocessing_options.get("document_type", "standard") != "standard":
|
942 |
+
meta_text += f"Document type ({preprocessing_options['document_type']}), "
|
943 |
+
if preprocessing_options.get("grayscale", False):
|
944 |
+
meta_text += "Grayscale, "
|
945 |
+
if preprocessing_options.get("denoise", False):
|
946 |
+
meta_text += "Denoise, "
|
947 |
+
if preprocessing_options.get("contrast", 0) != 0:
|
948 |
+
meta_text += f"Contrast ({preprocessing_options['contrast']}), "
|
949 |
+
if preprocessing_options.get("rotation", 0) != 0:
|
950 |
+
meta_text += f"Rotation ({preprocessing_options['rotation']}°), "
|
951 |
|
952 |
+
# Remove trailing comma and space
|
953 |
+
meta_text = meta_text.rstrip(", ")
|
954 |
+
st.caption(meta_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
955 |
|
956 |
# Empty container for progress indicators - will be filled during processing
|
957 |
progress_placeholder = st.empty()
|
|
|
1116 |
# Standard processing without custom prompt
|
1117 |
result = process_file(uploaded_file, use_vision, preprocessing_options, progress_container=progress_placeholder)
|
1118 |
|
1119 |
+
# Document Metadata in the top right of the right column
|
1120 |
with right_col:
|
1121 |
+
metadata_container = st.container()
|
1122 |
+
with metadata_container:
|
1123 |
+
st.subheader("Document Metadata")
|
1124 |
+
# Create a subtle container for metadata
|
1125 |
+
st.markdown('<div class="metadata-container">', unsafe_allow_html=True)
|
1126 |
+
# Display file info
|
1127 |
+
st.write(f"**File Name:** {result.get('file_name', uploaded_file.name)}")
|
1128 |
+
|
1129 |
+
# Display info if only limited pages were processed
|
1130 |
+
if 'limited_pages' in result:
|
1131 |
+
st.info(f"Processed {result['limited_pages']['processed']} of {result['limited_pages']['total']} pages")
|
1132 |
+
|
1133 |
+
# Display languages if available
|
1134 |
+
if 'languages' in result:
|
1135 |
+
languages = [lang for lang in result['languages'] if lang is not None]
|
1136 |
+
if languages:
|
1137 |
+
st.write(f"**Languages:** {', '.join(languages)}")
|
1138 |
+
|
1139 |
+
# Display topics if available
|
1140 |
+
if 'topics' in result and result['topics']:
|
1141 |
+
st.write(f"**Topics:** {', '.join(result['topics'])}")
|
1142 |
+
|
1143 |
+
# Processing time if available
|
1144 |
+
if 'processing_time' in result:
|
1145 |
+
proc_time = result['processing_time']
|
1146 |
+
st.write(f"**Processing Time:** {proc_time:.1f}s")
|
1147 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
1148 |
+
|
1149 |
+
# Display Document Contents below the metadata in the right column
|
1150 |
st.subheader("Document Contents")
|
1151 |
# Start document content div with consistent styling class
|
1152 |
st.markdown('<div class="document-content">', unsafe_allow_html=True)
|
|
|
1562 |
# Close document content div
|
1563 |
st.markdown('</div>', unsafe_allow_html=True)
|
1564 |
|
1565 |
+
# Update the placeholder with a success message
|
1566 |
with metadata_placeholder.container():
|
|
|
1567 |
st.success("**Document processed successfully**")
|
1568 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1569 |
# Store the result in the previous results list
|
1570 |
# Add timestamp to result for history tracking
|
1571 |
result_copy = result.copy()
|
ui/custom.css
CHANGED
@@ -88,6 +88,15 @@
|
|
88 |
object-fit: contain !important;
|
89 |
}
|
90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
/* Additional image fixes for all containers */
|
92 |
.document-content img,
|
93 |
.markdown-text-container img,
|
|
|
88 |
object-fit: contain !important;
|
89 |
}
|
90 |
|
91 |
+
/* Metadata container styling */
|
92 |
+
.metadata-container {
|
93 |
+
background-color: #f8f9fa;
|
94 |
+
border-radius: 4px;
|
95 |
+
padding: 12px;
|
96 |
+
margin-bottom: 20px;
|
97 |
+
border-left: 3px solid #4285f4;
|
98 |
+
}
|
99 |
+
|
100 |
/* Additional image fixes for all containers */
|
101 |
.document-content img,
|
102 |
.markdown-text-container img,
|