Spaces:
Sleeping
Sleeping
Commit
·
ef39d37
1
Parent(s):
08029e5
added loading
Browse files
app.py
CHANGED
@@ -51,6 +51,7 @@ with gr.Blocks(css=".custom-markdown { border: 1px solid #ccc; padding: 10px; bo
|
|
51 |
author_inp = gr.Dropdown(label="Autoren", choices=authors_list_de, multiselect=True)
|
52 |
inp = gr.Textbox(label="Query", placeholder="Wie kann ich gesund leben?; Wie kann ich mich besser konzentrieren?; Was ist der Sinn des Lebens?; ...")
|
53 |
btn = gr.Button("Suchen")
|
|
|
54 |
results = gr.State()
|
55 |
|
56 |
#def update_authors(database):
|
@@ -62,22 +63,26 @@ with gr.Blocks(css=".custom-markdown { border: 1px solid #ccc; padding: 10px; bo
|
|
62 |
# outputs=[author_inp]
|
63 |
#)
|
64 |
|
65 |
-
def perform_query(queries, authors
|
66 |
task = "Given a question, retrieve passages that answer the question"
|
67 |
queries = [query.strip() for query in queries.split(';')]
|
68 |
embeddings = get_embeddings(queries, task)
|
69 |
-
#collection = collection_de if database == "German" else collection_en
|
70 |
collection = collection_de
|
71 |
results_data = []
|
72 |
for query, embedding in zip(queries, embeddings):
|
73 |
res = query_chroma(collection, embedding, authors)
|
74 |
results_data.append((query, res))
|
75 |
-
return results_data
|
76 |
|
77 |
btn.click(
|
|
|
|
|
|
|
|
|
|
|
78 |
perform_query,
|
79 |
inputs=[inp, author_inp],
|
80 |
-
outputs=[results]
|
81 |
)
|
82 |
|
83 |
@gr.render(inputs=[results])
|
|
|
51 |
author_inp = gr.Dropdown(label="Autoren", choices=authors_list_de, multiselect=True)
|
52 |
inp = gr.Textbox(label="Query", placeholder="Wie kann ich gesund leben?; Wie kann ich mich besser konzentrieren?; Was ist der Sinn des Lebens?; ...")
|
53 |
btn = gr.Button("Suchen")
|
54 |
+
loading_indicator = gr.Markdown(visible=False)
|
55 |
results = gr.State()
|
56 |
|
57 |
#def update_authors(database):
|
|
|
63 |
# outputs=[author_inp]
|
64 |
#)
|
65 |
|
66 |
+
def perform_query(queries, authors):
|
67 |
task = "Given a question, retrieve passages that answer the question"
|
68 |
queries = [query.strip() for query in queries.split(';')]
|
69 |
embeddings = get_embeddings(queries, task)
|
|
|
70 |
collection = collection_de
|
71 |
results_data = []
|
72 |
for query, embedding in zip(queries, embeddings):
|
73 |
res = query_chroma(collection, embedding, authors)
|
74 |
results_data.append((query, res))
|
75 |
+
return results_data, ""
|
76 |
|
77 |
btn.click(
|
78 |
+
fn=lambda: ("Searching... This may take up to 40 seconds.", gr.update(visible=True)),
|
79 |
+
inputs=None,
|
80 |
+
outputs=[loading_indicator, loading_indicator],
|
81 |
+
queue=False
|
82 |
+
).then(
|
83 |
perform_query,
|
84 |
inputs=[inp, author_inp],
|
85 |
+
outputs=[results, loading_indicator]
|
86 |
)
|
87 |
|
88 |
@gr.render(inputs=[results])
|