Spaces:
Sleeping
Sleeping
Download app.py from bugrahans/google-maps-leads-scraper: direct link, hf CLI and curl.
- Browser
- Download file 22.2 kB
-
https://huggingface.co/spaces/bugrahans/google-maps-leads-scraper/resolve/main/app.py
- Command line
-
hf download hf://spaces/bugrahans/google-maps-leads-scraper/app.py
-
curl -L -o app.py https://huggingface.co/spaces/bugrahans/google-maps-leads-scraper/resolve/main/app.py
22.2 kB
| from __future__ import annotations | |
| import csv | |
| import html | |
| import tempfile | |
| from typing import Any, Dict, List, Optional, Tuple | |
| import gradio as gr | |
| from tool import SCRAPE_DO_SIGNUP_URL, SORT_OPTIONS, ScrapeDoGoogleMapsTool | |
| # ZeroGPU hardware refuses to keep a Space alive unless it finds at least one | |
| # @spaces.GPU function at startup. This app is pure HTTP and never touches a GPU, | |
| # so the probe below exists only to satisfy that check. It is never called. | |
| try: | |
| import spaces | |
| def _zerogpu_probe() -> str: | |
| return "ok" | |
| except ImportError: | |
| pass | |
| UTM = "utm_source=huggingface&utm_medium=google-maps-leads-scraper" | |
| NO_TOKEN_MD = ( | |
| "### Paste your Scrape.do API token above\n\n" | |
| f"No token yet? [Create a free account]({SCRAPE_DO_SIGNUP_URL}) — " | |
| "1,000 free credits a month, no credit card. Every call is 10 credits; one search page returns 20 places." | |
| ) | |
| SORT_LABELS = {"newest": "Newest", "most_relevant": "Most relevant", "highest_rating": "Highest rating", "lowest_rating": "Lowest rating"} | |
| PLACE_HEADERS = ["Name", "Category", "Rating", "Reviews", "Phone", "Website", "Address", "Hours", "Place ID"] | |
| # --------------------------------------------------------------------- helpers | |
| def _esc(value: Any) -> str: | |
| return html.escape("" if value is None else str(value), quote=True) | |
| def _safe_url(url: Any) -> str: | |
| url = str(url or "") | |
| return url if url.startswith("https://") else "" | |
| def _tool(token: str) -> Optional[ScrapeDoGoogleMapsTool]: | |
| token = (token or "").strip() | |
| return ScrapeDoGoogleMapsTool(api_token=token) if token else None | |
| def _write_csv(rows: List[Dict[str, Any]], prefix: str) -> Optional[str]: | |
| if not rows: | |
| return None | |
| fields: List[str] = [] | |
| for row in rows: | |
| for key in row: | |
| if key not in fields: | |
| fields.append(key) | |
| handle = tempfile.NamedTemporaryFile(mode="w", suffix=".csv", prefix=f"{prefix}-", delete=False, newline="", encoding="utf-8-sig") | |
| writer = csv.DictWriter(handle, fieldnames=fields, extrasaction="ignore") | |
| writer.writeheader() | |
| for row in rows: | |
| writer.writerow({k: (" | ".join(map(str, v)) if isinstance(v, list) else (str(v) if isinstance(v, dict) else v)) for k, v in row.items()}) | |
| handle.close() | |
| return handle.name | |
| def _error_md(data: Dict[str, Any]) -> str: | |
| out = f"**That didn't go through.**\n\n{data.get('errorMessage') or 'Unknown error'}" | |
| if data.get("hint"): | |
| out += f"\n\n{data['hint']}" | |
| return out | |
| def _stars(rating: Any) -> str: | |
| try: | |
| r = float(rating) | |
| except (TypeError, ValueError): | |
| return '<span class="gm-muted">No rating</span>' | |
| return f'<span class="gm-star">★ {r:.1f}</span>' | |
| def render_places(places: List[Dict[str, Any]]) -> str: | |
| cards = [] | |
| for p in places: | |
| site = _safe_url(p.get("website")) | |
| maps = _safe_url(p.get("maps_url")) | |
| name = _esc(p.get("name")) | |
| title = f'<a href="{_esc(maps)}" target="_blank" rel="noopener noreferrer">{name}</a>' if maps else name | |
| reviews = f' <span class="gm-muted">({p["reviews"]:,})</span>' if isinstance(p.get("reviews"), int) else "" | |
| lines = [f'<div class="gm-line gm-muted">{_esc(p.get("category"))}</div>'] | |
| if p.get("address"): | |
| lines.append(f'<div class="gm-line">{_esc(p["address"])}</div>') | |
| contact = [] | |
| if p.get("phone"): | |
| contact.append(_esc(p["phone"])) | |
| if site: | |
| short = site.split("//", 1)[-1].split("/", 1)[0] | |
| contact.append(f'<a href="{_esc(site)}" target="_blank" rel="noopener noreferrer">{_esc(short)}</a>') | |
| if contact: | |
| lines.append(f'<div class="gm-line">{" · ".join(contact)}</div>') | |
| if p.get("open_state"): | |
| lines.append(f'<div class="gm-line gm-open">{_esc(p["open_state"])}</div>') | |
| cards.append(f'<div class="gm-card"><div class="gm-card-top"><span class="gm-name">{title}</span>' | |
| f'<span>{_stars(p.get("rating"))}{reviews}</span></div>{"".join(lines)}</div>') | |
| if not cards: | |
| cards.append('<div class="gm-empty">No places came back for this search.</div>') | |
| return f'<div class="gm-wrap"><div class="gm-grid">{"".join(cards)}</div></div>' | |
| def render_place(p: Dict[str, Any]) -> str: | |
| breakdown = p.get("rating_breakdown") or {} | |
| total = sum(breakdown.values()) or 1 | |
| bars = "".join( | |
| f'<div class="gm-bar-row"><span>{s}★</span><div class="gm-bar"><div style="width:{100 * breakdown.get(s, 0) / total:.0f}%"></div></div>' | |
| f'<span class="gm-muted">{breakdown.get(s, 0):,}</span></div>' | |
| for s in ("5", "4", "3", "2", "1") if breakdown | |
| ) | |
| attrs = "".join(f'<div class="gm-attr"><b>{_esc(k.replace("_", " ").title())}</b> {_esc(", ".join(v))}</div>' | |
| for k, v in (p.get("attributes") or {}).items()) | |
| site = _safe_url(p.get("website")) | |
| rows = [ | |
| ("Category", _esc(", ".join(p.get("categories") or [])) or "—"), | |
| ("Rating", f'{_stars(p.get("rating"))} <span class="gm-muted">{p.get("reviews") or 0:,} reviews</span>'), | |
| ("Phone", _esc(p.get("phone")) or "—"), | |
| ("Website", f'<a href="{_esc(site)}" target="_blank" rel="noopener noreferrer">{_esc(site)}</a>' if site else "—"), | |
| ("Address", _esc(p.get("address")) or "—"), | |
| ("Plus code", _esc(p.get("plus_code")) or "—"), | |
| ("Coordinates", f'{p.get("latitude")}, {p.get("longitude")}' if p.get("latitude") is not None else "—"), | |
| ("Hours", _esc(p.get("hours")).replace("; ", "<br>") or "—"), | |
| ("Place ID", f'<code>{_esc(p.get("place_id"))}</code>'), | |
| ("Feature ID", f'<code>{_esc(p.get("data_id"))}</code>'), | |
| ] | |
| specs = "".join(f'<div class="gm-spec-name">{k}</div><div class="gm-spec-value">{v}</div>' for k, v in rows) | |
| maps = _safe_url(p.get("maps_url")) | |
| button = f'<a class="gm-btn" href="{_esc(maps)}" target="_blank" rel="noopener noreferrer">Open in Google Maps</a>' if maps else "" | |
| extra = f'<div class="gm-bars">{bars}</div>' if bars else "" | |
| extra += f'<div class="gm-attrs">{attrs}</div>' if attrs else "" | |
| return (f'<div class="gm-wrap"><div class="gm-profile"><div class="gm-p-name">{_esc(p.get("name"))}</div>' | |
| f'<div class="gm-specs">{specs}</div>{extra}{button}</div></div>') | |
| def render_reviews(reviews: List[Dict[str, Any]]) -> str: | |
| items = [] | |
| for r in reviews: | |
| reply = f'<div class="gm-reply"><b>Owner reply</b> {_esc(r.get("owner_reply"))}</div>' if r.get("owner_reply") else "" | |
| guide = ' <span class="gm-badge">Local Guide</span>' if r.get("local_guide") else "" | |
| items.append(f'<div class="gm-review"><div class="gm-card-top"><span class="gm-name">{_esc(r.get("author"))}{guide}</span>' | |
| f'<span>{_stars(r.get("rating"))} <span class="gm-muted">{_esc(r.get("date"))}</span></span></div>' | |
| f'<div class="gm-line">{_esc(r.get("text")) or "<span class=gm-muted>(rating only)</span>"}</div>{reply}</div>') | |
| if not items: | |
| items.append('<div class="gm-empty">No reviews came back.</div>') | |
| return f'<div class="gm-wrap">{"".join(items)}</div>' | |
| # ---------------------------------------------------------------- handlers | |
| def run_search(token: str, query: str, location: str, page: float): | |
| tool = _tool(token) | |
| empty = gr.Dataframe(value=[], headers=PLACE_HEADERS) | |
| hidden = gr.Dropdown(choices=[], value=None, visible=False) | |
| if tool is None: | |
| return NO_TOKEN_MD, "", empty, {}, None, hidden | |
| data = tool.search(query, location, int(page or 1)) | |
| if data.get("status") != "success": | |
| return _error_md(data), "", empty, data, None, hidden | |
| places = data["results"] | |
| phones = sum(1 for p in places if p.get("phone")) | |
| sites = sum(1 for p in places if p.get("website")) | |
| summary = (f"**{len(places)}** places on page {data['page']} · **{phones}** with a phone · **{sites}** with a website" | |
| f"\n\n1 request · {data['credits_used']} credits. Pick a place below to send it to the Place and Reviews tabs.") | |
| table = gr.Dataframe(value=[[p["name"], p["category"], p["rating"], p["reviews"], p["phone"], p["website"], p["address"], p["hours"], p["place_id"]] | |
| for p in places], headers=PLACE_HEADERS) | |
| choices = [(f'{p["name"]} · {p["address"]}', p["place_id"] or p["data_id"]) for p in places if p.get("place_id") or p.get("data_id")] | |
| return summary, render_places(places), table, data, _write_csv(places, "google-maps-places"), gr.Dropdown(choices=choices, value=None, visible=bool(choices)) | |
| def send_place(picked: Optional[str], p_cur: str, r_cur: str) -> Tuple[str, str, str]: | |
| if not picked: | |
| return p_cur, r_cur, "" | |
| return picked, picked, "Sent. Open the **Place** or **Reviews** tab and press the button." | |
| def run_place(token: str, ref: str): | |
| tool = _tool(token) | |
| if tool is None: | |
| return NO_TOKEN_MD, "", {}, None | |
| if not (ref or "").strip(): | |
| return "Paste a place ID or Google Maps link, or pick a place in the Search tab.", "", {}, None | |
| data = tool.place(ref) | |
| if data.get("status") != "success": | |
| return _error_md(data), "", data, None | |
| p = data["place"] | |
| return f"1 request · {data['credits_used']} credits", render_place(p), data, _write_csv([p], "google-maps-place") | |
| def run_reviews(token: str, ref: str, sort_label: str, pages: float): | |
| tool = _tool(token) | |
| if tool is None: | |
| return NO_TOKEN_MD, "", {}, None | |
| if not (ref or "").strip(): | |
| return "Paste a place ID or feature ID, or pick a place in the Search tab.", "", {}, None | |
| sort_by = next((k for k, v in SORT_LABELS.items() if v == sort_label), "newest") | |
| data = tool.reviews(ref, sort_by, int(pages or 1)) | |
| if data.get("status") != "success": | |
| return _error_md(data), "", data, None | |
| reviews = data["reviews"] | |
| replies = sum(1 for r in reviews if r.get("owner_reply")) | |
| topics = ", ".join(f'{t["keyword"]} ({t["mentions"]})' for t in data.get("topics") or [] if t.get("keyword")) | |
| summary = (f"**{len(reviews)}** reviews · **{replies}** with an owner reply" | |
| + (f"\n\nTopics: {topics}" if topics else "") + f"\n\n{data['credits_used']} credits used") | |
| return summary, render_reviews(reviews), data, _write_csv(reviews, "google-maps-reviews") | |
| # ----------------------------------------------------------------------- UI | |
| STYLE = """ | |
| <style> | |
| .gradio-container, .gradio-container button, .gradio-container input, .gradio-container textarea, .gradio-container select { | |
| font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif; } | |
| .gm-hero { position: relative; overflow: hidden; border-radius: 18px; padding: 30px 32px 28px 32px; margin-bottom: 16px; | |
| background: radial-gradient(circle at 90% 15%, rgba(26,115,232,.40) 0%, rgba(26,115,232,0) 45%), | |
| linear-gradient(135deg, #10161f 0%, #1b2430 60%, #24303e 100%); } | |
| .gm-hero, .gm-hero * { color: #ffffff !important; } | |
| .gm-hero-inner { position: relative; z-index: 1; max-width: 640px; } | |
| .gm-hero h1 { font-size: 2.05rem !important; font-weight: 800 !important; margin: 0 0 10px 0 !important; } | |
| .gm-hero h1 span { color: #8ab4f8 !important; } | |
| .gm-hero p { margin: 0 0 8px 0 !important; font-size: 1rem !important; line-height: 1.55 !important; opacity: .96; } | |
| .gm-hero a { text-decoration: underline !important; } | |
| .gm-hero a.gm-cta { display: inline-block; margin-top: 12px; padding: 11px 24px; border-radius: 10px; background: #1a73e8 !important; | |
| color: #ffffff !important; font-weight: 800 !important; text-decoration: none !important; } | |
| .gm-hero-card { position: absolute; right: 34px; top: 50%; transform: translateY(-50%); width: 270px; z-index: 1; | |
| background: #ffffff; border-radius: 14px; padding: 14px 16px; box-shadow: 0 10px 28px rgba(0,0,0,.35); } | |
| .gm-hero-card, .gm-hero-card * { color: #202124 !important; } | |
| .gm-hc-title { font-size: .72rem; font-weight: 800; color: #5f6368 !important; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 8px; } | |
| .gm-hc-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; font-size: .84rem; margin: 7px 0; } | |
| .gm-hc-row b { color: #1a73e8 !important; } | |
| @media (max-width: 900px) { .gm-hero-card { display: none; } } | |
| .gm-note { border-left: 3px solid #1a73e8; background: #eef4fe; padding: 12px 16px; border-radius: 0 10px 10px 0; font-size: .9rem; | |
| margin-bottom: 12px; color: #202124 !important; } | |
| .gradio-container .primary, .gradio-container button.primary, .gradio-container button[variant="primary"] { | |
| background: #1a73e8 !important; background-image: none !important; border-color: #1a73e8 !important; color: #ffffff !important; | |
| border-radius: 10px !important; font-weight: 800 !important; } | |
| .gradio-container .primary:hover, .gradio-container button.primary:hover { background: #1557b0 !important; } | |
| .gm-wrap { color: #202124 !important; } | |
| .gm-muted { color: #5f6368 !important; } | |
| .gm-empty { background: #ffffff; border: 1px solid #e8eaed; border-radius: 12px; padding: 20px; color: #5f6368 !important; } | |
| .gm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(290px, 100%), 1fr)); gap: 12px; } | |
| .gm-card, .gm-review { background: #ffffff; border: 1px solid #e8eaed; border-radius: 14px; padding: 12px 14px; } | |
| .gm-review { margin-bottom: 10px; } | |
| .gm-card:hover { box-shadow: 0 3px 12px rgba(32,33,36,.10); } | |
| .gm-card-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; } | |
| .gm-name, .gm-name a { font-weight: 800; color: #202124 !important; text-decoration: none !important; } | |
| .gm-name a:hover, .gm-line a { color: #1a73e8 !important; } | |
| .gm-star { color: #b06000 !important; font-weight: 800; white-space: nowrap; } | |
| .gm-line { font-size: .84rem; margin-top: 4px; color: #202124 !important; } | |
| .gm-open { color: #188038 !important; } | |
| .gm-badge { background: #e8f0fe; color: #1a73e8 !important; font-size: .7rem; border-radius: 6px; padding: 1px 6px; font-weight: 700; } | |
| .gm-reply { margin-top: 8px; padding: 8px 10px; background: #f8f9fa; border-radius: 8px; font-size: .82rem; color: #202124 !important; } | |
| .gm-profile { background: #ffffff; border: 1px solid #e8eaed; border-radius: 16px; padding: 18px 22px; } | |
| .gm-p-name { font-size: 1.4rem; font-weight: 800; color: #202124 !important; } | |
| .gm-specs { display: grid; grid-template-columns: minmax(120px, .3fr) 1fr; border-top: 1px solid #ececec; margin-top: 12px; } | |
| .gm-spec-name, .gm-spec-value { padding: 8px 10px; border-bottom: 1px solid #ececec; font-size: .86rem; } | |
| .gm-spec-name { color: #5f6368 !important; } | |
| .gm-spec-value, .gm-spec-value a { color: #202124 !important; } | |
| .gm-bars { margin-top: 14px; max-width: 360px; } | |
| .gm-bar-row { display: grid; grid-template-columns: 28px 1fr 50px; gap: 8px; align-items: center; font-size: .8rem; margin: 3px 0; color: #202124 !important; } | |
| .gm-bar { background: #e8eaed; border-radius: 4px; height: 8px; overflow: hidden; } | |
| .gm-bar div { background: #fbbc04; height: 8px; } | |
| .gm-attrs { margin-top: 12px; font-size: .82rem; } | |
| .gm-attr { margin: 3px 0; color: #202124 !important; } | |
| .gm-btn { display: inline-block; margin-top: 14px; padding: 10px 22px; border-radius: 10px; background: #1a73e8 !important; | |
| color: #ffffff !important; font-weight: 800; text-decoration: none !important; font-size: .9rem; } | |
| footer { display: none !important; } | |
| </style> | |
| """ | |
| HERO = f""" | |
| <div class="gm-hero"> | |
| <div class="gm-hero-inner"> | |
| <h1>Google Maps <span>Leads</span> Scraper</h1> | |
| <p><strong>Search a category around any point and get every business as a lead.</strong> Name, phone, website, | |
| address, rating, review count, hours and coordinates, then full place details and reviews with owner replies.</p> | |
| <p>Google Maps has no data in its HTML and answers scripts with consent walls and CAPTCHAs. This Space uses the | |
| <a href="https://scrape.do/?{UTM}" target="_blank" rel="noopener noreferrer">Scrape.do</a> Google Maps API, which returns parsed JSON.</p> | |
| <a class="gm-cta" href="{SCRAPE_DO_SIGNUP_URL}" target="_blank" rel="noopener noreferrer">Get a free API token →</a> | |
| </div> | |
| <div class="gm-hero-card" aria-hidden="true"> | |
| <div class="gm-hc-title">One query · 6 pages · 60 credits</div> | |
| <div class="gm-hc-row"><span>Places</span><span><b>104</b></span></div> | |
| <div class="gm-hc-row"><span>With a phone</span><span><b>77</b></span></div> | |
| <div class="gm-hc-row"><span>With a website</span><span><b>96</b></span></div> | |
| </div> | |
| </div> | |
| """ | |
| CREDIT_NOTE = """ | |
| <div class="gm-note"> | |
| Every call is 10 Scrape.do credits: a search page returns 20 places, a place lookup is one place, a reviews page is about 10 reviews. | |
| One query stops at about 120 places (6 pages); to cover a whole city, search again around other points. | |
| Reviews carry the names of the people who wrote them: store only what you need and follow the privacy rules that apply to you. | |
| </div> | |
| """ | |
| FOOTER_MD = f""" | |
| --- | |
| ### Use it as a smolagents Tool | |
| ```python | |
| from smolagents import CodeAgent, InferenceClientModel | |
| from tool import ScrapeDoGoogleMapsTool | |
| agent = CodeAgent( | |
| tools=[ScrapeDoGoogleMapsTool(api_token="YOUR_SCRAPEDO_TOKEN")], | |
| model=InferenceClientModel(), | |
| ) | |
| agent.run("Find dentists around 30.2672,-97.7431 on Google Maps and list the ones without a website.") | |
| ``` | |
| Or set `SCRAPE_DO_API_TOKEN` in the environment and instantiate with no arguments. | |
| Prefer plain Python? `pip install google-maps-leads-scraper` ([GitHub](https://github.com/bugrahansss/google-maps-leads-scraper)) · | |
| No-code: [Apify actor](https://apify.com/scrapedo/google-maps-leads-scraper) · | |
| Guide: [Google Maps Scraper: How to Scrape Google Maps for Leads](https://scrape.do/blog/google-maps-scraping/?{UTM}) | |
| [Scrape.do](https://scrape.do/?{UTM}) · [Documentation](https://scrape.do/documentation/) · [Sign up free]({SCRAPE_DO_SIGNUP_URL}) | |
| """ | |
| def build_demo() -> gr.Blocks: | |
| with gr.Blocks(title="Google Maps Leads Scraper — Scrape.do") as demo: | |
| gr.HTML(STYLE) | |
| gr.HTML(HERO) | |
| api_token = gr.Textbox(label="Scrape.do API token", placeholder="Paste your token here", type="password", | |
| info="Free tier: 1,000 credits a month. 10 credits per call.") | |
| gr.HTML(CREDIT_NOTE) | |
| with gr.Tabs(): | |
| with gr.Tab("Search"): | |
| with gr.Row(): | |
| query = gr.Textbox(label="What to search", value="coffee shop", scale=3, | |
| info="As you would type it into Google Maps. You can add a place: 'dentist in Denver, CO'.") | |
| location = gr.Textbox(label="Around (lat,lng)", value="30.2672,-97.7431", scale=2, | |
| info="Optional. Leave empty to use the place in the query.") | |
| page = gr.Number(label="Page (1-6)", value=1, minimum=1, maximum=6, precision=0, scale=1) | |
| search_btn = gr.Button("Search Google Maps", variant="primary") | |
| search_summary = gr.Markdown() | |
| search_view = gr.HTML() | |
| search_table = gr.Dataframe(headers=PLACE_HEADERS, wrap=True, label="Places") | |
| search_csv = gr.File(label="Download leads as CSV") | |
| pick = gr.Dropdown(label="Send a place to the Place and Reviews tabs", choices=[], value=None, visible=False) | |
| pick_note = gr.Markdown() | |
| with gr.Accordion("Raw JSON response", open=False): | |
| search_json = gr.JSON() | |
| with gr.Tab("Place"): | |
| place_ref = gr.Textbox(label="Place ID, CID, feature ID or Google Maps link", value="", | |
| placeholder="ChIJ... or https://www.google.com/maps/place/...", | |
| info="Pick a place in the Search tab, or paste one.") | |
| place_btn = gr.Button("Get place details", variant="primary") | |
| place_summary = gr.Markdown() | |
| place_view = gr.HTML() | |
| place_csv = gr.File(label="Download as CSV") | |
| with gr.Accordion("Raw JSON response", open=False): | |
| place_json = gr.JSON() | |
| with gr.Tab("Reviews"): | |
| with gr.Row(): | |
| review_ref = gr.Textbox(label="Place ID or feature ID", value="", scale=3, placeholder="ChIJ... or 0x...:0x...") | |
| sort = gr.Dropdown(choices=[SORT_LABELS[s] for s in SORT_OPTIONS], value="Newest", label="Order", scale=1) | |
| rpages = gr.Number(label="Pages (about 10 each)", value=1, minimum=1, maximum=5, precision=0, scale=1) | |
| reviews_btn = gr.Button("Get reviews", variant="primary") | |
| reviews_summary = gr.Markdown() | |
| reviews_view = gr.HTML() | |
| reviews_csv = gr.File(label="Download reviews as CSV") | |
| with gr.Accordion("Raw JSON response", open=False): | |
| reviews_json = gr.JSON() | |
| s_in = [api_token, query, location, page] | |
| s_out = [search_summary, search_view, search_table, search_json, search_csv, pick] | |
| search_btn.click(fn=run_search, inputs=s_in, outputs=s_out) | |
| query.submit(fn=run_search, inputs=s_in, outputs=s_out) | |
| pick.change(fn=send_place, inputs=[pick, place_ref, review_ref], outputs=[place_ref, review_ref, pick_note]) | |
| p_out = [place_summary, place_view, place_json, place_csv] | |
| place_btn.click(fn=run_place, inputs=[api_token, place_ref], outputs=p_out) | |
| place_ref.submit(fn=run_place, inputs=[api_token, place_ref], outputs=p_out) | |
| r_out = [reviews_summary, reviews_view, reviews_json, reviews_csv] | |
| reviews_btn.click(fn=run_reviews, inputs=[api_token, review_ref, sort, rpages], outputs=r_out) | |
| gr.Markdown(FOOTER_MD) | |
| return demo | |
| # Hugging Face Spaces launches the module-level `demo` object rather than | |
| # calling launch() itself, so build it at import time. | |
| demo = build_demo() | |
| if __name__ == "__main__": | |
| demo.queue(default_concurrency_limit=4).launch(ssr_mode=False) | |