|
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: |
|
|
|
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) |
|
|
|
|
|
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() |
|
|