chansung commited on
Commit
7b9a3c8
·
verified ·
1 Parent(s): 22cc657

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +24 -0
  2. app.py +28 -6
  3. statics/styles.css +27 -3
README.md CHANGED
@@ -131,3 +131,27 @@ $ python main.py # or gradio main.py
131
 
132
  # Acknowledgments
133
  This is a project built during the Vertex sprints held by Google's ML Developer Programs team. We are thankful to be granted good amount of GCP credits to do this project.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
 
132
  # Acknowledgments
133
  This is a project built during the Vertex sprints held by Google's ML Developer Programs team. We are thankful to be granted good amount of GCP credits to do this project.
134
+ # AdaptSum
135
+
136
+ AdaptSum stands for Adaptive Summarization. This project focuses on developing an LLM-powered system for dynamic summarization. Instead of generating entirely new summaries with each update, the system intelligently identifies and modifies only the necessary parts of the existing summary. This approach aims to create a more efficient and fluid summarization process within a continuous chat interaction with an LLM.
137
+
138
+ # Instructions
139
+
140
+ 1. Install dependencies
141
+ ```shell
142
+ $ pip install requirements.txt
143
+ ```
144
+
145
+ 2. Setup Gemini API Key
146
+ ```shell
147
+ $ export GEMINI_API_KEY=xxxxx
148
+ ```
149
+ > note that GEMINI API KEY should be obtained from Google AI Studio. Vertex AI is not supported at the moment (this is because Gemini SDK does not provide file uploading functionality for Vertex AI usage now).
150
+
151
+ 3. Run Gradio app
152
+ ```shell
153
+ $ python main.py # or gradio main.py
154
+ ```
155
+
156
+ # Acknowledgments
157
+ This is a project built during the Vertex sprints held by Google's ML Developer Programs team. We are thankful to be granted good amount of GCP credits to do this project.
app.py CHANGED
@@ -68,12 +68,14 @@ async def echo(message, history, state, persona):
68
  yield (
69
  response_chunks,
70
  state,
 
71
  state['summary_diff_history'][-1] if len(state['summary_diff_history']) > 1 else "",
72
  state['summary_history'][-1] if len(state['summary_history']) > 1 else "",
73
  gr.Slider(
74
  visible=False if len(state['summary_history']) <= 1 else True,
75
  interactive=False if len(state['summary_history']) <= 1 else True,
76
  ),
 
77
  )
78
 
79
  # make summary
@@ -113,10 +115,16 @@ async def echo(message, history, state, persona):
113
  for token in Differ().compare(prev_summary, state['summary'])
114
  ]
115
  )
 
 
 
 
 
116
 
117
  yield (
118
  response_chunks,
119
  state,
 
120
  state['summary_diff_history'][-1],
121
  state['summary_history'][-1],
122
  gr.Slider(
@@ -124,6 +132,7 @@ async def echo(message, history, state, persona):
124
  value=len(state['summary_history']),
125
  visible=False if len(state['summary_history']) == 1 else True, interactive=True
126
  ),
 
127
  )
128
 
129
  def change_view_toggle(view_toggle):
@@ -140,8 +149,10 @@ def change_view_toggle(view_toggle):
140
 
141
  def navigate_to_summary(summary_num, state):
142
  return (
 
143
  state['summary_diff_history'][summary_num-1],
144
- state['summary_history'][summary_num-1]
 
145
  )
146
 
147
  def main(args):
@@ -156,10 +167,12 @@ def main(args):
156
  # State per session
157
  state = gr.State({
158
  "messages": [],
 
159
  "attached_files": [],
160
  "summary": "",
161
  "summary_history": [],
162
- "summary_diff_history": []
 
163
  })
164
 
165
  with gr.Column():
@@ -176,27 +189,36 @@ def main(args):
176
  elem_id="view-toggle-btn"
177
  )
178
 
 
 
 
 
 
 
 
179
  summary_diff = gr.HighlightedText(
180
  label="Summary so far",
181
  # value="No summary yet. As you chat with the assistant, the summary will be updated automatically.",
182
  combine_adjacent=True,
183
  show_legend=True,
184
  color_map={"-": "red", "+": "green"},
185
- elem_classes=["summary-window"],
186
  visible=False
187
  )
188
 
189
  summary_md = gr.Markdown(
190
  label="Summary so far",
191
  value="No summary yet. As you chat with the assistant, the summary will be updated automatically.",
192
- elem_classes=["summary-window"],
193
  visible=True
194
  )
195
 
196
  summary_num = gr.Slider(label="summary history", minimum=1, maximum=1, step=1, show_reset_button=False, visible=False)
197
 
 
 
198
  view_toggle_btn.change(change_view_toggle, inputs=[view_toggle_btn], outputs=[summary_diff, summary_md])
199
- summary_num.release(navigate_to_summary, inputs=[summary_num, state], outputs=[summary_diff, summary_md])
200
 
201
  with gr.Column("persona-dropdown-container", elem_id="persona-dropdown-container"):
202
  persona = gr.Dropdown(
@@ -212,7 +234,7 @@ def main(args):
212
  type="messages",
213
  fn=echo,
214
  additional_inputs=[state, persona],
215
- additional_outputs=[state, summary_diff, summary_md, summary_num],
216
  )
217
 
218
  return demo
 
68
  yield (
69
  response_chunks,
70
  state,
71
+ message['text'],
72
  state['summary_diff_history'][-1] if len(state['summary_diff_history']) > 1 else "",
73
  state['summary_history'][-1] if len(state['summary_history']) > 1 else "",
74
  gr.Slider(
75
  visible=False if len(state['summary_history']) <= 1 else True,
76
  interactive=False if len(state['summary_history']) <= 1 else True,
77
  ),
78
+ gr.DownloadButton(visible=False)
79
  )
80
 
81
  # make summary
 
115
  for token in Differ().compare(prev_summary, state['summary'])
116
  ]
117
  )
118
+ state['user_messages'].append(message['text'])
119
+
120
+ state['filepaths'].append(f"{os.urandom(10).hex()}_summary_at_{len(state['summary_history'])}.md")
121
+ with open(state['filepaths'][-1], 'w', encoding='utf-8') as f:
122
+ f.write(state['summary'])
123
 
124
  yield (
125
  response_chunks,
126
  state,
127
+ message['text'],
128
  state['summary_diff_history'][-1],
129
  state['summary_history'][-1],
130
  gr.Slider(
 
132
  value=len(state['summary_history']),
133
  visible=False if len(state['summary_history']) == 1 else True, interactive=True
134
  ),
135
+ gr.DownloadButton(f"Download summary at index {len(state['summary_history'])}", value=state['filepaths'][-1], visible=True)
136
  )
137
 
138
  def change_view_toggle(view_toggle):
 
149
 
150
  def navigate_to_summary(summary_num, state):
151
  return (
152
+ state['user_messages'][summary_num-1],
153
  state['summary_diff_history'][summary_num-1],
154
+ state['summary_history'][summary_num-1],
155
+ gr.DownloadButton(f"Download summary at index {summary_num}", value=state['filepaths'][summary_num-1])
156
  )
157
 
158
  def main(args):
 
167
  # State per session
168
  state = gr.State({
169
  "messages": [],
170
+ "user_messages": [],
171
  "attached_files": [],
172
  "summary": "",
173
  "summary_history": [],
174
+ "summary_diff_history": [],
175
+ "filepaths": []
176
  })
177
 
178
  with gr.Column():
 
189
  elem_id="view-toggle-btn"
190
  )
191
 
192
+ last_user_msg = gr.Textbox(
193
+ label="Last User Message",
194
+ value="",
195
+ interactive=False,
196
+ elem_classes=["last-user-msg"]
197
+ )
198
+
199
  summary_diff = gr.HighlightedText(
200
  label="Summary so far",
201
  # value="No summary yet. As you chat with the assistant, the summary will be updated automatically.",
202
  combine_adjacent=True,
203
  show_legend=True,
204
  color_map={"-": "red", "+": "green"},
205
+ elem_classes=["summary-window-highlighted"],
206
  visible=False
207
  )
208
 
209
  summary_md = gr.Markdown(
210
  label="Summary so far",
211
  value="No summary yet. As you chat with the assistant, the summary will be updated automatically.",
212
+ elem_classes=["summary-window-markdown"],
213
  visible=True
214
  )
215
 
216
  summary_num = gr.Slider(label="summary history", minimum=1, maximum=1, step=1, show_reset_button=False, visible=False)
217
 
218
+ download_summary_md = gr.DownloadButton("Download summary", visible=False)
219
+
220
  view_toggle_btn.change(change_view_toggle, inputs=[view_toggle_btn], outputs=[summary_diff, summary_md])
221
+ summary_num.release(navigate_to_summary, inputs=[summary_num, state], outputs=[last_user_msg, summary_diff, summary_md, download_summary_md])
222
 
223
  with gr.Column("persona-dropdown-container", elem_id="persona-dropdown-container"):
224
  persona = gr.Dropdown(
 
234
  type="messages",
235
  fn=echo,
236
  additional_inputs=[state, persona],
237
+ additional_outputs=[state, last_user_msg, summary_diff, summary_md, summary_num, download_summary_md],
238
  )
239
 
240
  return demo
statics/styles.css CHANGED
@@ -1,11 +1,27 @@
1
- .summary-window {
2
- height: 600px !important;
 
 
 
 
 
 
 
 
 
 
 
 
3
  /* border: dashed 1px #e0e0e0 !important; */
4
  border-radius: 10px !important;
5
  padding: 4px;
6
  }
7
 
8
- .summary-window > label {
 
 
 
 
9
  display: none !important;
10
  }
11
 
@@ -48,4 +64,12 @@
48
 
49
  #persona-dropdown-container {
50
  margin-top: 40px !important;
 
 
 
 
 
 
 
 
51
  }
 
1
+ .summary-window-markdown {
2
+ height: 550px !important;
3
+ /* border: dashed 1px #e0e0e0 !important; */
4
+ border-radius: 10px !important;
5
+ padding: 4px;
6
+ border: 2px solid var(--border-color-primary) !important;
7
+ }
8
+
9
+ .summary-window-markdown > div > div {
10
+ border: none !important;
11
+ }
12
+
13
+ .summary-window-highlighted {
14
+ height: 550px !important;
15
  /* border: dashed 1px #e0e0e0 !important; */
16
  border-radius: 10px !important;
17
  padding: 4px;
18
  }
19
 
20
+ .summary-window-markdown > label {
21
+ display: none !important;
22
+ }
23
+
24
+ .summary-window-highlighted > label {
25
  display: none !important;
26
  }
27
 
 
64
 
65
  #persona-dropdown-container {
66
  margin-top: 40px !important;
67
+ }
68
+
69
+ .last-user-msg {
70
+ padding: 0px !important;
71
+ }
72
+
73
+ .last-user-msg > label > span {
74
+ display: none !important;
75
  }