Spaces:
Runtime error
Runtime error
show table
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import chromadb
|
3 |
import pandas as pd
|
|
|
4 |
|
5 |
client = chromadb.Client()
|
6 |
collection = client.create_collection("bolivian-recipes")
|
@@ -13,24 +14,23 @@ collection.add(ids=ids, documents=documents, metadatas=metadatas)
|
|
13 |
|
14 |
|
15 |
with gr.Blocks() as demo:
|
16 |
-
gr.Markdown(" ##
|
17 |
-
gr.
|
18 |
-
gr.Markdown(" datasets library https://huggingface.co/docs/datasets")
|
19 |
-
|
20 |
-
dataset = gr.Textbox(label="dataset", placeholder="mstz/iris", value="mstz/iris")
|
21 |
-
config = gr.Textbox(label="config", placeholder="iris", value="iris")
|
22 |
-
split = gr.Textbox(label="split", placeholder="train", value="train")
|
23 |
-
prompt = gr.Textbox(label="prompt (str)", placeholder="How many records do I have?. Give me the median of sepal_width. Show me the first 5 rows.")
|
24 |
-
cached_responses_table = gr.DataFrame()
|
25 |
get_result_button = gr.Button("Submit")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
def get_result(dataset, config, split, prompt) -> str:
|
28 |
-
result = collection.query(query_texts=[prompt], n_results=4)
|
29 |
return {
|
30 |
-
|
31 |
}
|
32 |
|
33 |
-
get_result_button.click(get_result, inputs=
|
34 |
|
35 |
if __name__ == "__main__":
|
36 |
-
demo.launch(
|
|
|
1 |
import gradio as gr
|
2 |
import chromadb
|
3 |
import pandas as pd
|
4 |
+
import json
|
5 |
|
6 |
client = chromadb.Client()
|
7 |
collection = client.create_collection("bolivian-recipes")
|
|
|
14 |
|
15 |
|
16 |
with gr.Blocks() as demo:
|
17 |
+
gr.Markdown(" ## Chroma demo using datasets server parquet files")
|
18 |
+
query = gr.Textbox(label="query", placeholder="anticucho")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
get_result_button = gr.Button("Submit")
|
20 |
+
cached_responses_table = gr.DataFrame()
|
21 |
+
|
22 |
+
def get_result(query) -> str:
|
23 |
+
result = collection.query(query_texts=[query], n_results=2)
|
24 |
+
ids = result["ids"][0]
|
25 |
+
distances = result["distances"][0]
|
26 |
+
metadatas = [json.dumps(data) for data in result["metadatas"][0]]
|
27 |
+
documents = result["documents"][0]
|
28 |
|
|
|
|
|
29 |
return {
|
30 |
+
cached_responses_table: gr.update(value=pd.DataFrame(data={"ids": ids, "distances":distances, "metadatas": metadatas, "documents":documents})),
|
31 |
}
|
32 |
|
33 |
+
get_result_button.click(get_result, inputs=query, outputs=[cached_responses_table])
|
34 |
|
35 |
if __name__ == "__main__":
|
36 |
+
demo.launch()
|