Julia Ostheimer
commited on
Commit
·
768cf00
1
Parent(s):
c50cc21
Add example of saving data to session state with ChatInterface
Browse files
app.py
CHANGED
|
@@ -160,7 +160,7 @@ graph_builder.add_edge("generate", END)
|
|
| 160 |
graph = graph_builder.compile(checkpointer=memory)
|
| 161 |
# -----
|
| 162 |
|
| 163 |
-
def bot(message, history) -> list[Any]:
|
| 164 |
"""Generate bot response and history from message.
|
| 165 |
|
| 166 |
With multi-modal inputs text and each file is treated as separate message.
|
|
@@ -187,10 +187,14 @@ def bot(message, history) -> list[Any]:
|
|
| 187 |
|
| 188 |
logger.info("Generated a response", response=response)
|
| 189 |
|
| 190 |
-
|
|
|
|
| 191 |
|
|
|
|
| 192 |
|
| 193 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
| 194 |
gr.Markdown("Dies ist der aktuelle Protozype der DEval AI4Kontextanalysen, mit dem Fokus auf das Testen der Zitationsfunktion und der grundlegenden Konfiguration.")
|
| 195 |
with gr.Tab("Chat"):
|
| 196 |
gr.ChatInterface(
|
|
@@ -202,6 +206,8 @@ with gr.Blocks() as demo:
|
|
| 202 |
multimodal=True,
|
| 203 |
textbox=gr.MultimodalTextbox(file_count="multiple"),
|
| 204 |
title="DEval Prototype 1",
|
|
|
|
|
|
|
| 205 |
)
|
| 206 |
with gr.Tab("Quellen"):
|
| 207 |
gr.Markdown("Hier sind die Quellen")
|
|
@@ -209,5 +215,9 @@ with gr.Blocks() as demo:
|
|
| 209 |
source_history = gr.Markdown(pretty_source_history_md())
|
| 210 |
btn.click(pretty_source_history_md, outputs=source_history)
|
| 211 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
if __name__ == "__main__":
|
| 213 |
demo.launch(share=False, server_name="0.0.0.0")
|
|
|
|
| 160 |
graph = graph_builder.compile(checkpointer=memory)
|
| 161 |
# -----
|
| 162 |
|
| 163 |
+
def bot(message, history, session_data) -> list[Any]:
|
| 164 |
"""Generate bot response and history from message.
|
| 165 |
|
| 166 |
With multi-modal inputs text and each file is treated as separate message.
|
|
|
|
| 187 |
|
| 188 |
logger.info("Generated a response", response=response)
|
| 189 |
|
| 190 |
+
# Example: append dict to session state
|
| 191 |
+
session_data.append("test")
|
| 192 |
|
| 193 |
+
return [response["messages"][-1].content], session_data
|
| 194 |
|
| 195 |
with gr.Blocks() as demo:
|
| 196 |
+
session_data = gr.State([])
|
| 197 |
+
|
| 198 |
gr.Markdown("Dies ist der aktuelle Protozype der DEval AI4Kontextanalysen, mit dem Fokus auf das Testen der Zitationsfunktion und der grundlegenden Konfiguration.")
|
| 199 |
with gr.Tab("Chat"):
|
| 200 |
gr.ChatInterface(
|
|
|
|
| 206 |
multimodal=True,
|
| 207 |
textbox=gr.MultimodalTextbox(file_count="multiple"),
|
| 208 |
title="DEval Prototype 1",
|
| 209 |
+
additional_inputs=[session_data],
|
| 210 |
+
additional_outputs=[session_data],
|
| 211 |
)
|
| 212 |
with gr.Tab("Quellen"):
|
| 213 |
gr.Markdown("Hier sind die Quellen")
|
|
|
|
| 215 |
source_history = gr.Markdown(pretty_source_history_md())
|
| 216 |
btn.click(pretty_source_history_md, outputs=source_history)
|
| 217 |
|
| 218 |
+
gr.Markdown("## Current State:")
|
| 219 |
+
state_display = gr.Markdown()
|
| 220 |
+
session_data.change(lambda s: f"{s or []}", session_data, state_display)
|
| 221 |
+
|
| 222 |
if __name__ == "__main__":
|
| 223 |
demo.launch(share=False, server_name="0.0.0.0")
|