|
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() |
|
return "README.md not found." |
|
|
|
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=False) |
|
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(enable_submit, [query_input, depth_input, api_key_input], [search_btn]) |
|
depth_input.input(enable_submit, [query_input, depth_input, api_key_input], [search_btn]) |
|
api_key_input.input(enable_submit, [query_input, depth_input, api_key_input], [search_btn]) |
|
|
|
gr.Markdown("---") |
|
gr.Markdown("## π Tool Documentation") |
|
gr.Markdown(load_readme()) |
|
|
|
demo.launch() |
|
|