Commit
Β·
2a05c69
1
Parent(s):
3fc3426
update app
Browse files
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 |
-
|
|
|
6 |
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
9 |
|
10 |
-
#
|
11 |
-
|
12 |
-
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
|
18 |
-
|
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()
|