nischaypar commited on
Commit
92c55b6
Β·
1 Parent(s): 4639906

update app

Browse files
Files changed (1) hide show
  1. app.py +27 -23
app.py CHANGED
@@ -1,35 +1,39 @@
1
  import gradio as gr
2
- from tool import LinkupSearchTool
3
 
4
  def run_search(query, depth, api_key):
5
- if not (query and depth and api_key):
6
  return "❌ All fields are required."
7
-
8
  try:
9
- # Initialize the tool here, using the API key from the form
10
- tool = LinkupSearchTool(linkup_api_key=api_key)
11
  return tool.forward(query=query, depth=depth)
12
  except Exception as e:
13
  return f"❌ Error: {str(e)}"
14
 
15
- def check_inputs(query, depth, api_key):
16
- return gr.Button.update(interactive=bool(query and depth and api_key))
17
-
18
  with gr.Blocks() as demo:
19
  gr.Markdown("## πŸ” Linkup Web Search Tool")
20
-
21
- query = gr.Textbox(label="Search Query", placeholder="e.g. AI trends in 2024")
22
- depth = gr.Dropdown(label="Search Depth", choices=["standard", "deep"])
23
- api_key = gr.Textbox(label="Linkup API Key", type="password")
24
-
 
25
  output = gr.Markdown()
26
- search_btn = gr.Button("Search", interactive=False)
27
-
28
- search_btn.click(fn=run_search, inputs=[query, depth, api_key], outputs=output)
29
-
30
- # Live enable/disable of the search button
31
- query.input(check_inputs, [query, depth, api_key], [search_btn])
32
- depth.input(check_inputs, [query, depth, api_key], [search_btn])
33
- api_key.input(check_inputs, [query, depth, api_key], [search_btn])
34
-
35
- demo.launch()
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from tool import LinkupSearchTool # Assuming this is your tool class
3
 
4
  def run_search(query, depth, api_key):
5
+ if not query or not depth or not api_key:
6
  return "❌ All fields are required."
7
+
8
  try:
9
+ # Initialize tool ONLY when we have the API key
10
+ tool = LinkupSearchTool(linkup_api_key=api_key) # Pass API key to constructor
11
  return tool.forward(query=query, depth=depth)
12
  except Exception as e:
13
  return f"❌ Error: {str(e)}"
14
 
 
 
 
15
  with gr.Blocks() as demo:
16
  gr.Markdown("## πŸ” Linkup Web Search Tool")
17
+
18
+ with gr.Row():
19
+ query_input = gr.Textbox(label="Search Query", placeholder="e.g. AI trends in 2024")
20
+ depth_input = gr.Dropdown(label="Search Depth", choices=["standard", "deep"], value="standard")
21
+ api_key_input = gr.Textbox(label="Linkup API Key", type="password")
22
+
23
  output = gr.Markdown()
24
+ btn = gr.Button("Search", interactive=False)
25
+
26
+ btn.click(
27
+ fn=run_search,
28
+ inputs=[query_input, depth_input, api_key_input],
29
+ outputs=output
30
+ )
31
+
32
+ def enable_submit(q, d, k):
33
+ return gr.Button.update(interactive=bool(q.strip() and d and k.strip()))
34
+
35
+ query_input.change(enable_submit, [query_input, depth_input, api_key_input], [btn])
36
+ depth_input.change(enable_submit, [query_input, depth_input, api_key_input], [btn])
37
+ api_key_input.change(enable_submit, [query_input, depth_input, api_key_input], [btn])
38
+
39
+ demo.launch()