{"id":16507940,"url":"https://github.com/noahgift/gcp-hello-ml","last_synced_at":"2025-08-31T17:42:25.915Z","repository":{"id":54798737,"uuid":"189298610","full_name":"noahgift/gcp-hello-ml","owner":"noahgift","description":null,"archived":false,"fork":false,"pushed_at":"2023-05-01T20:34:20.000Z","size":63,"stargazers_count":12,"open_issues_count":2,"forks_count":19,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-02T06:01:04.681Z","etag":null,"topics":["ai","cloudshell","flask","gcp","ml","pandas","pragmaticai"],"latest_commit_sha":null,"homepage":null,"language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/noahgift.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-29T21:09:13.000Z","updated_at":"2024-03-25T15:44:12.000Z","dependencies_parsed_at":"2022-08-14T03:10:46.831Z","dependency_job_id":null,"html_url":"https://github.com/noahgift/gcp-hello-ml","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noahgift%2Fgcp-hello-ml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noahgift%2Fgcp-hello-ml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noahgift%2Fgcp-hello-ml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noahgift%2Fgcp-hello-ml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/noahgift","download_url":"https://codeload.github.com/noahgift/gcp-hello-ml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219860253,"owners_count":16556021,"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","cloudshell","flask","gcp","ml","pandas","pragmaticai"],"created_at":"2024-10-11T15:31:57.879Z","updated_at":"2024-10-11T15:31:59.563Z","avatar_url":"https://github.com/noahgift.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gcp-hello-ml\n\nmore stuff\n\n## Hello World.\n\n1. Create Project\n\n![create project](https://user-images.githubusercontent.com/58792/58592055-8430da00-821c-11e9-976e-f9c832532a08.png)\n\n2.  Activate cloud shell \n\n3.  Refer to [hello world docs for python3 app engine](https://cloud.google.com/appengine/docs/standard/python3/quickstart)\n\n4.  Run describe\n\nverify project is working\n```bash\ngcloud projects describe $GOOGLE_CLOUD_PROJECT\n```\noutput of command:\n```bash\ncreateTime: '2019-05-29T21:21:10.187Z'\nlifecycleState: ACTIVE\nname: helloml\nprojectId: helloml-xxxxx\nprojectNumber: '881692383648'\n```\n\n5.  You may want to verify you have the correct project and if not, do this to switch:\n\n```bash\ngcloud config set project $GOOGLE_CLOUD_PROJECT\n```\n\n6.  Create app engine app:\n\n```bash\ngcloud app create \n```\nthis will ask for the region.  Go ahead and pick us-central [12]\n\n```bash\nCreating App Engine application in project [helloml-xxx] and region [us-central]....done.\nSuccess! The app is now created. Please use `gcloud app deploy` to deploy your first app.\n```\n7.  Clone the hello world sample app repo:\n\n```bash\ngit clone https://github.com/GoogleCloudPlatform/python-docs-samples\n```\n\n8.  cd into the repo:\n\n```bash\ncd python-docs-samples/appengine/standard_python37/hello_world\n```\n\n9.  Update Cloudshell image [NOTE this is optional....you don't need this]\n\n```bash\ngit clone https://github.com/noahgift/gcp-hello-ml.git\n# Update .cloudshellcustomimagerepo.json with project and image name\n# TIP: enable \"Boost Mode\" in in Cloudshell\ncloudshell env build-local\ncloudshell env push\ncloudshell env update-default-image\n# Restart Cloudshell VM\n```\n\n10. create and source the virtual environment:\n\n```bash\nvirtualenv --python $(which python) venv\nsource venv/bin/activate\n```\n\ndouble check it works:\n\n```bash\nwhich python\n/home/noah_gift/python-docs-samples/appengine/standard_python37/hello_world/venv/bin/python\n```\n\n10.  activate cloud shell editor\n\n![code editor](https://user-images.githubusercontent.com/58792/58593852-f60b2280-8220-11e9-850d-9858585be42e.png)\n\n11.  install packages:\n\n```bash\npip install -r requirements.txt\n```\n\nthis should install flask\n\n```\nFlask==1.0.2\n```\n\n12.  run flask locally\n\nthis runs flask locally in gcp shell\n\n\n```bash\npython main.py\n```\n\n13.  preview \n\n![preview](https://user-images.githubusercontent.com/58792/58594280-fb1ca180-8221-11e9-8934-736b5ea05f1f.png)\n\n\n14.  update main.py\n\n```python\n\nfrom flask import Flask\nfrom flask import jsonify\n\napp = Flask(__name__)\n\n@app.route('/')\ndef hello():\n    \"\"\"Return a friendly HTTP greeting.\"\"\"\n    return 'Hello I like to make AI Apps'\n\n@app.route('/name/\u003cvalue\u003e')\ndef name(value):\n    val = {\"value\": value}\n    return jsonify(val)\n\nif __name__ == '__main__':\n    app.run(host='127.0.0.1', port=8080, debug=True)\n```\n\n15.  Test out passing in parameters to exercise this function:\n\n```python\n@app.route('/name/\u003cvalue\u003e')\ndef name(value):\n    val = {\"value\": value}\n    return jsonify(val)\n```\nFor example, calling this route will take the word lion and pass into the name function in flask:\n```bash\nhttps://8080-dot-3104625-dot-devshell.appspot.com/name/lion\n```\nreturns value in web browser:\n```python\n{\nvalue: \"lion\"\n}\n```\n16.  Now deploy the app\n\n```bash\ngcloud app deploy\n```\n\nWarning first deploy could take about 10 minutes\nFYI!!! you may also need to enable cloud build API.\n\n```bash\n\nDo you want to continue (Y/n)?  y\nBeginning deployment of service [default]...\n╔════════════════════════════════════════════════════════════╗\n╠═ Uploading 934 files to Google Cloud Storage              ═╣\n\n```\n\n\n17.  Now stream the log files:\n\n```bash\ngcloud app logs tail -s default\n```\n\n18.  The production app is deployed and should like this:\n\n```bash\n\nSetting traffic split for service [default]...done.\nDeployed service [default] to [https://helloml-xxx.appspot.com]\nYou can stream logs from the command line by running:\n  $ gcloud app logs tail -s default\n\n  $ gcloud app browse\n(venv) noah_gift@cloudshell:~/python-docs-samples/appengine/standard_python37/hello_world (helloml-242121)$ gcloud app\n logs tail -s default\nWaiting for new log entries...\n2019-05-29 22:45:02 default[20190529t150420]  [2019-05-29 22:45:02 +0000] [8] [INFO] Starting gunicorn 19.9.0\n2019-05-29 22:45:02 default[20190529t150420]  [2019-05-29 22:45:02 +0000] [8] [INFO] Listening at: http://0.0.0.0:8081\n (8)\n2019-05-29 22:45:02 default[20190529t150420]  [2019-05-29 22:45:02 +0000] [8] [INFO] Using worker: threads\n2019-05-29 22:45:02 default[20190529t150420]  [2019-05-29 22:45:02 +0000] [25] [INFO] Booting worker with pid: 25\n2019-05-29 22:45:02 default[20190529t150420]  [2019-05-29 22:45:02 +0000] [27] [INFO] Booting worker with pid: 27\n2019-05-29 22:45:04 default[20190529t150420]  \"GET /favicon.ico HTTP/1.1\" 404\n2019-05-29 22:46:25 default[20190529t150420]  \"GET /name/usf HTTP/1.1\" 200\n```\n\n19.  Add a new route and test it out\n\n```python\n@app.route('/html')\ndef html():\n    \"\"\"Returns some custom HTML\"\"\"\n    return \"\"\"\n    \u003ctitle\u003eThis is a Hello World World Page\u003c/title\u003e\n    \u003cp\u003eHello\u003c/p\u003e\n    \u003cp\u003e\u003cb\u003eWorld\u003c/b\u003e\u003c/p\u003e\n    \"\"\"\n```\n\n20.  Install pandas and return json results\n\nAt this point, you may want to consider creating a Makefile and do this:\n\n```bash\ntouch Makefile\n#this goes inside that file\ninstall:\n\tpip install -r requirements.txt\n```\nyou also may want to setup lint:\n\n```\npylint --disable=R,C main.py\n------------------------------------\nYour code has been rated at 10.00/10\n\n```\n\nRoute looks like this:\n\nadd pandas import at top:\n\n```python\nimport pandas as pd\n```\n\n```python\n@app.route('/pandas')\ndef pandas_sugar():\n    df = pd.read_csv(\"https://raw.githubusercontent.com/noahgift/sugar/master/data/education_sugar_cdc_2003.csv\")\n    return jsonify(df.to_dict())\n\n```\n\nWhen you call the route ```https://\u003cyourapp\u003e.appspot.com/pandas```\n\nyou should get something like this:\n\n![example out](https://user-images.githubusercontent.com/58792/58598673-2a3b0f00-8232-11e9-9621-9aa094511a46.png)\n\n21.Add this wikipedia route\n\n```python\nimport wikipedia\n```\n\n```python\n@app.route('/wikipedia/\u003ccompany\u003e')\ndef wikipedia_route(company):\n    result = wikipedia.summary(company, sentences=10)\n    return result\n````\n\n22. Add NLP to app:\n\nA.  https://github.com/noahgift/recommendations/blob/master/notebooks/NLP_GCP.ipynb\nB.  Enable Cloud Natural Language API\nC.  ```pip install google-cloud-language```\n\n\ntest it out in IPython\n\n```python\nIn [1]: from google.cloud import language\nIn [2]: \nIn [2]: text = \"LeBron James plays for the Cleveland Cavaliers.\"\n   ...: client = language.LanguageServiceClient()\n   ...: document = language.Document(\n   ...:         content=result,\n   ...:         type_=language.Document.Type.PLAIN_TEXT)\n   ...:         encoding_type = language.EncodingType.UTF8\n   ...:         entities = client.analyze_entities(request = {'document': document, 'encoding_type': encoding_type}).entities\nIn [3]: entities\n```\n\n##\nEnd to End AI API Example\n\n```python\nfrom flask import Flask\nfrom flask import jsonify\nimport pandas as pd\nimport wikipedia\n\n\napp = Flask(__name__)\n\n@app.route('/')\ndef hello():\n    \"\"\"Return a friendly HTTP greeting.\"\"\"\n    return 'Hello I like to make AI Apps'\n\n@app.route('/name/\u003cvalue\u003e')\ndef name(value):\n    val = {\"value\": value}\n    return jsonify(val)\n\n@app.route('/html')\ndef html():\n    \"\"\"Returns some custom HTML\"\"\"\n    return \"\"\"\n    \u003ctitle\u003eThis is a Hello World World Page\u003c/title\u003e\n    \u003cp\u003eHello\u003c/p\u003e\n    \u003cp\u003e\u003cb\u003eWorld\u003c/b\u003e\u003c/p\u003e\n    \"\"\"\n@app.route('/pandas')\ndef pandas_sugar():\n    df = pd.read_csv(\"https://raw.githubusercontent.com/noahgift/sugar/master/data/education_sugar_cdc_2003.csv\")\n    return jsonify(df.to_dict())\n\n@app.route('/wikipedia/\u003ccompany\u003e')\ndef wikipedia_route(company):\n\n    # Imports the Google Cloud client library\n    from google.cloud import language\n    result = wikipedia.summary(company, sentences=10)\n\n    client = language.LanguageServiceClient()\n    document = language.Document(\n        content=result,\n        type_=language.Document.Type.PLAIN_TEXT)\n    encoding_type = language.EncodingType.UTF8\n    entities = client.analyze_entities(request = {'document': document, 'encoding_type': encoding_type}).entities\n    return str(entities)\n\n\nif __name__ == '__main__':\n    app.run(host='127.0.0.1', port=8080, debug=True)\n```\n\n## Reference\n\n* [Github Markdown Cheatsheet](https://guides.github.com/features/mastering-markdown/)\n* [hello world python 3 docs](https://cloud.google.com/appengine/docs/standard/python3/quickstart)\nmichael was here\n* [cloudshell quick start](https://cloud.google.com/shell/docs/quickstart)\n* [how do I switch projects](https://stackoverflow.com/questions/46770900/how-to-change-the-project-in-gcp-using-cli-commands)\n* [more information about project setup](https://github.com/noahgift/myrepo)\n* [nlp google](https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/language)\n* [nlp gcp](https://www.freecodecamp.org/news/how-to-make-your-own-sentiment-analyzer-using-python-and-googles-natural-language-api-9e91e1c493e/)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoahgift%2Fgcp-hello-ml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnoahgift%2Fgcp-hello-ml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoahgift%2Fgcp-hello-ml/lists"}