File size: 1,402 Bytes
9af61ac
2a05c69
 
b02669d
2a05c69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e922dc7
2a05c69
b02669d
9af61ac
2a05c69
 
 
 
 
9af61ac
2a05c69
b02669d
3fc3426
2a05c69
 
 
3fc3426
b02669d
3fc3426
 
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
37
38
39
40
41
42
import gradio as gr
from tool import LinkupSearchTool

tool = LinkupSearchTool()

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

    try:
        return tool.forward(query=query, depth=depth, api_key=api_key)
    except Exception as e:
        return f"❌ Error: {str(e)}"

with gr.Blocks() as demo:
    gr.Markdown("## πŸ” Linkup Web Search Tool\nEnter your query and API key below.")

    with gr.Row():
        query_input = gr.Textbox(label="Search Query", placeholder="e.g. AI trends in 2024")
        depth_input = gr.Dropdown(label="Search Depth", choices=["standard", "deep"])
        api_key_input = gr.Textbox(label="Linkup API Key", type="password")

    output = gr.Markdown()
    btn = gr.Button("Search")  # βœ… Keep the label here

    btn.click(
        fn=run_search,
        inputs=[query_input, depth_input, api_key_input],
        outputs=output
    )

    def enable_submit(q, d, k):
        return gr.Button.update(interactive=bool(q and d and k))  # βœ… fix

    query_input.change(enable_submit, [query_input, depth_input, api_key_input], [btn])
    depth_input.change(enable_submit, [query_input, depth_input, api_key_input], [btn])
    api_key_input.change(enable_submit, [query_input, depth_input, api_key_input], [btn])

    btn.interactive = False  # Disabled by default

demo.launch()