Julia Ostheimer commited on
Commit
8398286
·
1 Parent(s): caedc5e

Remove previous implementation with global variable and edit titles in UI

Browse files
Files changed (1) hide show
  1. app.py +1 -37
app.py CHANGED
@@ -24,10 +24,6 @@ from tools.langfuse_client import get_langfuse_handler
24
 
25
  from config import app_settings
26
 
27
- document_metadata_to_display_in_ui = []
28
- def get_metadata():
29
- global document_metadata_to_display_in_ui
30
- return document_metadata_to_display_in_ui # safe to read and return
31
 
32
  # Get Langfuse Callback handler
33
  langfuse_handler = get_langfuse_handler()
@@ -92,22 +88,6 @@ def get_chunk_page_number(document) -> str:
92
 
93
  return str(correct_page_number)
94
 
95
- def pretty_source_history_md():
96
- unpretty_history = get_metadata()
97
- if not unpretty_history:
98
- return "Bislang wurden keine Anfragen gestellt."
99
-
100
- markdown_string = ""
101
- for idx, record in enumerate(unpretty_history):
102
- markdown_string += f"## Query {idx+1}: `{record['query']}`\n"
103
- for filename, page, chunk in zip(record["filename"], record["number_of_pages"], record["source_text_chunk"]):
104
- # Clean up chunk: remove newlines and trim spaces
105
- cleaned_chunk = chunk.replace("\n", " ").replace("\r", " ").strip()
106
-
107
- markdown_string += f"- **Dokument**: {filename}, **Seite**: {page}\n\n> {cleaned_chunk} \n\n"
108
- markdown_string += "---\n"
109
- return markdown_string
110
-
111
  def prettify_session_state_content(session_state):
112
 
113
  unpretty_history = session_state
@@ -130,16 +110,6 @@ def retrieve(query: str):
130
  (f"Source: {doc.metadata}\n" f"Content: {doc.page_content}")
131
  for doc in retrieved_docs
132
  )
133
-
134
- global document_metadata_to_display_in_ui
135
- document_metadata_to_display_in_ui.append({
136
- "query": query,
137
- "filename": [get_document_filename(doc) for doc in retrieved_docs],
138
- "number_of_pages": [get_chunk_page_number(doc) for doc in retrieved_docs],
139
- "source_text_chunk": [doc.page_content for doc in retrieved_docs]
140
- })
141
-
142
- logger.info("Retrieved document metadata to display in UI", content=document_metadata_to_display_in_ui)
143
 
144
  return serialized, retrieved_docs
145
 
@@ -245,7 +215,7 @@ def bot(message, history, session_data) -> list[Any]:
245
  with gr.Blocks() as demo:
246
  session_data = gr.State([])
247
 
248
- gr.Markdown("Dies ist der aktuelle Protozype der DEval AI4Kontextanalysen, mit dem Fokus auf das Testen der Zitationsfunktion und der grundlegenden Konfiguration.")
249
  with gr.Tab("Chat"):
250
  gr.ChatInterface(
251
  bot,
@@ -260,12 +230,6 @@ with gr.Blocks() as demo:
260
  additional_outputs=[session_data],
261
  )
262
  with gr.Tab("Quellen"):
263
- gr.Markdown("Hier sind die Quellen")
264
- btn = gr.Button("Zuletzt genutzte Quellen anzeigen")
265
- source_history = gr.Markdown(pretty_source_history_md())
266
- btn.click(pretty_source_history_md, outputs=source_history)
267
-
268
- gr.Markdown("## Current State:")
269
  state_display = gr.Markdown()
270
  session_data.change(prettify_session_state_content, session_data, state_display)
271
 
 
24
 
25
  from config import app_settings
26
 
 
 
 
 
27
 
28
  # Get Langfuse Callback handler
29
  langfuse_handler = get_langfuse_handler()
 
88
 
89
  return str(correct_page_number)
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  def prettify_session_state_content(session_state):
92
 
93
  unpretty_history = session_state
 
110
  (f"Source: {doc.metadata}\n" f"Content: {doc.page_content}")
111
  for doc in retrieved_docs
112
  )
 
 
 
 
 
 
 
 
 
 
113
 
114
  return serialized, retrieved_docs
115
 
 
215
  with gr.Blocks() as demo:
216
  session_data = gr.State([])
217
 
218
+ gr.Markdown("### Dies ist der aktuelle Prototyp der DEval AI4Kontextanalysen, mit dem Fokus auf dem Testen der Zitationsfunktion und der grundlegenden Konfiguration.")
219
  with gr.Tab("Chat"):
220
  gr.ChatInterface(
221
  bot,
 
230
  additional_outputs=[session_data],
231
  )
232
  with gr.Tab("Quellen"):
 
 
 
 
 
 
233
  state_display = gr.Markdown()
234
  session_data.change(prettify_session_state_content, session_data, state_display)
235