Julia Ostheimer
commited on
Commit
·
d0bf374
1
Parent(s):
c2a9ca7
Show source history in pretty markdown when clicking button to retrieve latest sources
Browse files
app.py
CHANGED
|
@@ -77,6 +77,22 @@ def get_document_filename(document) -> str:
|
|
| 77 |
|
| 78 |
return document_filename
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
@tool(response_format="content_and_artifact")
|
| 81 |
def retrieve(query: str):
|
| 82 |
"""Retrieve information related to a query."""
|
|
@@ -175,9 +191,9 @@ with gr.Blocks() as demo:
|
|
| 175 |
)
|
| 176 |
with gr.Tab("Quellen"):
|
| 177 |
gr.Markdown("Hier sind die Quellen")
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
btn.click(
|
| 181 |
|
| 182 |
if __name__ == "__main__":
|
| 183 |
demo.launch(share=False, server_name="0.0.0.0")
|
|
|
|
| 77 |
|
| 78 |
return document_filename
|
| 79 |
|
| 80 |
+
def pretty_source_history_md():
|
| 81 |
+
unpretty_history = get_metadata()
|
| 82 |
+
if not unpretty_history:
|
| 83 |
+
return "Bislang wurden keine Anfragen gestellt."
|
| 84 |
+
|
| 85 |
+
markdown_string = ""
|
| 86 |
+
for idx, record in enumerate(unpretty_history):
|
| 87 |
+
markdown_string += f"## Query {idx+1}: `{record['query']}`\n"
|
| 88 |
+
for filename, author, creation_date, chunk in zip(record["filename"], record["author"], record["creation_date"], record["source_text_chunk"]):
|
| 89 |
+
# Clean up chunk: remove newlines and trim spaces
|
| 90 |
+
cleaned_chunk = chunk.replace("\n", " ").replace("\r", " ").strip()
|
| 91 |
+
|
| 92 |
+
markdown_string += f"- **Dokument**: {filename}, **Autor(en)**: {author}, **Erstellungsdatum**: {creation_date}\n\n> {cleaned_chunk} \n\n"
|
| 93 |
+
markdown_string += "---\n"
|
| 94 |
+
return markdown_string
|
| 95 |
+
|
| 96 |
@tool(response_format="content_and_artifact")
|
| 97 |
def retrieve(query: str):
|
| 98 |
"""Retrieve information related to a query."""
|
|
|
|
| 191 |
)
|
| 192 |
with gr.Tab("Quellen"):
|
| 193 |
gr.Markdown("Hier sind die Quellen")
|
| 194 |
+
btn = gr.Button("Zuletzt genutzte Quellen anzeigen")
|
| 195 |
+
source_history = gr.Markdown(pretty_source_history_md())
|
| 196 |
+
btn.click(pretty_source_history_md, outputs=source_history)
|
| 197 |
|
| 198 |
if __name__ == "__main__":
|
| 199 |
demo.launch(share=False, server_name="0.0.0.0")
|