BrightData commited on
Commit
d624fb3
·
verified ·
1 Parent(s): 8bb17bf

Add Bright Data Search Tool

Browse files
Files changed (2) hide show
  1. app.py +16 -3
  2. tool.py +26 -0
app.py CHANGED
@@ -1,5 +1,18 @@
1
- from smolagents import launch_gradio_demo
2
- from tool import BrightDataSearchTool
3
 
 
4
  tool = BrightDataSearchTool()
5
- launch_gradio_demo(tool)
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import importlib
3
 
4
+ BrightDataSearchTool = importlib.import_module("tool").BrightDataSearchTool
5
  tool = BrightDataSearchTool()
6
+
7
+ def run(query, engine):
8
+ return tool(query=query, engine=engine)
9
+
10
+ with gr.Blocks() as demo:
11
+ gr.Markdown("### Bright Data search")
12
+ query = gr.Textbox(label="Query")
13
+ engine = gr.Dropdown(choices=['google', 'bing', 'yandex'], label="Engine", value="google")
14
+ run_btn = gr.Button("Run")
15
+ output = gr.Textbox(label="Output", lines=12)
16
+ run_btn.click(run, inputs=[query, engine], outputs=output)
17
+
18
+ demo.launch()
tool.py CHANGED
@@ -94,3 +94,29 @@ class BrightDataSearchTool(Tool):
94
 
95
  except requests.exceptions.RequestException as e:
96
  return json.dumps({"error": str(e)})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
 
95
  except requests.exceptions.RequestException as e:
96
  return json.dumps({"error": str(e)})
97
+
98
+ def _get_gradio_app_code(self, tool_module_name: str = "tool") -> str:
99
+ """
100
+ Custom Gradio UI: dropdown for engine, textbox for query.
101
+ Uses importlib to avoid adding a fake 'tool' requirement.
102
+ """
103
+ choices = ["google", "bing", "yandex"]
104
+ return f"""import gradio as gr
105
+ import importlib
106
+
107
+ BrightDataSearchTool = importlib.import_module("tool").BrightDataSearchTool
108
+ tool = BrightDataSearchTool()
109
+
110
+ def run(query, engine):
111
+ return tool(query=query, engine=engine)
112
+
113
+ with gr.Blocks() as demo:
114
+ gr.Markdown("### Bright Data search")
115
+ query = gr.Textbox(label="Query")
116
+ engine = gr.Dropdown(choices={choices}, label="Engine", value="google")
117
+ run_btn = gr.Button("Run")
118
+ output = gr.Textbox(label="Output", lines=12)
119
+ run_btn.click(run, inputs=[query, engine], outputs=output)
120
+
121
+ demo.launch()
122
+ """