Spaces:
Sleeping
Sleeping
File size: 2,428 Bytes
bcba5ba b3ecc7a 98eec6c bcba5ba 98eec6c b3ecc7a 665a0db bcba5ba 665a0db bcba5ba 665a0db bcba5ba 173b4ae b3ecc7a e487181 bcba5ba 65c8976 c01de1b bcba5ba |
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
from __future__ import annotations
import gradio as gr
from tool import BrightDataDatasetTool, DATASET_CHOICES, DATASET_FIELDS
tool = BrightDataDatasetTool()
def toggle_fields(selected: str):
inputs = ["url", "keyword", "first_name", "last_name", "days_limit", "num_of_reviews", "num_of_comments"]
wanted = set(DATASET_FIELDS.get(selected, []))
def visibility(name: str):
return gr.update(visible=name in wanted)
return tuple(visibility(name) for name in inputs)
def run(dataset: str, url: str, keyword: str, first_name: str, last_name: str, days_limit: str, num_of_reviews: str, num_of_comments: str) -> str:
import sys
print(f"[DEBUG app.run] Received url: {url!r} (type: {type(url).__name__})", file=sys.stderr)
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,
)
def create_demo() -> gr.Blocks:
with gr.Blocks() as demo:
gr.Markdown("# Bright Data dataset fetch")
gr.Markdown("### [Signup here](https://brightdata.com/?utm_source=tech-partner&utm_medium=link&utm_campaign=huggingface&hs_signup=1)")
dataset = gr.Dropdown(choices=DATASET_CHOICES, label="Dataset", value=DATASET_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,
)
return demo
if __name__ == "__main__":
create_demo().launch()
|