update UI
Browse files- app.py +88 -19
- statics/styles.css +28 -3
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import os
|
2 |
-
import gradio as gr
|
3 |
import argparse
|
|
|
|
|
4 |
from functools import partial
|
5 |
from string import Template
|
6 |
from utils import load_prompt, setup_gemini_client
|
@@ -25,7 +26,7 @@ def find_attached_file(filename, attached_files):
|
|
25 |
return None
|
26 |
|
27 |
def echo(message, history, state):
|
28 |
-
|
29 |
attached_file = None
|
30 |
if message['files']:
|
31 |
path_local = message['files'][0]
|
@@ -60,9 +61,7 @@ def echo(message, history, state):
|
|
60 |
model_response = response.text
|
61 |
|
62 |
# make summary
|
63 |
-
if state['summary']
|
64 |
-
state['summary'] = response.text
|
65 |
-
else:
|
66 |
response = client.models.generate_content(
|
67 |
model="gemini-1.5-flash",
|
68 |
contents=[
|
@@ -74,9 +73,52 @@ def echo(message, history, state):
|
|
74 |
)
|
75 |
]
|
76 |
)
|
77 |
-
state['summary'] = response.text
|
78 |
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
def main(args):
|
82 |
style_css = open(args.css_path, "r").read()
|
@@ -91,25 +133,52 @@ def main(args):
|
|
91 |
state = gr.State({
|
92 |
"messages": [],
|
93 |
"attached_files": [],
|
94 |
-
"summary": ""
|
|
|
|
|
95 |
})
|
96 |
|
97 |
gr.Markdown("# Adaptive Summarization")
|
98 |
gr.Markdown("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.")
|
99 |
|
100 |
-
with gr.
|
101 |
-
with gr.
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
type="messages",
|
108 |
-
fn=echo,
|
109 |
-
additional_inputs=[state],
|
110 |
-
additional_outputs=[state, summary],
|
111 |
)
|
112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
return demo
|
114 |
|
115 |
if __name__ == "__main__":
|
|
|
1 |
import os
|
|
|
2 |
import argparse
|
3 |
+
import gradio as gr
|
4 |
+
from difflib import Differ
|
5 |
from functools import partial
|
6 |
from string import Template
|
7 |
from utils import load_prompt, setup_gemini_client
|
|
|
26 |
return None
|
27 |
|
28 |
def echo(message, history, state):
|
29 |
+
|
30 |
attached_file = None
|
31 |
if message['files']:
|
32 |
path_local = message['files'][0]
|
|
|
61 |
model_response = response.text
|
62 |
|
63 |
# make summary
|
64 |
+
if state['summary'] != "":
|
|
|
|
|
65 |
response = client.models.generate_content(
|
66 |
model="gemini-1.5-flash",
|
67 |
contents=[
|
|
|
73 |
)
|
74 |
]
|
75 |
)
|
|
|
76 |
|
77 |
+
if state['summary'] != "":
|
78 |
+
prev_summary = state['summary_history'][-1]
|
79 |
+
else:
|
80 |
+
prev_summary = ""
|
81 |
+
|
82 |
+
d = Differ()
|
83 |
+
state['summary'] = response.text
|
84 |
+
state['summary_history'].append(response.text)
|
85 |
+
state['summary_diff_history'].append(
|
86 |
+
[
|
87 |
+
(token[2:], token[0] if token[0] != " " else None)
|
88 |
+
for token in d.compare(prev_summary, state['summary'])
|
89 |
+
]
|
90 |
+
)
|
91 |
+
|
92 |
+
return (
|
93 |
+
model_response,
|
94 |
+
state,
|
95 |
+
# state['summary'],
|
96 |
+
state['summary_diff_history'][-1],
|
97 |
+
state['summary_history'][-1],
|
98 |
+
gr.Slider(
|
99 |
+
maximum=len(state['summary_history']),
|
100 |
+
value=len(state['summary_history']),
|
101 |
+
visible=False if len(state['summary_history']) == 1 else True, interactive=True
|
102 |
+
),
|
103 |
+
)
|
104 |
+
|
105 |
+
def change_view_toggle(view_toggle):
|
106 |
+
if view_toggle == "Diff":
|
107 |
+
return (
|
108 |
+
gr.HighlightedText(visible=True),
|
109 |
+
gr.Markdown(visible=False)
|
110 |
+
)
|
111 |
+
else:
|
112 |
+
return (
|
113 |
+
gr.HighlightedText(visible=False),
|
114 |
+
gr.Markdown(visible=True)
|
115 |
+
)
|
116 |
+
|
117 |
+
def navigate_to_summary(summary_num, state):
|
118 |
+
return (
|
119 |
+
state['summary_diff_history'][summary_num-1],
|
120 |
+
state['summary_history'][summary_num-1]
|
121 |
+
)
|
122 |
|
123 |
def main(args):
|
124 |
style_css = open(args.css_path, "r").read()
|
|
|
133 |
state = gr.State({
|
134 |
"messages": [],
|
135 |
"attached_files": [],
|
136 |
+
"summary": "",
|
137 |
+
"summary_history": [],
|
138 |
+
"summary_diff_history": []
|
139 |
})
|
140 |
|
141 |
gr.Markdown("# Adaptive Summarization")
|
142 |
gr.Markdown("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.")
|
143 |
|
144 |
+
with gr.Accordion("Adaptive Summary"):
|
145 |
+
with gr.Row(elem_id="view-toggle-btn-container"):
|
146 |
+
view_toggle_btn = gr.Radio(
|
147 |
+
choices=["Diff", "Markdown"],
|
148 |
+
value="Markdown",
|
149 |
+
interactive=True,
|
150 |
+
elem_id="view-toggle-btn"
|
|
|
|
|
|
|
|
|
151 |
)
|
152 |
|
153 |
+
summary_diff = gr.HighlightedText(
|
154 |
+
label="Summary so far",
|
155 |
+
combine_adjacent=True,
|
156 |
+
show_legend=True,
|
157 |
+
color_map={"+": "red", "-": "green"},
|
158 |
+
elem_classes=["summary-window"],
|
159 |
+
visible=False
|
160 |
+
)
|
161 |
+
|
162 |
+
summary_md = gr.Markdown(
|
163 |
+
label="Summary so far",
|
164 |
+
elem_classes=["summary-window"],
|
165 |
+
visible=True
|
166 |
+
)
|
167 |
+
|
168 |
+
summary_num = gr.Slider(label="summary history", minimum=1, maximum=1, step=1, show_reset_button=False, visible=False)
|
169 |
+
|
170 |
+
view_toggle_btn.change(change_view_toggle, inputs=[view_toggle_btn], outputs=[summary_diff, summary_md])
|
171 |
+
summary_num.release(navigate_to_summary, inputs=[summary_num, state], outputs=[summary_diff, summary_md])
|
172 |
+
|
173 |
+
with gr.Column("chat-window"):
|
174 |
+
gr.ChatInterface(
|
175 |
+
multimodal=True,
|
176 |
+
type="messages",
|
177 |
+
fn=echo,
|
178 |
+
additional_inputs=[state],
|
179 |
+
additional_outputs=[state, summary_diff, summary_md, summary_num],
|
180 |
+
)
|
181 |
+
|
182 |
return demo
|
183 |
|
184 |
if __name__ == "__main__":
|
statics/styles.css
CHANGED
@@ -1,3 +1,28 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.summary-window {
|
2 |
+
height: 400px !important;
|
3 |
+
border: solid 1px red !important;
|
4 |
+
padding: 4px;
|
5 |
+
}
|
6 |
+
|
7 |
+
#view-toggle-btn-container > div {
|
8 |
+
border: none !important;
|
9 |
+
}
|
10 |
+
|
11 |
+
#view-toggle-btn > span {
|
12 |
+
display: none !important;
|
13 |
+
}
|
14 |
+
|
15 |
+
#view-toggle-btn > div:nth-child(3) {
|
16 |
+
margin: auto !important;
|
17 |
+
width: fit-content !important;
|
18 |
+
}
|
19 |
+
|
20 |
+
.textfield {
|
21 |
+
line-height: 1.7 !important;
|
22 |
+
}
|
23 |
+
|
24 |
+
.textspan {
|
25 |
+
padding: 0px !important;
|
26 |
+
margin: 0px !important;
|
27 |
+
line-height: 1.7 !important;
|
28 |
+
}
|