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)}" def check_inputs(query, depth, api_key): if query and depth and api_key: return gr.Button.update(interactive=True) return gr.Button.update(interactive=False) 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(run_search, inputs=[query, depth, api_key], outputs=output) # Dynamically update button interactivity 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()