SURIAPRAKASH1 commited on
Commit
42ecf43
·
1 Parent(s): 3a5d6a3

initial setup - part2

Browse files
Files changed (1) hide show
  1. app.py +24 -1
app.py CHANGED
@@ -1 +1,24 @@
1
- import gradio
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from typing import List, Dict
3
+ import json
4
+
5
+ def query_tool_similarity(query: str, tools_json: str, top_k: int):
6
+ """Calculates similarity between query and each tool.
7
+ Returns list of int as index for each tool in based on similarity."""
8
+ try:
9
+ tools = json.loads(tools_json)
10
+ assert isinstance(tools, list) and all(isinstance(d, dict) for d in tools)
11
+ except Exception as e:
12
+ return f"Invalid JSON for tools: {e}"
13
+ return f"{query}, {tools}, {top_k}"
14
+
15
+ with gr.Blocks() as demo:
16
+ gr.Interface(fn = query_tool_similarity,
17
+ inputs= [gr.Textbox(label="Query"),
18
+ gr.Textbox(label="Tools (List of Dicts as JSON)", lines=6, placeholder='e.g. [{"name": "foo", "desc": "bar"}]'),
19
+ gr.Number(label="Top K", precision=0)],
20
+ outputs= gr.Textbox(label="Result")
21
+ )
22
+
23
+ if __name__ == "__main__":
24
+ demo.launch()