Add Bright Data Dataset Tool
Browse files
app.py
CHANGED
|
@@ -4,6 +4,16 @@ import importlib
|
|
| 4 |
BrightDataDatasetTool = importlib.import_module("tool").BrightDataDatasetTool
|
| 5 |
tool = BrightDataDatasetTool()
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
def run(dataset, url, keyword, first_name, last_name, days_limit, num_of_reviews, num_of_comments):
|
| 8 |
return tool(
|
| 9 |
dataset=dataset,
|
|
@@ -18,14 +28,21 @@ def run(dataset, url, keyword, first_name, last_name, days_limit, num_of_reviews
|
|
| 18 |
|
| 19 |
with gr.Blocks() as demo:
|
| 20 |
gr.Markdown("### Bright Data dataset fetch")
|
| 21 |
-
dataset = gr.Dropdown(choices=
|
| 22 |
-
url = gr.Textbox(label="URL", placeholder="https://...")
|
| 23 |
-
keyword = gr.Textbox(label="Keyword")
|
| 24 |
-
first_name = gr.Textbox(label="First name")
|
| 25 |
-
last_name = gr.Textbox(label="Last name")
|
| 26 |
-
days_limit = gr.Textbox(label="Days limit (e.g. 3)")
|
| 27 |
-
num_of_reviews = gr.Textbox(label="Number of reviews")
|
| 28 |
-
num_of_comments = gr.Textbox(label="Number of comments")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
run_btn = gr.Button("Run")
|
| 30 |
output = gr.Textbox(label="Output", lines=12)
|
| 31 |
run_btn.click(
|
|
|
|
| 4 |
BrightDataDatasetTool = importlib.import_module("tool").BrightDataDatasetTool
|
| 5 |
tool = BrightDataDatasetTool()
|
| 6 |
|
| 7 |
+
DATASET_FIELDS = {'amazon_product': ['url'], 'amazon_product_reviews': ['url'], 'amazon_product_search': ['keyword', 'url'], 'walmart_product': ['url'], 'walmart_seller': ['url'], 'ebay_product': ['url'], 'homedepot_products': ['url'], 'zara_products': ['url'], 'etsy_products': ['url'], 'bestbuy_products': ['url'], 'linkedin_person_profile': ['url'], 'linkedin_company_profile': ['url'], 'linkedin_job_listings': ['url'], 'linkedin_posts': ['url'], 'linkedin_people_search': ['url', 'first_name', 'last_name'], 'crunchbase_company': ['url'], 'zoominfo_company_profile': ['url'], 'instagram_profiles': ['url'], 'instagram_posts': ['url'], 'instagram_reels': ['url'], 'instagram_comments': ['url'], 'facebook_posts': ['url'], 'facebook_marketplace_listings': ['url'], 'facebook_company_reviews': ['url', 'num_of_reviews'], 'facebook_events': ['url'], 'tiktok_profiles': ['url'], 'tiktok_posts': ['url'], 'tiktok_shop': ['url'], 'tiktok_comments': ['url'], 'google_maps_reviews': ['url', 'days_limit'], 'google_shopping': ['url'], 'google_play_store': ['url'], 'apple_app_store': ['url'], 'reuter_news': ['url'], 'github_repository_file': ['url'], 'yahoo_finance_business': ['url'], 'x_posts': ['url'], 'zillow_properties_listing': ['url'], 'booking_hotel_listings': ['url'], 'youtube_profiles': ['url'], 'youtube_comments': ['url', 'num_of_comments'], 'reddit_posts': ['url'], 'youtube_videos': ['url']}
|
| 8 |
+
CHOICES = ['amazon_product', 'amazon_product_reviews', 'amazon_product_search', 'apple_app_store', 'bestbuy_products', 'booking_hotel_listings', 'crunchbase_company', 'ebay_product', 'etsy_products', 'facebook_company_reviews', 'facebook_events', 'facebook_marketplace_listings', 'facebook_posts', 'github_repository_file', 'google_maps_reviews', 'google_play_store', 'google_shopping', 'homedepot_products', 'instagram_comments', 'instagram_posts', 'instagram_profiles', 'instagram_reels', 'linkedin_company_profile', 'linkedin_job_listings', 'linkedin_people_search', 'linkedin_person_profile', 'linkedin_posts', 'reddit_posts', 'reuter_news', 'tiktok_comments', 'tiktok_posts', 'tiktok_profiles', 'tiktok_shop', 'walmart_product', 'walmart_seller', 'x_posts', 'yahoo_finance_business', 'youtube_comments', 'youtube_profiles', 'youtube_videos', 'zara_products', 'zillow_properties_listing', 'zoominfo_company_profile']
|
| 9 |
+
|
| 10 |
+
def toggle_fields(selected):
|
| 11 |
+
inputs = ["url", "keyword", "first_name", "last_name", "days_limit", "num_of_reviews", "num_of_comments"]
|
| 12 |
+
wanted = set(DATASET_FIELDS.get(selected, []))
|
| 13 |
+
def vis(name):
|
| 14 |
+
return gr.update(visible=name in wanted)
|
| 15 |
+
return tuple(vis(n) for n in inputs)
|
| 16 |
+
|
| 17 |
def run(dataset, url, keyword, first_name, last_name, days_limit, num_of_reviews, num_of_comments):
|
| 18 |
return tool(
|
| 19 |
dataset=dataset,
|
|
|
|
| 28 |
|
| 29 |
with gr.Blocks() as demo:
|
| 30 |
gr.Markdown("### Bright Data dataset fetch")
|
| 31 |
+
dataset = gr.Dropdown(choices=CHOICES, label="Dataset", multiselect=False, value=CHOICES[0])
|
| 32 |
+
url = gr.Textbox(label="URL", placeholder="https://...", visible=True)
|
| 33 |
+
keyword = gr.Textbox(label="Keyword", visible=False)
|
| 34 |
+
first_name = gr.Textbox(label="First name", visible=False)
|
| 35 |
+
last_name = gr.Textbox(label="Last name", visible=False)
|
| 36 |
+
days_limit = gr.Textbox(label="Days limit (e.g. 3)", visible=False)
|
| 37 |
+
num_of_reviews = gr.Textbox(label="Number of reviews", visible=False)
|
| 38 |
+
num_of_comments = gr.Textbox(label="Number of comments", visible=False)
|
| 39 |
+
|
| 40 |
+
dataset.change(
|
| 41 |
+
toggle_fields,
|
| 42 |
+
inputs=[dataset],
|
| 43 |
+
outputs=[url, keyword, first_name, last_name, days_limit, num_of_reviews, num_of_comments],
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
run_btn = gr.Button("Run")
|
| 47 |
output = gr.Textbox(label="Output", lines=12)
|
| 48 |
run_btn.click(
|
tool.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
from typing import Any, Optional
|
| 2 |
from smolagents.tools import Tool
|
| 3 |
-
import requests
|
| 4 |
-
import os
|
| 5 |
import json
|
| 6 |
import time
|
|
|
|
|
|
|
| 7 |
|
| 8 |
class BrightDataDatasetTool(Tool):
|
| 9 |
name = "brightdata_dataset_fetch"
|
|
@@ -198,16 +198,26 @@ class BrightDataDatasetTool(Tool):
|
|
| 198 |
"""
|
| 199 |
Override the default app to render a dropdown for dataset selection
|
| 200 |
instead of a long text field. Kept minimal: single-select dropdown,
|
| 201 |
-
|
| 202 |
"""
|
| 203 |
-
choices =
|
| 204 |
-
|
| 205 |
return f"""import gradio as gr
|
| 206 |
import importlib
|
| 207 |
|
| 208 |
BrightDataDatasetTool = importlib.import_module("tool").BrightDataDatasetTool
|
| 209 |
tool = BrightDataDatasetTool()
|
| 210 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
def run(dataset, url, keyword, first_name, last_name, days_limit, num_of_reviews, num_of_comments):
|
| 212 |
return tool(
|
| 213 |
dataset=dataset,
|
|
@@ -222,14 +232,21 @@ class BrightDataDatasetTool(Tool):
|
|
| 222 |
|
| 223 |
with gr.Blocks() as demo:
|
| 224 |
gr.Markdown("### Bright Data dataset fetch")
|
| 225 |
-
dataset = gr.Dropdown(choices=
|
| 226 |
-
url = gr.Textbox(label="URL", placeholder="https://...")
|
| 227 |
-
keyword = gr.Textbox(label="Keyword")
|
| 228 |
-
first_name = gr.Textbox(label="First name")
|
| 229 |
-
last_name = gr.Textbox(label="Last name")
|
| 230 |
-
days_limit = gr.Textbox(label="Days limit (e.g. 3)")
|
| 231 |
-
num_of_reviews = gr.Textbox(label="Number of reviews")
|
| 232 |
-
num_of_comments = gr.Textbox(label="Number of comments")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
run_btn = gr.Button("Run")
|
| 234 |
output = gr.Textbox(label="Output", lines=12)
|
| 235 |
run_btn.click(
|
|
|
|
| 1 |
from typing import Any, Optional
|
| 2 |
from smolagents.tools import Tool
|
|
|
|
|
|
|
| 3 |
import json
|
| 4 |
import time
|
| 5 |
+
import os
|
| 6 |
+
import requests
|
| 7 |
|
| 8 |
class BrightDataDatasetTool(Tool):
|
| 9 |
name = "brightdata_dataset_fetch"
|
|
|
|
| 198 |
"""
|
| 199 |
Override the default app to render a dropdown for dataset selection
|
| 200 |
instead of a long text field. Kept minimal: single-select dropdown,
|
| 201 |
+
and shows only relevant parameter fields for the chosen dataset.
|
| 202 |
"""
|
| 203 |
+
choices = sorted(self.datasets.keys())
|
| 204 |
+
dataset_fields = {k: v["inputs"] for k, v in self.datasets.items()}
|
| 205 |
return f"""import gradio as gr
|
| 206 |
import importlib
|
| 207 |
|
| 208 |
BrightDataDatasetTool = importlib.import_module("tool").BrightDataDatasetTool
|
| 209 |
tool = BrightDataDatasetTool()
|
| 210 |
|
| 211 |
+
DATASET_FIELDS = {dataset_fields}
|
| 212 |
+
CHOICES = {choices}
|
| 213 |
+
|
| 214 |
+
def toggle_fields(selected):
|
| 215 |
+
inputs = ["url", "keyword", "first_name", "last_name", "days_limit", "num_of_reviews", "num_of_comments"]
|
| 216 |
+
wanted = set(DATASET_FIELDS.get(selected, []))
|
| 217 |
+
def vis(name):
|
| 218 |
+
return gr.update(visible=name in wanted)
|
| 219 |
+
return tuple(vis(n) for n in inputs)
|
| 220 |
+
|
| 221 |
def run(dataset, url, keyword, first_name, last_name, days_limit, num_of_reviews, num_of_comments):
|
| 222 |
return tool(
|
| 223 |
dataset=dataset,
|
|
|
|
| 232 |
|
| 233 |
with gr.Blocks() as demo:
|
| 234 |
gr.Markdown("### Bright Data dataset fetch")
|
| 235 |
+
dataset = gr.Dropdown(choices=CHOICES, label="Dataset", multiselect=False, value=CHOICES[0])
|
| 236 |
+
url = gr.Textbox(label="URL", placeholder="https://...", visible=True)
|
| 237 |
+
keyword = gr.Textbox(label="Keyword", visible=False)
|
| 238 |
+
first_name = gr.Textbox(label="First name", visible=False)
|
| 239 |
+
last_name = gr.Textbox(label="Last name", visible=False)
|
| 240 |
+
days_limit = gr.Textbox(label="Days limit (e.g. 3)", visible=False)
|
| 241 |
+
num_of_reviews = gr.Textbox(label="Number of reviews", visible=False)
|
| 242 |
+
num_of_comments = gr.Textbox(label="Number of comments", visible=False)
|
| 243 |
+
|
| 244 |
+
dataset.change(
|
| 245 |
+
toggle_fields,
|
| 246 |
+
inputs=[dataset],
|
| 247 |
+
outputs=[url, keyword, first_name, last_name, days_limit, num_of_reviews, num_of_comments],
|
| 248 |
+
)
|
| 249 |
+
|
| 250 |
run_btn = gr.Button("Run")
|
| 251 |
output = gr.Textbox(label="Output", lines=12)
|
| 252 |
run_btn.click(
|