Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -40,6 +40,9 @@ def search_embeddings(query_text, output_option):
|
|
| 40 |
elapsed_time_meilisearch = time.time() - start_time_meilisearch
|
| 41 |
hits = response["hits"]
|
| 42 |
|
|
|
|
|
|
|
|
|
|
| 43 |
# step3: present the results in markdown
|
| 44 |
if output_option == "human-friendly":
|
| 45 |
md = f"Stats:\n\nembedding time: {elapsed_time_embedding:.2f}s\n\nmeilisearch time: {elapsed_time_meilisearch:.2f}s\n\n---\n\n"
|
|
@@ -47,20 +50,20 @@ def search_embeddings(query_text, output_option):
|
|
| 47 |
text, source_page_url, source_page_title = hit["text"], hit["source_page_url"], hit["source_page_title"]
|
| 48 |
source = f"src: [\"{source_page_title}\"]({source_page_url})"
|
| 49 |
md += text + f"\n\n{source}\n\n---\n\n"
|
| 50 |
-
return md
|
| 51 |
elif output_option == "RAG-friendly":
|
| 52 |
hit_texts = [hit["text"] for hit in hits]
|
| 53 |
hit_text_str = "\n------------\n".join(hit_texts)
|
| 54 |
-
return hit_text_str
|
| 55 |
|
| 56 |
|
| 57 |
demo = gr.Interface(
|
| 58 |
fn=search_embeddings,
|
| 59 |
inputs=[gr.Textbox(label="enter your query", placeholder="Type Markdown here...", lines=10), gr.Radio(label="Select an output option", choices=output_options, value="RAG-friendly")],
|
| 60 |
-
outputs=gr.Markdown(),
|
| 61 |
title="HF Docs Emebddings Explorer",
|
| 62 |
allow_flagging="never"
|
| 63 |
)
|
| 64 |
|
| 65 |
if __name__ == "__main__":
|
| 66 |
-
demo.launch()
|
|
|
|
| 40 |
elapsed_time_meilisearch = time.time() - start_time_meilisearch
|
| 41 |
hits = response["hits"]
|
| 42 |
|
| 43 |
+
sources_md = [f"[\"{hit['source_page_title']}\"]({hit['source_page_url']})" for hit in hits]
|
| 44 |
+
sources_md = ",".join(sources_md)
|
| 45 |
+
|
| 46 |
# step3: present the results in markdown
|
| 47 |
if output_option == "human-friendly":
|
| 48 |
md = f"Stats:\n\nembedding time: {elapsed_time_embedding:.2f}s\n\nmeilisearch time: {elapsed_time_meilisearch:.2f}s\n\n---\n\n"
|
|
|
|
| 50 |
text, source_page_url, source_page_title = hit["text"], hit["source_page_url"], hit["source_page_title"]
|
| 51 |
source = f"src: [\"{source_page_title}\"]({source_page_url})"
|
| 52 |
md += text + f"\n\n{source}\n\n---\n\n"
|
| 53 |
+
return md, sources_md
|
| 54 |
elif output_option == "RAG-friendly":
|
| 55 |
hit_texts = [hit["text"] for hit in hits]
|
| 56 |
hit_text_str = "\n------------\n".join(hit_texts)
|
| 57 |
+
return hit_text_str, sources_md
|
| 58 |
|
| 59 |
|
| 60 |
demo = gr.Interface(
|
| 61 |
fn=search_embeddings,
|
| 62 |
inputs=[gr.Textbox(label="enter your query", placeholder="Type Markdown here...", lines=10), gr.Radio(label="Select an output option", choices=output_options, value="RAG-friendly")],
|
| 63 |
+
outputs=[gr.Markdown(), gr.Markdown()],
|
| 64 |
title="HF Docs Emebddings Explorer",
|
| 65 |
allow_flagging="never"
|
| 66 |
)
|
| 67 |
|
| 68 |
if __name__ == "__main__":
|
| 69 |
+
demo.launch()
|