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: # Initialize the tool here, using the API key from the form 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) # Live enable/disable of the search button 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()