Spaces:
Running
Running
Commit
·
def34f2
1
Parent(s):
2d7464e
rthrth
Browse files
app.py
CHANGED
@@ -63,25 +63,17 @@ def perform_query(query, authors, num_results):
|
|
63 |
results = query_chroma(embeddings, authors, num_results)
|
64 |
|
65 |
if "error" in results:
|
66 |
-
return [gr.update(visible=True, value=f"Error: {results['error']}") for _ in range(max_textboxes *
|
67 |
|
68 |
updates = []
|
69 |
for res in results:
|
70 |
-
markdown_content = f"**{res['author']}, {res['book']}
|
71 |
updates.append(gr.update(visible=True, value=markdown_content))
|
72 |
-
updates.append(gr.update(visible=True, value="Flag", elem_id=f"flag-{len(updates)//2}"))
|
73 |
-
updates.append(gr.update(visible=False, value=res['id'])) # Hide the ID textbox
|
74 |
-
|
75 |
-
updates += [gr.update(visible=False)] * (3 * (max_textboxes - len(results)))
|
76 |
|
77 |
-
|
78 |
|
79 |
-
|
80 |
-
callback = gr.CSVLogger()
|
81 |
|
82 |
-
def flag_output(query, output_text, output_id):
|
83 |
-
callback.flag([query, output_text, output_id])
|
84 |
-
|
85 |
# Gradio interface
|
86 |
max_textboxes = 30
|
87 |
|
@@ -96,34 +88,18 @@ with gr.Blocks(css=".custom-markdown { border: 1px solid #ccc; padding: 10px; bo
|
|
96 |
|
97 |
components = []
|
98 |
textboxes = []
|
99 |
-
flag_buttons = []
|
100 |
-
ids = []
|
101 |
|
102 |
for _ in range(max_textboxes):
|
103 |
with gr.Column() as col:
|
104 |
text_out = gr.Markdown(visible=False, elem_classes="custom-markdown")
|
105 |
-
|
106 |
-
id_out = gr.Textbox(visible=False)
|
107 |
-
components.extend([text_out, flag_btn, id_out])
|
108 |
textboxes.append(text_out)
|
109 |
-
flag_buttons.append(flag_btn)
|
110 |
-
ids.append(id_out)
|
111 |
|
112 |
-
callback.setup([inp] + textboxes + ids, "flagged_data_points")
|
113 |
-
|
114 |
btn.click(
|
115 |
fn=perform_query,
|
116 |
inputs=[inp, author_inp, num_results_inp],
|
117 |
outputs=components
|
118 |
)
|
119 |
|
120 |
-
for i in range(0, len(components), 3):
|
121 |
-
flag_buttons[i//3].click(
|
122 |
-
fn=flag_output,
|
123 |
-
inputs=[inp, textboxes[i//3], ids[i//3]],
|
124 |
-
outputs=[],
|
125 |
-
preprocess=False
|
126 |
-
)
|
127 |
-
|
128 |
|
129 |
demo.launch()
|
|
|
63 |
results = query_chroma(embeddings, authors, num_results)
|
64 |
|
65 |
if "error" in results:
|
66 |
+
return [gr.update(visible=True, value=f"Error: {results['error']}") for _ in range(max_textboxes * 2)]
|
67 |
|
68 |
updates = []
|
69 |
for res in results:
|
70 |
+
markdown_content = f"**{res['author']}, {res['book']}**\n\n{res['text']}"
|
71 |
updates.append(gr.update(visible=True, value=markdown_content))
|
|
|
|
|
|
|
|
|
72 |
|
73 |
+
updates += [gr.update(visible=False)] * (max_textboxes - len(results))
|
74 |
|
75 |
+
return updates
|
|
|
76 |
|
|
|
|
|
|
|
77 |
# Gradio interface
|
78 |
max_textboxes = 30
|
79 |
|
|
|
88 |
|
89 |
components = []
|
90 |
textboxes = []
|
|
|
|
|
91 |
|
92 |
for _ in range(max_textboxes):
|
93 |
with gr.Column() as col:
|
94 |
text_out = gr.Markdown(visible=False, elem_classes="custom-markdown")
|
95 |
+
components.append(text_out)
|
|
|
|
|
96 |
textboxes.append(text_out)
|
|
|
|
|
97 |
|
|
|
|
|
98 |
btn.click(
|
99 |
fn=perform_query,
|
100 |
inputs=[inp, author_inp, num_results_inp],
|
101 |
outputs=components
|
102 |
)
|
103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
|
105 |
demo.launch()
|