gigant commited on
Commit
a011821
·
verified ·
1 Parent(s): b62ffcd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -18
app.py CHANGED
@@ -6,7 +6,6 @@ import io
6
  import base64
7
  from datasets import load_dataset
8
 
9
-
10
  max_token_budget = 512
11
 
12
  min_pixels = 1 * 28 * 28
@@ -77,7 +76,6 @@ def doc_to_messages(text, slides):
77
  text = processor.apply_chat_template(
78
  messages, tokenize=False, add_generation_prompt=True
79
  )
80
- print(text)
81
  image_inputs, video_inputs = process_vision_info(messages)
82
  inputs = processor(
83
  text=[text],
@@ -93,6 +91,8 @@ def doc_to_messages(text, slides):
93
  current_doc_index = 0
94
  annotations = []
95
 
 
 
96
  def load_document(index):
97
  """Load a specific document from the dataset"""
98
  if 0 <= index < len(ds):
@@ -103,19 +103,25 @@ def load_document(index):
103
  doc["abstract"],
104
  create_interleaved_html(segments_doc, doc["slides"], scale=0.7),
105
  doc_to_messages(segments_doc, doc["slides"]).input_ids.shape[1],
 
106
  )
107
- return ("", "", "", "")
108
 
109
  def get_next_document():
110
  """Get the next document in the dataset"""
111
  global current_doc_index
112
- current_doc_index = (current_doc_index + 1) % len(ds)
113
- return load_document(current_doc_index)
114
 
115
  def get_prev_document():
116
  """Get the previous document in the dataset"""
117
  global current_doc_index
118
- current_doc_index = (current_doc_index - 1) % len(ds)
 
 
 
 
 
 
119
  return load_document(current_doc_index)
120
 
121
 
@@ -123,36 +129,34 @@ theme = gr.themes.Ocean()
123
 
124
  with gr.Blocks(theme=theme) as demo:
125
  gr.Markdown("# Slide Presentation Visualization Tool")
 
126
  with gr.Row():
127
  with gr.Column():
128
  body = gr.HTML(max_height=400)
129
 
130
- # Function to update the interleaved view
131
- def update_interleaved_view(title, abstract, body, token_count):
132
- return body
133
-
134
  with gr.Column():
135
  title = gr.Textbox(label="Title", interactive=False, max_lines=1)
136
  abstract = gr.Textbox(label="Abstract", interactive=False, max_lines=8)
137
  token_count = gr.Textbox(label=f"Token Count (Qwen2-VL with under {max_token_budget} tokens per image)", interactive=False, max_lines=1)
138
 
139
- title.change(
140
- fn=update_interleaved_view,
141
- inputs=[title, abstract, body, token_count],
142
- outputs=body,
143
- )
144
  # Load first document
145
- title_val, abstract_val, body_val, token_count_val = load_document(current_doc_index)
146
  title.value = title_val
147
  abstract.value = abstract_val
148
  body.value = body_val
149
  token_count.value = str(token_count_val)
 
150
 
 
 
 
 
 
151
 
152
  with gr.Row():
153
  prev_button = gr.Button("Previous Document")
154
- prev_button.click(fn=get_prev_document, inputs=[], outputs=[title, abstract, body, token_count])
155
  next_button = gr.Button("Next Document")
156
- next_button.click(fn=get_next_document, inputs=[], outputs=[title, abstract, body, token_count])
157
 
158
  demo.launch()
 
6
  import base64
7
  from datasets import load_dataset
8
 
 
9
  max_token_budget = 512
10
 
11
  min_pixels = 1 * 28 * 28
 
76
  text = processor.apply_chat_template(
77
  messages, tokenize=False, add_generation_prompt=True
78
  )
 
79
  image_inputs, video_inputs = process_vision_info(messages)
80
  inputs = processor(
81
  text=[text],
 
91
  current_doc_index = 0
92
  annotations = []
93
 
94
+ choices = [f"{i} | {ds['title'][i]}" for i in range(len(ds))]
95
+
96
  def load_document(index):
97
  """Load a specific document from the dataset"""
98
  if 0 <= index < len(ds):
 
103
  doc["abstract"],
104
  create_interleaved_html(segments_doc, doc["slides"], scale=0.7),
105
  doc_to_messages(segments_doc, doc["slides"]).input_ids.shape[1],
106
+ choices[index],
107
  )
108
+ return ("", "", "", "", "")
109
 
110
  def get_next_document():
111
  """Get the next document in the dataset"""
112
  global current_doc_index
113
+ return choices[(current_doc_index + 1) % len(ds)]
 
114
 
115
  def get_prev_document():
116
  """Get the previous document in the dataset"""
117
  global current_doc_index
118
+ return choices[(current_doc_index - 1) % len(ds)]
119
+
120
+ def get_selected_document(arg):
121
+ """Get the selected document from the dataset"""
122
+ global current_doc_index
123
+ index = int(arg.split(" | ")[0])
124
+ current_doc_index = index
125
  return load_document(current_doc_index)
126
 
127
 
 
129
 
130
  with gr.Blocks(theme=theme) as demo:
131
  gr.Markdown("# Slide Presentation Visualization Tool")
132
+ pres_selection_dd = gr.Dropdown(label="Presentation", value=choices[0], choices=choices)
133
  with gr.Row():
134
  with gr.Column():
135
  body = gr.HTML(max_height=400)
136
 
 
 
 
 
137
  with gr.Column():
138
  title = gr.Textbox(label="Title", interactive=False, max_lines=1)
139
  abstract = gr.Textbox(label="Abstract", interactive=False, max_lines=8)
140
  token_count = gr.Textbox(label=f"Token Count (Qwen2-VL with under {max_token_budget} tokens per image)", interactive=False, max_lines=1)
141
 
 
 
 
 
 
142
  # Load first document
143
+ title_val, abstract_val, body_val, token_count_val, choices_val = load_document(current_doc_index)
144
  title.value = title_val
145
  abstract.value = abstract_val
146
  body.value = body_val
147
  token_count.value = str(token_count_val)
148
+ pres_selection_dd.value = choices_val
149
 
150
+ pres_selection_dd.change(
151
+ fn=get_selected_document,
152
+ inputs=pres_selection_dd,
153
+ outputs=[title, abstract, body, token_count, pres_selection_dd],
154
+ )
155
 
156
  with gr.Row():
157
  prev_button = gr.Button("Previous Document")
158
+ prev_button.click(fn=get_prev_document, inputs=[], outputs=[pres_selection_dd])
159
  next_button = gr.Button("Next Document")
160
+ next_button.click(fn=get_next_document, inputs=[], outputs=[pres_selection_dd])
161
 
162
  demo.launch()