xhluca commited on
Commit
1fe6197
1 Parent(s): eeae578

Refactor app

Browse files
Files changed (1) hide show
  1. app.py +20 -86
app.py CHANGED
@@ -45,7 +45,8 @@ def show_selectbox(demonstration_dir):
45
 
46
 
47
  def show_overview(data, recording_name, basedir):
48
- st.title(f"Recording {recording_name}")
 
49
 
50
  screenshot_size = st.session_state.get("screenshot_size_view_mode", "regular")
51
  show_advanced_info = st.session_state.get("show_advanced_information", False)
@@ -111,78 +112,17 @@ def show_overview(data, recording_name, basedir):
111
  col_act.markdown(action_str)
112
 
113
  if show_advanced_info:
114
- colors = {
115
- "good": "green",
116
- "broken": "red",
117
- "delayed": "orange"
118
- }
119
  status = d["state"].get("screenshot_status", "unknown")
120
- color = colors.get(status, "blue")
121
 
122
  text = ""
123
- text += f'Status: **:{color}[{status.upper()}]**\n\n'
 
124
  text += f'Screenshot: `{d["state"]["screenshot"]}`\\\n'
125
  text += f'Page: `{d["state"]["page"]}`\n'
126
 
127
  col_act.markdown(text)
128
 
129
 
130
- def show_slide(data, example_index, recording_name, basedir):
131
- columns = st.columns([1, 5], gap="large")
132
-
133
- chat = gather_chat_history(data, example_index)
134
- example = data[example_index]
135
-
136
- # display current message
137
- if example["type"] == "chat":
138
- columns[0].markdown(format_chat_message(example), unsafe_allow_html=True)
139
-
140
- # display chat history
141
- with columns[0]:
142
- for d in chat:
143
- columns[0].markdown(format_chat_message(d), unsafe_allow_html=True)
144
-
145
- img = find_screenshot(data, example_index, basedir)
146
-
147
- if example["type"] == "browser":
148
- event_type = example["action"]["intent"]
149
- arguments = parse_arguments(example["action"])
150
- event_type = example["action"]["intent"]
151
-
152
- action = f"**{event_type}**({arguments})"
153
-
154
- with columns[1]:
155
- st.write(action)
156
-
157
- with columns[1]:
158
- st.image(img)
159
-
160
-
161
- def show_presentation(data, recording_name, basedir):
162
- example_index = st.slider(
163
- "example",
164
- min_value=0,
165
- max_value=len(data) - 1,
166
- step=1,
167
- label_visibility="hidden",
168
- )
169
-
170
- show_slide(data, example_index, recording_name=recording_name, basedir=basedir)
171
-
172
-
173
- def show_video(basedir):
174
- # find the mp4 file in the basedir
175
- video_filename = None
176
- for filename in os.listdir(f"{basedir}"):
177
- if filename.endswith(".mp4"):
178
- video_filename = filename
179
- video_path = f"{basedir}/{video_filename}"
180
- st.video(video_path)
181
-
182
- if not video_filename:
183
- st.error("No video found")
184
-
185
-
186
  def load_recording(basedir):
187
  # Before loading replay, we need a dropdown that allows us to select replay.json or replay_orig.json
188
  # Find all files in basedir starting with "replay" and ending with ".json"
@@ -198,15 +138,12 @@ def load_recording(basedir):
198
  "Advanced Screenshot Info", False, key="show_advanced_information"
199
  )
200
  st.sidebar.checkbox(
201
- "Enable HTML download", True, key="enable_html_download"
202
  )
203
  replay_file = replay_file.replace(".json", "")
204
 
205
  metadata = load_json(basedir, "metadata")
206
 
207
- extension_version = metadata["version"]
208
- st.sidebar.markdown(f"**extension version**: {extension_version}")
209
-
210
  # convert timestamp to readable date string
211
  recording_start_timestamp = metadata["recordingStart"]
212
  recording_start_date = datetime.fromtimestamp(
@@ -239,10 +176,13 @@ def load_recording(basedir):
239
  "uses_ai_generated_output",
240
  ]:
241
  if form and key in form:
 
 
 
242
  if type(form[key]) == list:
243
- st.sidebar.markdown(f"**{key}**: {', '.join(form[key])}")
244
  else:
245
- st.sidebar.markdown(f"**{key}**: {form[key]}")
246
 
247
  st.sidebar.markdown("---")
248
  if replay_dict and "status" in replay_dict:
@@ -266,7 +206,7 @@ def load_recording(basedir):
266
 
267
 
268
  def run():
269
- mode = st.sidebar.radio("Mode", ["Overview"])
270
  demonstration_dir = "./demonstrations"
271
 
272
  # params = st.experimental_get_query_params()
@@ -296,15 +236,14 @@ def run():
296
  # use st.query_params as a dict instead
297
  st.query_params['recording'] = recording_name
298
 
299
- if mode == "Overview":
300
- with st.sidebar:
301
- # Want a dropdown
302
- st.selectbox(
303
- "Screenshot size",
304
- ["small", "regular", "large"],
305
- index=1,
306
- key="screenshot_size_view_mode",
307
- )
308
 
309
  if recording_name is not None:
310
  basedir = f"{demonstration_dir}/{recording_name}"
@@ -313,12 +252,7 @@ def run():
313
  if not data:
314
  st.stop()
315
 
316
- if mode == "Overview":
317
- show_overview(data, recording_name=recording_name, basedir=basedir)
318
- elif mode == "Presentation":
319
- show_presentation(data, recording_name=recording_name, basedir=basedir)
320
- elif mode == "Video":
321
- show_video(basedir=basedir)
322
 
323
 
324
  if __name__ == "__main__":
 
45
 
46
 
47
  def show_overview(data, recording_name, basedir):
48
+ st.title('[WebLINX](https://mcgill-nlp.github.io/weblinx) Explorer')
49
+ st.header(f"Recording: `{recording_name}`")
50
 
51
  screenshot_size = st.session_state.get("screenshot_size_view_mode", "regular")
52
  show_advanced_info = st.session_state.get("show_advanced_information", False)
 
112
  col_act.markdown(action_str)
113
 
114
  if show_advanced_info:
 
 
 
 
 
115
  status = d["state"].get("screenshot_status", "unknown")
 
116
 
117
  text = ""
118
+ if status == "good":
119
+ text += f'**:green[Used in demo]**\n\n'
120
  text += f'Screenshot: `{d["state"]["screenshot"]}`\\\n'
121
  text += f'Page: `{d["state"]["page"]}`\n'
122
 
123
  col_act.markdown(text)
124
 
125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  def load_recording(basedir):
127
  # Before loading replay, we need a dropdown that allows us to select replay.json or replay_orig.json
128
  # Find all files in basedir starting with "replay" and ending with ".json"
 
138
  "Advanced Screenshot Info", False, key="show_advanced_information"
139
  )
140
  st.sidebar.checkbox(
141
+ "Enable HTML download", False, key="enable_html_download"
142
  )
143
  replay_file = replay_file.replace(".json", "")
144
 
145
  metadata = load_json(basedir, "metadata")
146
 
 
 
 
147
  # convert timestamp to readable date string
148
  recording_start_timestamp = metadata["recordingStart"]
149
  recording_start_date = datetime.fromtimestamp(
 
176
  "uses_ai_generated_output",
177
  ]:
178
  if form and key in form:
179
+ # Normalize the key to be more human-readable
180
+ key_name = key.replace("_", " ").title()
181
+
182
  if type(form[key]) == list:
183
+ st.sidebar.markdown(f"**{key_name}**: {', '.join(form[key])}")
184
  else:
185
+ st.sidebar.markdown(f"**{key_name}**: {form[key]}")
186
 
187
  st.sidebar.markdown("---")
188
  if replay_dict and "status" in replay_dict:
 
206
 
207
 
208
  def run():
209
+ # mode = st.sidebar.radio("Mode", ["Overview"])
210
  demonstration_dir = "./demonstrations"
211
 
212
  # params = st.experimental_get_query_params()
 
236
  # use st.query_params as a dict instead
237
  st.query_params['recording'] = recording_name
238
 
239
+ with st.sidebar:
240
+ # Want a dropdown
241
+ st.selectbox(
242
+ "Screenshot size",
243
+ ["small", "regular", "large"],
244
+ index=1,
245
+ key="screenshot_size_view_mode",
246
+ )
 
247
 
248
  if recording_name is not None:
249
  basedir = f"{demonstration_dir}/{recording_name}"
 
252
  if not data:
253
  st.stop()
254
 
255
+ show_overview(data, recording_name=recording_name, basedir=basedir)
 
 
 
 
 
256
 
257
 
258
  if __name__ == "__main__":