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

update app

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -1,18 +1,19 @@
1
  import gradio as gr
2
  from tool import LinkupSearchTool
3
 
4
- tool = LinkupSearchTool()
5
-
6
  def run_search(query, depth, api_key):
 
 
 
7
  try:
8
- return tool.forward(query=query, depth=depth, api_key=api_key)
 
 
9
  except Exception as e:
10
  return f"❌ Error: {str(e)}"
11
 
12
  def check_inputs(query, depth, api_key):
13
- if query and depth and api_key:
14
- return gr.Button.update(interactive=True)
15
- return gr.Button.update(interactive=False)
16
 
17
  with gr.Blocks() as demo:
18
  gr.Markdown("## πŸ” Linkup Web Search Tool")
@@ -24,9 +25,9 @@ with gr.Blocks() as demo:
24
  output = gr.Markdown()
25
  search_btn = gr.Button("Search", interactive=False)
26
 
27
- search_btn.click(run_search, inputs=[query, depth, api_key], outputs=output)
28
 
29
- # Dynamically update button interactivity
30
  query.input(check_inputs, [query, depth, api_key], [search_btn])
31
  depth.input(check_inputs, [query, depth, api_key], [search_btn])
32
  api_key.input(check_inputs, [query, depth, api_key], [search_btn])
 
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")
 
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])