Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import importlib | |
| BrightDataDatasetTool = importlib.import_module("tool").BrightDataDatasetTool | |
| tool = BrightDataDatasetTool() | |
| 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']} | |
| 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'] | |
| def toggle_fields(selected): | |
| inputs = ["url", "keyword", "first_name", "last_name", "days_limit", "num_of_reviews", "num_of_comments"] | |
| wanted = set(DATASET_FIELDS.get(selected, [])) | |
| def vis(name): | |
| return gr.update(visible=name in wanted) | |
| return tuple(vis(n) for n in inputs) | |
| def run(dataset, url, keyword, first_name, last_name, days_limit, num_of_reviews, num_of_comments): | |
| return tool( | |
| dataset=dataset, | |
| url=url, | |
| keyword=keyword, | |
| first_name=first_name, | |
| last_name=last_name, | |
| days_limit=days_limit, | |
| num_of_reviews=num_of_reviews, | |
| num_of_comments=num_of_comments, | |
| ) | |
| with gr.Blocks() as demo: | |
| gr.Markdown("### Bright Data dataset fetch") | |
| dataset = gr.Dropdown(choices=CHOICES, label="Dataset", multiselect=False, value=CHOICES[0]) | |
| url = gr.Textbox(label="URL", placeholder="https://...", visible=True) | |
| keyword = gr.Textbox(label="Keyword", visible=False) | |
| first_name = gr.Textbox(label="First name", visible=False) | |
| last_name = gr.Textbox(label="Last name", visible=False) | |
| days_limit = gr.Textbox(label="Days limit (e.g. 3)", visible=False) | |
| num_of_reviews = gr.Textbox(label="Number of reviews", visible=False) | |
| num_of_comments = gr.Textbox(label="Number of comments", visible=False) | |
| dataset.change( | |
| toggle_fields, | |
| inputs=[dataset], | |
| outputs=[url, keyword, first_name, last_name, days_limit, num_of_reviews, num_of_comments], | |
| ) | |
| run_btn = gr.Button("Run") | |
| output = gr.Textbox(label="Output", lines=12) | |
| run_btn.click( | |
| run, | |
| inputs=[dataset, url, keyword, first_name, last_name, days_limit, num_of_reviews, num_of_comments], | |
| outputs=output, | |
| ) | |
| demo.launch() | |