Spaces:
Sleeping
Sleeping
HonestAnnie
commited on
Commit
•
471f612
1
Parent(s):
0b7e756
formatted metadata
Browse files
app.py
CHANGED
@@ -34,10 +34,10 @@ def query_chroma(collection, embedding, authors):
|
|
34 |
for id_, metadata, document_text, distance in zip(ids, metadatas, documents, distances):
|
35 |
result_dict = {
|
36 |
"id": id_,
|
37 |
-
"author": metadata.get('author', '
|
38 |
-
"book": metadata.get('book', '
|
39 |
-
"section": metadata.get('section', '
|
40 |
-
"title": metadata.get('title', '
|
41 |
"text": document_text,
|
42 |
"distance": distance
|
43 |
}
|
@@ -84,10 +84,10 @@ custom_css = """
|
|
84 |
"""
|
85 |
|
86 |
with gr.Blocks(theme=theme, css=custom_css) as demo:
|
87 |
-
gr.Markdown("Geben Sie ein, wonach Sie suchen möchten (Query), filtern Sie nach Autoren (ohne Auswahl werden alle durchsucht) und klicken Sie auf **Suchen**, um zu suchen.
|
88 |
#database_inp = gr.Dropdown(label="Database", choices=["German", "English"], value="German")
|
89 |
author_inp = gr.Dropdown(label="Autoren", choices=authors_list_de, multiselect=True)
|
90 |
-
inp = gr.Textbox(label="Query", placeholder="Wie kann ich gesund leben?; Wie kann ich mich besser konzentrieren?; Was ist der Sinn des Lebens?; ...")
|
91 |
btn = gr.Button("Suchen")
|
92 |
loading_indicator = gr.Markdown(visible=False)
|
93 |
results = gr.State()
|
@@ -102,7 +102,7 @@ with gr.Blocks(theme=theme, css=custom_css) as demo:
|
|
102 |
#)
|
103 |
|
104 |
def perform_query(queries, authors):
|
105 |
-
task = "
|
106 |
queries = [query.strip() for query in queries.split(';')]
|
107 |
embeddings = get_embeddings(queries, task)
|
108 |
collection = collection_de
|
@@ -113,7 +113,7 @@ with gr.Blocks(theme=theme, css=custom_css) as demo:
|
|
113 |
return results_data, ""
|
114 |
|
115 |
btn.click(
|
116 |
-
fn=lambda: ("
|
117 |
inputs=None,
|
118 |
outputs=[loading_indicator, loading_indicator],
|
119 |
queue=False
|
@@ -129,10 +129,24 @@ with gr.Blocks(theme=theme, css=custom_css) as demo:
|
|
129 |
with gr.Accordion(query, open=False) as acc:
|
130 |
for result in res:
|
131 |
with gr.Column():
|
132 |
-
author = result.get('author', '
|
133 |
-
book = result.get('book', '
|
134 |
-
|
135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
gr.Markdown(value=markdown_contents, elem_classes="custom-markdown")
|
137 |
|
138 |
demo.launch()
|
|
|
34 |
for id_, metadata, document_text, distance in zip(ids, metadatas, documents, distances):
|
35 |
result_dict = {
|
36 |
"id": id_,
|
37 |
+
"author": metadata.get('author', ''),
|
38 |
+
"book": metadata.get('book', ''),
|
39 |
+
"section": metadata.get('section', ''),
|
40 |
+
"title": metadata.get('title', ''),
|
41 |
"text": document_text,
|
42 |
"distance": distance
|
43 |
}
|
|
|
84 |
"""
|
85 |
|
86 |
with gr.Blocks(theme=theme, css=custom_css) as demo:
|
87 |
+
gr.Markdown("Geben Sie ein, wonach Sie suchen möchten (Query), trennen Sie mehrere Suchanfragen durch Semikola; filtern Sie nach Autoren (ohne Auswahl werden alle durchsucht) und klicken Sie auf **Suchen**, um zu suchen.")
|
88 |
#database_inp = gr.Dropdown(label="Database", choices=["German", "English"], value="German")
|
89 |
author_inp = gr.Dropdown(label="Autoren", choices=authors_list_de, multiselect=True)
|
90 |
+
inp = gr.Textbox(label="Query", lines=3, placeholder="Wie kann ich gesund leben?; Wie kann ich mich besser konzentrieren?; Was ist der Sinn des Lebens?; ...")
|
91 |
btn = gr.Button("Suchen")
|
92 |
loading_indicator = gr.Markdown(visible=False)
|
93 |
results = gr.State()
|
|
|
102 |
#)
|
103 |
|
104 |
def perform_query(queries, authors):
|
105 |
+
task = "Suche den zur Frage passenden Text"
|
106 |
queries = [query.strip() for query in queries.split(';')]
|
107 |
embeddings = get_embeddings(queries, task)
|
108 |
collection = collection_de
|
|
|
113 |
return results_data, ""
|
114 |
|
115 |
btn.click(
|
116 |
+
fn=lambda: ("Suche... Das kann bis zu 40 Sekunden dauern...", gr.update(visible=True)),
|
117 |
inputs=None,
|
118 |
outputs=[loading_indicator, loading_indicator],
|
119 |
queue=False
|
|
|
129 |
with gr.Accordion(query, open=False) as acc:
|
130 |
for result in res:
|
131 |
with gr.Column():
|
132 |
+
author = str(result.get('author', ''))
|
133 |
+
book = str(result.get('book', ''))
|
134 |
+
section = str(result.get('section', ''))
|
135 |
+
title = str(result.get('title', ''))
|
136 |
+
text = str(result.get('text', ''))
|
137 |
+
|
138 |
+
header_parts = []
|
139 |
+
if author and author != "Unknown":
|
140 |
+
header_parts.append(author)
|
141 |
+
if book and book != "Unknown":
|
142 |
+
header_parts.append(book)
|
143 |
+
if section and section != "Unknown":
|
144 |
+
header_parts.append(section)
|
145 |
+
if title and title != "Unknown":
|
146 |
+
header_parts.append(title)
|
147 |
+
|
148 |
+
header = ", ".join(header_parts)
|
149 |
+
markdown_contents = f"**{header}**\n\n{text}"
|
150 |
gr.Markdown(value=markdown_contents, elem_classes="custom-markdown")
|
151 |
|
152 |
demo.launch()
|