File size: 1,181 Bytes
9af61ac 2a05c69 b02669d 2a05c69 a0d8cc7 2a05c69 a0d8cc7 2a05c69 a0d8cc7 e922dc7 2a05c69 a0d8cc7 9af61ac a0d8cc7 3fc3426 a0d8cc7 3fc3426 e923eaa |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
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()
|