|
import gradio as gr |
|
from tool import LinkupSearchTool |
|
|
|
tool = LinkupSearchTool() |
|
|
|
def run_search(query, depth, api_key): |
|
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", placeholder="Required") |
|
|
|
output = gr.Markdown() |
|
btn = gr.Button("Search", interactive=False) |
|
|
|
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)) |
|
|
|
|
|
query_input.input(enable_submit, [query_input, depth_input, api_key_input], [btn]) |
|
depth_input.input(enable_submit, [query_input, depth_input, api_key_input], [btn]) |
|
api_key_input.input(enable_submit, [query_input, depth_input, api_key_input], [btn]) |
|
|
|
demo.launch() |
|
|