nischaypar commited on
Commit
2a05c69
Β·
1 Parent(s): 3fc3426

update app

Browse files
Files changed (1) hide show
  1. app.py +34 -18
app.py CHANGED
@@ -1,26 +1,42 @@
1
- from smolagents import launch_gradio_demo
2
- from tool import LinkupSearchTool
3
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
- tool = LinkupSearchTool()
 
6
 
7
- # Launch original demo to extract layout
8
- demo = launch_gradio_demo(tool, return_interface=True)
 
 
 
9
 
10
- # Find the submit button and inputs
11
- submit_btn = demo.children[-1] # last element is usually the submit button
12
- input_components = demo.children[0].children # first child is the input layout
13
 
14
- # Hook: disable submit if any input is empty
15
- def check_required_fields(*args):
16
- return all(args)
17
 
18
- demo.load(
19
- check_required_fields,
20
- inputs=input_components,
21
- outputs=[submit_btn],
22
- every=0.1,
23
- queue=False,
24
- )
25
 
26
  demo.launch()
 
 
 
1
  import gradio as gr
2
+ from tool import LinkupSearchTool
3
+
4
+ tool = LinkupSearchTool() # we will pass API key at runtime only
5
+
6
+ def run_search(query, depth, api_key):
7
+ if not query or not depth or not api_key:
8
+ return "❌ All fields are required."
9
+
10
+ try:
11
+ return tool.forward(query=query, depth=depth, api_key=api_key)
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\nEnter your query and API key below.")
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"])
21
+ api_key_input = gr.Textbox(label="Linkup API Key", type="password")
22
 
23
+ output = gr.Markdown()
24
+ btn = gr.Button("Search")
25
 
26
+ btn.click(
27
+ fn=run_search,
28
+ inputs=[query_input, depth_input, api_key_input],
29
+ outputs=output
30
+ )
31
 
32
+ # Disable button unless all fields are filled
33
+ def enable_submit(q, d, k):
34
+ return bool(q and d and k)
35
 
36
+ query_input.change(enable_submit, [query_input, depth_input, api_key_input], [btn])
37
+ depth_input.change(enable_submit, [query_input, depth_input, api_key_input], [btn])
38
+ api_key_input.change(enable_submit, [query_input, depth_input, api_key_input], [btn])
39
 
40
+ btn.interactive = False # disabled by default
 
 
 
 
 
 
41
 
42
  demo.launch()