nischaypar's picture
update app
4e10e1e
raw
history blame
1.49 kB
import gradio as gr
from tool import LinkupSearchTool # Assuming this is your tool class
def run_search(query, depth, api_key):
if not query or not depth or not api_key:
return "❌ All fields are required."
try:
# Initialize tool ONLY when we have the API key
tool = LinkupSearchTool(linkup_api_key=api_key) # Pass API key to constructor
return tool.forward(query=query, depth=depth)
except Exception as e:
return f"❌ Error: {str(e)}"
with gr.Blocks() as demo:
gr.Markdown("## πŸ” Linkup Web Search Tool")
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"], value="standard")
api_key_input = gr.Textbox(label="Linkup API Key", type="password")
output = gr.Markdown()
btn = gr.Button("Search", interactive=True)
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.strip() and d and k.strip()))
query_input.change(enable_submit, [query_input, depth_input, api_key_input], [btn])
depth_input.change(enable_submit, [query_input, depth_input, api_key_input], [btn])
api_key_input.change(enable_submit, [query_input, depth_input, api_key_input], [btn])
demo.launch()