Spaces:
Sleeping
Sleeping
File size: 1,197 Bytes
9b0ab3a f7091c5 8225dde 4d7bc75 8225dde f7091c5 4f8dcc4 f7091c5 8e540e5 f7091c5 e96c4ee f7091c5 8225dde 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 30 31 32 33 34 35 36 |
from vectordb import Memory
import gradio as gr
import json
import numpy as np
class CustomEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, np.float32):
return float(obj) # Convert float32 to native float
return super().default(obj)
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, cls=CustomEncoder)
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()
|