Commit
Β·
92c55b6
1
Parent(s):
4639906
update app
Browse files
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
|
6 |
return "β All fields are required."
|
7 |
-
|
8 |
try:
|
9 |
-
# Initialize
|
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 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
25 |
output = gr.Markdown()
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|