-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_image_viewer_web.py
More file actions
200 lines (160 loc) Β· 5.92 KB
/
Copy patherror_image_viewer_web.py
File metadata and controls
200 lines (160 loc) Β· 5.92 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/usr/bin/env python3
"""
Error Image Viewer - Web-based version using Streamlit
Features:
- Display marked screenshots from error_imgs folders
- Show judgment_response.txt and aggregation_response.txt content
- Navigate between entries with prev/next buttons
- Jump to specific entry by number
- Zoom functionality using browser's built-in zoom
- Works in any browser - perfect for remote servers
"""
import streamlit as st
import os
from pathlib import Path
from PIL import Image
import base64
from io import BytesIO
def load_error_folders():
"""Load all error folders from the error_imgs directory"""
error_imgs_path = Path("error_imgs")
if not error_imgs_path.exists():
st.error(f"error_imgs directory not found at {error_imgs_path.absolute()}")
return []
# Get all subdirectories and sort them by name (which includes timestamp)
error_folders = sorted([
d for d in error_imgs_path.iterdir()
if d.is_dir() and (d / "marked_screenshot.png").exists()
])
return error_folders
def load_text_file(file_path):
"""Load text file content"""
try:
if file_path.exists():
with open(file_path, 'r', encoding='utf-8') as f:
return f.read()
else:
return f"No {file_path.name} found"
except Exception as e:
return f"Error reading {file_path.name}:\n{str(e)}"
def get_image_base64(image_path):
"""Convert image to base64 for HTML display"""
try:
with open(image_path, "rb") as img_file:
return base64.b64encode(img_file.read()).decode()
except Exception as e:
st.error(f"Error loading image: {e}")
return None
def main():
st.set_page_config(
page_title="Error Image Viewer",
page_icon="π",
layout="wide",
initial_sidebar_state="expanded"
)
st.title("π Error Image Viewer")
st.markdown("Interactive viewer for RegionFocus error images and responses")
# Load error folders
error_folders = load_error_folders()
if not error_folders:
st.error("No error folders found!")
return
# Sidebar navigation
st.sidebar.title("Navigation")
st.sidebar.write(f"Total entries: **{len(error_folders)}**")
# Initialize session state
if 'current_index' not in st.session_state:
st.session_state.current_index = 0
# Navigation controls
col1, col2, col3 = st.sidebar.columns([1, 1, 1])
with col1:
if st.button("β Prev", disabled=st.session_state.current_index == 0):
st.session_state.current_index -= 1
st.rerun()
with col2:
current_display = st.session_state.current_index + 1
st.write(f"**{current_display} / {len(error_folders)}**")
with col3:
if st.button("Next βΆ", disabled=st.session_state.current_index >= len(error_folders) - 1):
st.session_state.current_index += 1
st.rerun()
# Jump to entry
st.sidebar.markdown("---")
jump_to = st.sidebar.number_input(
"Jump to entry:",
min_value=1,
max_value=len(error_folders),
value=current_display,
step=1
)
if st.sidebar.button("Go to Entry"):
st.session_state.current_index = jump_to - 1
st.rerun()
# Get current folder
current_folder = error_folders[st.session_state.current_index]
# Display folder name
st.header(f"π {current_folder.name}")
# Main content area
col1, col2 = st.columns([2, 1])
with col1:
st.subheader("πΌοΈ Screenshot")
# Load and display image
image_path = current_folder / "marked_screenshot.png"
if image_path.exists():
try:
# Load image
image = Image.open(image_path)
# Display image with zoom controls
st.image(
image,
caption=f"Marked screenshot from {current_folder.name}",
use_column_width=True
)
# Add zoom instructions
st.info("π‘ **Tip**: Use your browser's zoom (Ctrl/Cmd + scroll) to zoom into the image!")
# Image info
st.caption(f"Image size: {image.width} x {image.height} pixels")
except Exception as e:
st.error(f"Error loading image: {e}")
else:
st.error("marked_screenshot.png not found!")
with col2:
# Judgment response
st.subheader("π Judgment Response")
judgment_path = current_folder / "judgment_response.txt"
judgment_content = load_text_file(judgment_path)
st.text_area(
"judgment_response.txt",
value=judgment_content,
height=300,
label_visibility="collapsed"
)
# Aggregation response
st.subheader("π Aggregation Response")
aggregation_path = current_folder / "aggregation_response.txt"
aggregation_content = load_text_file(aggregation_path)
st.text_area(
"aggregation_response.txt",
value=aggregation_content,
height=300,
label_visibility="collapsed"
)
# Keyboard shortcuts info
st.sidebar.markdown("---")
st.sidebar.markdown("""
### β¨οΈ Keyboard Shortcuts
- **R**: Refresh page
- **Ctrl/Cmd + Plus**: Zoom in
- **Ctrl/Cmd + Minus**: Zoom out
- **Ctrl/Cmd + 0**: Reset zoom
""")
# Additional info
st.sidebar.markdown("---")
st.sidebar.markdown(f"""
### βΉοΈ Current Entry Info
- **Folder**: `{current_folder.name}`
- **Has Judgment**: β
Yes
- **Has Aggregation**: {'β
Yes' if (current_folder / 'aggregation_response.txt').exists() else 'β No'}
""")
if __name__ == "__main__":
main()