File size: 1,296 Bytes
9af61ac
2a05c69
 
 
4639906
 
 
2a05c69
4639906
 
 
2a05c69
 
 
a0d8cc7
4639906
a0d8cc7
2a05c69
a0d8cc7
2a05c69
a0d8cc7
 
 
e922dc7
2a05c69
a0d8cc7
9af61ac
4639906
3fc3426
4639906
a0d8cc7
 
 
3fc3426
e923eaa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import gradio as gr
from tool import LinkupSearchTool

def run_search(query, depth, api_key):
    if not (query and depth and api_key):
        return "❌ All fields are required."

    try:
        # Initialize the tool here, using the API key from the form
        tool = LinkupSearchTool(linkup_api_key=api_key)
        return tool.forward(query=query, depth=depth)
    except Exception as e:
        return f"❌ Error: {str(e)}"

def check_inputs(query, depth, api_key):
    return gr.Button.update(interactive=bool(query and depth and api_key))

with gr.Blocks() as demo:
    gr.Markdown("## πŸ” Linkup Web Search Tool")

    query = gr.Textbox(label="Search Query", placeholder="e.g. AI trends in 2024")
    depth = gr.Dropdown(label="Search Depth", choices=["standard", "deep"])
    api_key = gr.Textbox(label="Linkup API Key", type="password")

    output = gr.Markdown()
    search_btn = gr.Button("Search", interactive=False)

    search_btn.click(fn=run_search, inputs=[query, depth, api_key], outputs=output)

    # Live enable/disable of the search button
    query.input(check_inputs, [query, depth, api_key], [search_btn])
    depth.input(check_inputs, [query, depth, api_key], [search_btn])
    api_key.input(check_inputs, [query, depth, api_key], [search_btn])

demo.launch()