Spaces:
Runtime error
Runtime error
File size: 1,066 Bytes
bbaa137 8c76b59 a68dc87 8c76b59 08dc3c0 8c76b59 08dc3c0 a68dc87 8c76b59 a68dc87 8c76b59 d3a44b4 8c76b59 8fdb6b2 130076a 8fdb6b2 130076a 8fdb6b2 a68dc87 8c76b59 |
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
import gradio as gr
import json
import faiss_vdb as vdb
def upsert_role(roleId, data):
"""
body: { meta, content }
"""
text = json.dumps(data['content'])
meta = data['meta']
meta['id'] = roleId
cnt = vdb.upsert(text, meta)
return cnt
i_upsert = gr.Interface(fn=upsert_role, inputs=["text", "json"],
outputs="text")
# gradio_interface.launch()
def search_roles(content, size):
if size is None: size = 4
size = int(size)
text = json.dumps(content)
docs = vdb.search(text, size)
return docs
i_search = gr.Interface(
fn=search_roles,
inputs=["json", "number"],
outputs="json"
)
def embed_texts(texts):
arr = [vdb.embed_text(t)[0].tolist() for t in texts]
json_arr = json.dumps(arr)
return json_arr
i_embed = gr.Interface(
fn=embed_texts,
inputs='json',
outputs="json"
)
demo = gr.TabbedInterface([i_upsert, i_search, i_embed], [
"upsert role", "search roles", "embed text"])
if __name__ == "__main__":
demo.launch()
|