{"id":21130402,"url":"https://github.com/serpapi/google-local-results-ai-server","last_synced_at":"2025-07-09T01:33:27.385Z","repository":{"id":175299784,"uuid":"652859317","full_name":"serpapi/google-local-results-ai-server","owner":"serpapi","description":"A server code for serving BERT-based models for text classification. It is designed by SerpApi for heavy-load prototyping and production tasks, specifically for the implementation of the google-local-results-ai-parser gem.","archived":false,"fork":false,"pushed_at":"2024-04-17T06:16:15.000Z","size":159,"stargazers_count":14,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-30T09:15:16.037Z","etag":null,"topics":["ai","bert","bert-classification","bert-model","model","nlp-machine-learning","production-ready","prototyping","pytorch","server"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/serpapi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-06-13T00:09:11.000Z","updated_at":"2025-03-31T01:48:30.000Z","dependencies_parsed_at":"2024-02-05T21:51:37.731Z","dependency_job_id":null,"html_url":"https://github.com/serpapi/google-local-results-ai-server","commit_stats":null,"previous_names":["serpapi/google-local-results-ai-server"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/serpapi/google-local-results-ai-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serpapi%2Fgoogle-local-results-ai-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serpapi%2Fgoogle-local-results-ai-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serpapi%2Fgoogle-local-results-ai-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serpapi%2Fgoogle-local-results-ai-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serpapi","download_url":"https://codeload.github.com/serpapi/google-local-results-ai-server/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serpapi%2Fgoogle-local-results-ai-server/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264375560,"owners_count":23598398,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","bert","bert-classification","bert-model","model","nlp-machine-learning","production-ready","prototyping","pytorch","server"],"created_at":"2024-11-20T05:33:01.086Z","updated_at":"2025-07-09T01:33:27.128Z","avatar_url":"https://github.com/serpapi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eGoogle Local Results AI Server\u003c/h1\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n  \u003ca href=\"\"\u003e[![Contributors][contributors-shield]][contributors-url] \u003c/a\u003e\n  \u003ca href=\"\"\u003e[![Forks][forks-shield]][forks-url]\u003c/a\u003e\n  \u003ca href=\"\"\u003e[![Stargazers][stars-shield]][stars-url]\u003c/a\u003e\n  \u003ca href=\"\"\u003e[![Issues][issues-shield]][issues-url]\u003c/a\u003e\n  \u003ca href=\"\"\u003e[![Issues][issuesclosed-shield]][issuesclosed-url]\u003c/a\u003e\n  \u003ca href=\"\"\u003e[![MIT License][license-shield]][license-url]\u003c/a\u003e\n \n\u003c/div\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/73674035/247621175-3b738b9c-499e-43c9-a45a-49a9a1f2f7c8.png\" alt=\"AI Model Server\" width=\"50%\"/\u003e\n\u003c/p\u003e\n\nThis repository contains the code for a server that mimics the Inference API endpoints at Huggingface for BERT-based classification models. The server provides a simple interface to perform text classification using BERT models. It is designed by [SerpApi](https://serpapi.com/) for the heavy-load prototyping, and production tasks for the implementation of [`google-local-results-ai-parser` gem](https://github.com/serpapi/google-local-results-ai-parser) which uses [`serpapi/bert-base-local-results` model](https://huggingface.co/serpapi/bert-base-local-results).\n\n\n\u003cdiv align=\"center\"\u003e\u003cb\u003eRelevant Sources\u003c/b\u003e\u003c/div\u003e\n\n- [**Real World Example of AI Powered Parsing**](https://serpapi.com/blog/real-world-example-of-ai-powered-parsing/): A Blog Post Explaining How Everything Works.\n- [**Google Local Results AI Parser**](https://github.com/serpapi/google-local-results-ai-parser): Ruby Gem for extracting structured data from Google Local Search Results using the `serpapi/bert-base-local-results` transformer model\n- [**BERT-Based Classification Model for Google Local Listings**](https://huggingface.co/serpapi/bert-base-local-results): BERT-based classification model developed using the Hugging Face library, and a dataset gathered by SerpApi's Google Local API.\n- [**BERT**](https://huggingface.co/docs/transformers/model_doc/bert): A language representation model called BERT, which stands for Bidirectional Encoder Representations from Transformers.\n- [**SerpApi's Google Local Results API Documentation**](https://serpapi.com/google-local-api): A documentation on SerpApi's Scraper API for Google Local Search Results. The model within the repository has been created using this tool.\n---\n\u003ch2 align=\"center\"\u003eInstallation\u003c/h2\u003e\n\nTo set up and run the Google Local Results AI Server locally, follow these steps:\n- **Clone the repository**:\n```bash\ncd google-local-results-ai-server\ngit clone git clone https://huggingface.co/serpapi/bert-base-local-results ./google/bert-base-local-results\n```\n\n- **Create and activate a virtual environment (optional but recommended)**:\n```bash\npython3 -m venv env\nsource env/bin/activate\n```\n\n- **Install the dependencies**:\n```bash\npip install -r requirements.txt\n```\n\n- **Set the necessary environment variables at `main.py`:**\n```py\n# Master key to keep track of access\nMASTER_KEY = \"master_key\"\n```\n\n- **Clone the contents of the [Huggingface Repository](https://huggingface.co/serpapi/bert-base-local-results) to `google/bert-base-local-results` folder.**\n```bash\n# Make sure you have git-lfs installed (https://git-lfs.com)\ngit lfs install\ngit lfs pull\ngit clone https://huggingface.co/serpapi/bert-base-local-results google/bert-base-local-results\n```\n\n- **Start the server using gunicorn:**\n```bash\ngunicorn main:app --workers 4 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0\n```\n\nYou may set the number of workers depending on your system allowace. The server will start running on `http://localhost:8000`.\n\n---\n\n\u003ch2 align=\"center\"\u003eDocker Deployment\u003c/h2\u003e\n\nAlternatively, you can deploy the Google Local Results AI Server using Docker. The repository already contains a Dockerfile for easy deployment.\n\nA Docker Image will be created and published in the repository.\n\nTo build the image, and deploy the server with Docker locally, follow these steps:\n- **Set the necessary environment variables at `main.py`:**\n```py\n# Master key to keep track of access\nMASTER_KEY = \"master_key\"\n```\n\n- **Build the Docker image**:\n```bash\ndocker build -t google-local-results-ai-server .\n```\n\n- **Optional: Change the number of workers depending on your system allowance in `Dockerfile`. Here's an example with 2 workers:\n  - `CMD [\"gunicorn\", \"main:app\", \"--workers\", \"2\", \"--worker-class\", \"uvicorn.workers.UvicornWorker\", \"--bind\", \"0.0.0.0\"]`\n\n- **Run the Docker container**:\n```bash\ndocker run -p 8000:8000 google-local-results-ai-server\n```\n\nThe server will start running on `http://localhost:8000`.\n\n---\n\u003ch2 align=\"center\"\u003eUsage\u003c/h2\u003e\n\nThe server exposes an HTTP API endpoint that accepts POST requests for classification. You can send requests to the API endpoint using various programming languages and tools. The following examples demonstrate how to make requests using Ruby, Python, JavaScript, and cURL.\n\n\u003ch3 align=\"center\"\u003eRuby Example\u003c/h3\u003e\n\n```ruby\nrequire 'http'\n\nurl = \"http://127.0.0.1:8000/models/serpapi/bert-base-local-results\"\nheaders = { \"Authorization\" =\u003e \"Bearer XXXXXX\" }\npayload = { \"inputs\" =\u003e \"5540 N Lamar Blvd #12 Austin, TX 78756\" }\n\nresponse = HTTP.headers(headers).post(url, json: payload)\noutput = response.parse\n```\n\n\u003ch3 align=\"center\"\u003ePython Example\u003c/h3\u003e\n\n```py\nimport requests\n\nAPI_URL = \"http://127.0.0.1:8000/models/serpapi/bert-base-local-results\"\nheaders = {\"Authorization\": \"Bearer XXXXXX\"}\n\ndef query(payload):\n    response = requests.post(API_URL, headers=headers, json=payload)\n    return response.json()\n\noutput = query({\n    \"inputs\": \"5540 N Lamar Blvd #12 Austin, TX 78756\",\n})\n```\n\n\u003ch3 align=\"center\"\u003eJavaScript Example\u003c/h3\u003e\n\n```js\nasync function query(data) {\n    const response = await fetch(\n        \"http://127.0.0.1:8000/models/serpapi/bert-base-local-results\",\n        {\n            headers: { Authorization: \"Bearer XXXXXX\" },\n            method: \"POST\",\n            body: JSON.stringify(data),\n        }\n    );\n    const result = await response.json();\n    return result;\n}\n\nquery({\"inputs\": \"5540 N Lamar Blvd #12 Austin, TX 78756\"}).then((response) =\u003e {\n    console.log(JSON.stringify(response));\n});\n```\n\n\u003ch3 align=\"center\"\u003ecURL Example\u003c/h3\u003e\n\n```curl\ncurl http://127.0.0.1:8000/models/serpapi/bert-base-local-results \\\n    -X POST \\\n    -d '{\"inputs\": \"5540 N Lamar Blvd #12 Austin, TX 78756\"}' \\\n    -H \"Authorization: Bearer XXXXXX\"\n```\n\n\u003ch3 align=\"center\"\u003eExample JSON Output\u003c/h3\u003e\n\n```json\n[\n  [\n    {\n      \"label\": \"address\",\n      \"score\": 0.9988067150115967\n    },\n    {\n      \"label\": \"type\",\n      \"score\": 0.0010613144841045141\n    },\n    {\n      \"label\": \"description\",\n      \"score\": 0.00021563934569712728\n    },\n    {\n      \"label\": \"hours\",\n      \"score\": 0.0002154999820049852\n    },\n    {\n      \"label\": \"phone\",\n      \"score\": 0.00018228559929411858\n    },\n    {\n      \"label\": \"reviews\",\n      \"score\": 0.00007934834866318852\n    },\n    {\n      \"label\": \"service options\",\n      \"score\": 0.0000681085730320774\n    },\n    {\n      \"label\": \"price\",\n      \"score\": 0.00001069890731741907\n    },\n    {\n      \"label\": \"years in business\",\n      \"score\": 0.000007037287559796823\n    },\n    {\n      \"label\": \"button text\",\n      \"score\": 0.000006214133918547304\n    },\n    {\n      \"label\": \"rating\",\n      \"score\": 0.000004599460226017982\n    }\n  ]\n]\n```\n---\n\u003ch2 align=\"center\"\u003eAdvanced Usage\u003c/h2\u003e\n\nThe server code provided in this repository supports advanced usage, allowing you to extend the models served by adding more BERT-based classification models. However, please note that the existing models are hardcoded with their paths in the code. The current model, `google/bert-base-local-results`, is located at `./google/bert-base-local-results`.\n\nTo add more models, follow these steps:\n\n- Prepare the BERT-based classification model and save it in a directory.\n- Update the models dictionary in the code to include the new model name and its corresponding directory path.\n```py\nmodels = {\n    \"serpapi/bert-base-local-results\": \"./google/bert-base-local-results\",\n    \"new-repository/new-model\": \"new-model-folder-path\"\n}\n```\n- Restart the server.\n\nThe server will automatically load the new models at startup, and you can access them using the appropriate API endpoints.\n\nPlease note that you need to ensure the model directory contains the necessary files for the BERT-based classification model, such as the model weights, configuration, and tokenizer.\n\n\n[contributors-shield]: https://img.shields.io/github/contributors/serpapi/google-local-results-ai-server.svg\n[contributors-url]: https://github.com/serpapi/google-local-results-ai-server/graphs/contributors\n[forks-shield]: https://img.shields.io/github/forks/serpapi/google-local-results-ai-server.svg\n[forks-url]: https://github.com/serpapi/google-local-results-ai-server/network/members\n[stars-shield]: https://img.shields.io/github/stars/serpapi/google-local-results-ai-server.svg\n[stars-url]: https://github.com/serpapi/google-local-results-ai-server/stargazers\n[issues-shield]: https://img.shields.io/github/issues/serpapi/google-local-results-ai-server.svg\n[issues-url]: https://github.com/serpapi/google-local-results-ai-server/issues\n[issuesclosed-shield]: https://img.shields.io/github/issues-closed/serpapi/google-local-results-ai-server.svg\n[issuesclosed-url]: https://github.com/serpapi/google-local-results-ai-server/issues?q=is%3Aissue+is%3Aclosed\n[board-shield]: https://img.shields.io/badge/Kanban-Board-grey?logo=data:image/svg%2bxml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgMjQgMjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEzLjM1MiAxNC41ODVsLTQuNTA5IDQuNjE0LjcyLTQuMDYyTDMuNDI4IDcuNTcgMCA3Ljc1MyA3LjU4IDB2Mi45NTNsNy4yMTQgNi42NDYgNC41MTMtMS4xMDUtNC42ODkgNC45ODJMMjQgMjRsLTEwLjY0OC05LjQxNXoiLz48L3N2Zz4=\n[board-url]: https://github.com/serpapi/google-local-results-ai-server/projects/1\n[license-shield]: https://img.shields.io/github/license/serpapi/google-local-results-ai-server.svg\n[license-url]: https://github.com/serpapi/google-local-results-ai-server/blob/master/LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserpapi%2Fgoogle-local-results-ai-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserpapi%2Fgoogle-local-results-ai-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserpapi%2Fgoogle-local-results-ai-server/lists"}