Commit
·
65557bc
1
Parent(s):
58d2a52
fix
Browse files
app.log
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
app.py
CHANGED
@@ -172,17 +172,38 @@ async def summarize_chat(end_of_chat_response: bool, messages: dict, sidebar_sum
|
|
172 |
)
|
173 |
if should_return:
|
174 |
return gr.skip(), gr.skip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
config = RunnableConfig(
|
176 |
run_name="summarize_chat",
|
177 |
configurable={"thread_id": uuid}
|
178 |
)
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
return sidebar_summaries, False
|
187 |
|
188 |
async def new_tab(uuid, gradio_graph, messages, tabs, prompt, sidebar_summaries):
|
@@ -257,6 +278,10 @@ footer {visibility: hidden}
|
|
257 |
padding-left: 0;
|
258 |
padding-right: 0;
|
259 |
}
|
|
|
|
|
|
|
|
|
260 |
"""
|
261 |
|
262 |
# We set the ChatInterface textbox id to chat-textbox for this to work
|
@@ -283,6 +308,36 @@ function triggerChatButtonClick() {
|
|
283 |
button.click();
|
284 |
}"""
|
285 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
286 |
if __name__ == "__main__":
|
287 |
logger.info("Starting the interface")
|
288 |
with gr.Blocks(title="Langgraph Template", fill_height=True, css=CSS) as app:
|
@@ -510,6 +565,7 @@ if __name__ == "__main__":
|
|
510 |
def click_followup_button(btn):
|
511 |
buttons = [gr.Button(visible=False) for _ in range(len(followup_question_buttons))]
|
512 |
return btn, *buttons
|
|
|
513 |
for btn in followup_question_buttons:
|
514 |
btn.click(
|
515 |
fn=click_followup_button,
|
@@ -562,4 +618,6 @@ if __name__ == "__main__":
|
|
562 |
def load_prompt(current_prompt):
|
563 |
return current_prompt
|
564 |
|
|
|
|
|
565 |
app.launch(server_name="0.0.0.0", server_port=7860, share=True)
|
|
|
172 |
)
|
173 |
if should_return:
|
174 |
return gr.skip(), gr.skip()
|
175 |
+
|
176 |
+
filtered_messages = []
|
177 |
+
for msg in messages:
|
178 |
+
if isinstance(msg, dict) and msg.get("content") and msg["content"].strip():
|
179 |
+
filtered_messages.append(msg)
|
180 |
+
|
181 |
+
# If we don't have any valid messages after filtering, provide a default summary
|
182 |
+
if not filtered_messages:
|
183 |
+
if uuid not in sidebar_summaries:
|
184 |
+
sidebar_summaries[uuid] = "Chat History"
|
185 |
+
return sidebar_summaries, False
|
186 |
+
|
187 |
+
|
188 |
config = RunnableConfig(
|
189 |
run_name="summarize_chat",
|
190 |
configurable={"thread_id": uuid}
|
191 |
)
|
192 |
+
try:
|
193 |
+
weak_model_with_config = weak_model.with_config(config)
|
194 |
+
summary_response = await weak_model_with_config.ainvoke([
|
195 |
+
("system", "summarize this chat in 7 tokens or less. Refrain from using periods"),
|
196 |
+
*filtered_messages,
|
197 |
+
])
|
198 |
+
|
199 |
+
if uuid not in sidebar_summaries:
|
200 |
+
sidebar_summaries[uuid] = summary_response.content
|
201 |
+
except Exception as e:
|
202 |
+
logger.error(f"Error summarizing chat: {e}")
|
203 |
+
# Provide a fallback summary if an error occurs
|
204 |
+
if uuid not in sidebar_summaries:
|
205 |
+
sidebar_summaries[uuid] = "Previous Chat"
|
206 |
+
|
207 |
return sidebar_summaries, False
|
208 |
|
209 |
async def new_tab(uuid, gradio_graph, messages, tabs, prompt, sidebar_summaries):
|
|
|
278 |
padding-left: 0;
|
279 |
padding-right: 0;
|
280 |
}
|
281 |
+
|
282 |
+
.sidebar-collapsed {
|
283 |
+
display: none !important;
|
284 |
+
}
|
285 |
"""
|
286 |
|
287 |
# We set the ChatInterface textbox id to chat-textbox for this to work
|
|
|
308 |
button.click();
|
309 |
}"""
|
310 |
|
311 |
+
|
312 |
+
SIDEBAR_VISIBILITY_JS = """
|
313 |
+
document.addEventListener('DOMContentLoaded', function() {
|
314 |
+
// Wait for Gradio to fully load
|
315 |
+
setTimeout(function() {
|
316 |
+
const sidebarToggle = document.querySelector('.sidebar button');
|
317 |
+
const sidebar = document.querySelector('.sidebar');
|
318 |
+
|
319 |
+
if (sidebarToggle && sidebar) {
|
320 |
+
// Initial check
|
321 |
+
if (sidebar.classList.contains('!-left-64')) {
|
322 |
+
sidebar.classList.add('sidebar-collapsed');
|
323 |
+
}
|
324 |
+
|
325 |
+
// Add click listener to toggle button
|
326 |
+
sidebarToggle.addEventListener('click', function() {
|
327 |
+
// Use setTimeout to wait for Gradio's class changes to apply
|
328 |
+
setTimeout(function() {
|
329 |
+
if (sidebar.classList.contains('!-left-64')) {
|
330 |
+
sidebar.classList.add('sidebar-collapsed');
|
331 |
+
} else {
|
332 |
+
sidebar.classList.remove('sidebar-collapsed');
|
333 |
+
}
|
334 |
+
}, 50);
|
335 |
+
});
|
336 |
+
}
|
337 |
+
}, 1000);
|
338 |
+
});
|
339 |
+
"""
|
340 |
+
|
341 |
if __name__ == "__main__":
|
342 |
logger.info("Starting the interface")
|
343 |
with gr.Blocks(title="Langgraph Template", fill_height=True, css=CSS) as app:
|
|
|
565 |
def click_followup_button(btn):
|
566 |
buttons = [gr.Button(visible=False) for _ in range(len(followup_question_buttons))]
|
567 |
return btn, *buttons
|
568 |
+
|
569 |
for btn in followup_question_buttons:
|
570 |
btn.click(
|
571 |
fn=click_followup_button,
|
|
|
618 |
def load_prompt(current_prompt):
|
619 |
return current_prompt
|
620 |
|
621 |
+
|
622 |
+
app.js = SIDEBAR_VISIBILITY_JS
|
623 |
app.launch(server_name="0.0.0.0", server_port=7860, share=True)
|