File size: 2,613 Bytes
9af61ac
0b10ccb
d6054c0
2a05c69
 
0b10ccb
4639906
0b10ccb
2a05c69
0b10ccb
4639906
2a05c69
 
 
b17bf8d
 
0b10ccb
d6054c0
 
 
 
b17bf8d
 
 
 
 
 
 
 
d6054c0
0b10ccb
 
 
 
 
 
 
 
 
 
 
 
 
92c55b6
0b10ccb
 
d6054c0
0b10ccb
 
 
 
 
 
 
 
 
 
 
 
 
 
b17bf8d
0b10ccb
 
 
92c55b6
 
0b10ccb
 
92c55b6
0b10ccb
b17bf8d
 
 
0b10ccb
d6054c0
 
 
0b10ccb
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import gradio as gr
from tool import LinkupSearchTool
from pathlib import Path

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

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

# def enable_submit(q, d, k):
#     return gr.Button.update(interactive=bool(q.strip() and d and k.strip()))

def load_readme():
    path = Path(__file__).parent / "README.md"
    if path.exists():
        return path.read_text()

    lines = path.read_text().splitlines()
    if lines[0].strip() == "---":
        # Find the closing "---"
        end_index = next((i for i, line in enumerate(lines[1:], 1) if line.strip() == "---"), -1)
        if end_index != -1:
            lines = lines[end_index + 1:]  # Skip frontmatter
    return "\n".join(lines)

with gr.Blocks(title="Linkup Web Search Tool") as demo:
    gr.Markdown(
        """
        # πŸ” Linkup Web Search Tool
        Perform real-time web search using [Linkup API](https://linkup.so).

        🧠 Supports `standard` and `deep` query depth.  
        πŸ” Requires your personal Linkup API key.  
        πŸ’‘ Ideal for facts, trends, research, and real-time data discovery.
        """,
        elem_id="header",
    )

    with gr.Row():
        query_input = gr.Textbox(
            label="Search Query",
            placeholder="e.g. Linkup French AI Startup",
            lines=1,
        )
        depth_input = gr.Dropdown(
            label="Search Depth",
            choices=["standard", "deep"],
            value="standard",
            allow_custom_value=False,
        )
        api_key_input = gr.Textbox(
            label="Linkup API Key",
            placeholder="Paste your Linkup API key here",
            type="password",
        )

    search_btn = gr.Button("πŸ” Search", interactive=True)
    output = gr.Markdown("πŸ’¬ *Enter a query and click Search to begin.*", elem_id="output")

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

    query_input.input([query_input, depth_input, api_key_input], [search_btn])
    depth_input.input([query_input, depth_input, api_key_input], [search_btn])
    api_key_input.input([query_input, depth_input, api_key_input], [search_btn])

    gr.Markdown("---")
    gr.Markdown("## πŸ“„ Tool Documentation")
    gr.Markdown(load_readme())

demo.launch()