Spaces:
Sleeping
Sleeping
File size: 940 Bytes
9b0ab3a f7091c5 4d7bc75 f7091c5 4f8dcc4 f7091c5 e96c4ee f7091c5 4d7bc75 9b0ab3a f7091c5 f621a6c f7091c5 7a8cb87 f7091c5 9b0ab3a f7091c5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
from vectordb import Memory
import gradio as gr
import json
def process_json(json_input):
try:
input = json.loads(json_input)
memory = Memory(embedding_model="TaylorAI/bge-micro-v2")
memory.save(input['terms'], input['metadata'])
results = memory.search(input['prompt'], top_n=input['topN'])
return json.dumps(results, indent=4)
except json.JSONDecodeError:
return "Invalid JSON input."
with gr.Blocks() as demo:
gr.Markdown("## *VectorDB* based Paragraph Embedder")
input_json = gr.Textbox(label="Input", lines=10, placeholder='{"topN": 5, "prompt": "yellow", "metadata": [], "terms": ["banana", "blueberry", "apple"]}')
output_json = gr.Textbox(label="Output", lines=10, interactive=False)
process_button = gr.Button("Process")
process_button.click(process_json, inputs=input_json, outputs=output_json)
# Launch the app
demo.launch()
|