Commit
Β·
4639906
1
Parent(s):
a0d8cc7
update app
Browse files
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 |
-
|
|
|
|
|
9 |
except Exception as e:
|
10 |
return f"β Error: {str(e)}"
|
11 |
|
12 |
def check_inputs(query, depth, api_key):
|
13 |
-
|
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 |
-
#
|
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])
|