Annie AI Learning
  • NEW!
    NEW!  Connect Ideas Across Notes
    Save time and share insights. With Paragraph Citation, you can quote others’ work with source info built in. If someone cites your note, you’ll see a card showing where it’s used—bringing notes closer together.
    Got it
        • Sharing URL Link copied
        • /edit
        • View mode
          • Edit mode
          • View mode
          • Book mode
          • Slide mode
          Edit mode View mode Book mode Slide mode
        • Customize slides
        • Note Permission
        • Read
          • Owners
          • Signed-in users
          • Everyone
          Owners Signed-in users Everyone
        • Write
          • Owners
          • Signed-in users
          • Everyone
          Owners Signed-in users Everyone
        • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invite by email
        Invitee

        This note has no invitees

      • Publish Note

        Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

        Your note will be visible on your profile and discoverable by anyone.
        Your note is now live.
        This note is visible on your profile and discoverable online.
        Everyone on the web can find and read all notes of this public team.

        Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Explore these features while you wait
        Complete general settings
        Bookmark and like published notes
        Write a few more notes
        Complete general settings
        Write a few more notes
        See published notes
        Unpublish note
        Please check the box to agree to the Community Guidelines.
        View profile
      • Commenting
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Suggest edit
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
      • Emoji Reply
      • Enable
      • Versions and GitHub Sync
      • Note settings
      • Note Insights New
      • Engagement control
      • Make a copy
      • Transfer ownership
      • Delete this note
      • Insert from template
      • Import from
        • Dropbox
        • Google Drive
        • Gist
        • Clipboard
      • Export to
        • Dropbox
        • Google Drive
        • Gist
      • Download
        • Markdown
        • HTML
        • Raw HTML
    Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
    Menu
    Options
    Engagement control Make a copy Transfer ownership Delete this note
    Import from
    Dropbox Google Drive Gist Clipboard
    Export to
    Dropbox Google Drive Gist
    Download
    Markdown HTML Raw HTML
    Back
    Sharing URL Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    Customize slides
    Note Permission
    Read
    Owners
    • Owners
    • Signed-in users
    • Everyone
    Owners Signed-in users Everyone
    Write
    Owners
    • Owners
    • Signed-in users
    • Everyone
    Owners Signed-in users Everyone
    Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- title: 1209對話機器人(5/5) tags: GCP, 筆記 --- # 1209 對話機器人(5/5) 一 開發環境本地集成 (pipenv+docker) 二 雲端虛擬機租用 三 heroku試行 電腦 套件統一 ->pipenv使用 ## 套件管理的必要 python 套件管理工具 ` pip install pipenv` ![](https://i.imgur.com/o7okFBP.png) ## 打開pycharm->新增專案->選pipenv->編譯器內有選到東西即可 ![](https://i.imgur.com/JLC3oao.png) ## 用pipenv創建的專案裡,都會有pipfile(用來記錄安裝過的套件) ![](https://i.imgur.com/BlTx2vR.png) ## 創python檔:demo_project->new->python file ![](https://i.imgur.com/gTmqH6I.png) ### 命名檔案 ![](https://i.imgur.com/WBjtNYo.png) ### 在main.py輸入以下程式碼 會出現紅字 查看external libraries發現沒有安裝 ![](https://i.imgur.com/MeEa6jq.png) ### 至pipfile的『packages』輸入,再點擊右下方pipenv update ``` “line-bot-sdk" = "版本號(這邊先暫時打星號)" ``` ![](https://i.imgur.com/XAyrk8t.png) ### 若右下方沒出現,也可自行從從左下方叫出terminal也可,打上 ``` pipenv update ``` ![](https://i.imgur.com/rvhNvfq.png) ### 安裝成功後,external libraries以可以查看到下載的linebot資料夾,這樣的方法就是在一個專業下安裝他要的套件 ![](https://i.imgur.com/E4nZHwI.png) ### 為了驗證,我們先關掉這個專案,重新創一個demo_project2來看看 ![](https://i.imgur.com/7oBNdU5.png) ### ㄧ樣創個main.py檔,打下程式碼,會發現剛剛安裝的套件部會這專案中,所以使用pipenv可以在專案中安裝要用的套件方便管理 ![](https://i.imgur.com/KGMlKaL.png) ![](https://i.imgur.com/DkTsLOJ.png) :::danger 但是若作業系統不一樣 可能還是會遇到這邊能跑 另一編不能跑的問題 這也是為什麼在瀏覽器中使用的colab會興起 每個人都可以使用。 >colab較像數據專案在使用 >pycharm VS Code cloud shell 系統性開發 -------- “docker”以後可以去研究 pipenv+docker 一起搭配 ::: ---- ## GCP 操作加入VM instance ## 點選computer Engine ![](https://i.imgur.com/aCNfgv7.png) ## create:VM instances(gcp把gce(Google Compute Engine)此服務加進專案內了只有最高管理員才能把各項服務加到專案內) ![](https://i.imgur.com/M4ateq7.png) ## create an instance 1. name:(不能更改不要亂取,因為機器可以用名字互相溝通->取公司未來會用代號) 2. region:區域選台灣(速度快/公司要求/選其他區域要額外收費,特別是跨區域連線) 3. labels:以後寄帳單有關 4. machine configuration: * gereral-propse: series:依照規格計價,越好越貴,這邊先選E2(E系列通常夠用) * compute-optimized跟memory-optimized(記憶體優化)比較貴,先不碰,未來有需要可再研究 ![](https://i.imgur.com/CJHyYpZ.png) 5. Book disk: 點選change 進入到下個頁面 ![](https://i.imgur.com/7bJh1oz.png) ### public images: * operating system:這邊可以依照需求選擇:如deep learning. debian.... 不要選windows 有版權很貴->這邊先選debian * size(gb):先選15gb,磁碟選越大 越貴 雲服務如果服務不夠可以再加 不用一次買很多 ![](https://i.imgur.com/XZ7EfYB.png) ### identity and API access: * service account:選擇 no service account * Firewall:勾選Alow HTTP traffic 往下點開 manage,security,disks...繼續設定 ![](https://i.imgur.com/ZmgBxR6.png) ### management: - Automation->Startup script(要安裝的東西:這邊名稱取為:cxcxc) ``` #!bin/bash touch/tmp/cxcxc ``` ![](https://i.imgur.com/O4AEgL7.png) ![](https://i.imgur.com/34oFfko.png) ## 開好機器->連到機器裡:這邊的external ip還沒設定所以回無法顯示 ![](https://i.imgur.com/iqjCuRy.png) ## 按下SSH連結 ![](https://i.imgur.com/BGC8IFs.png) ## 顯示剛剛創的cxcxc ## 輸入指令: ``` ls/tmp ``` ![](https://i.imgur.com/z0PCgMM.png) ## 這邊示範輸入指令安裝apache2:安裝完後 外人就可以連進網址 ``` sudo apt-get install -y apache2 ``` ![](https://i.imgur.com/ukrv4vx.png) ## 完成後 剛剛的外部網址就能連進apache網址了(未來可依照個人需求替換要連的東西) ![](https://i.imgur.com/aIjhDpZ.png) ## 輸入指令:訪問桶子 發現無法進入 我要訪問cloud storage,沒有辦法讀取 因為這邊還沒創bucket ``` gsutil ls ``` ![](https://i.imgur.com/RpNZA9E.png) --- :::success # 這邊重新示範 當成複習-> 重新來創一個新的instances 並開啟 跟service account ::: ## 1. create instance ![](https://i.imgur.com/8HmJDcJ.png) ## 2. name 命名/region 選台灣/series:E2 ![](https://i.imgur.com/v8vxJla.png) ## 3.若要更改容量 點change ![](https://i.imgur.com/zyOucso.png) 要改作業系統也行 在自己選擇:選擇windows系列會貴 因為有版權 ![](https://i.imgur.com/6c5GVRm.png) ## 4. service account:這邊選之前創的專案(ai-demo-gcp)可以操作桶子如果沒有的話,則選compute engine default service account ![](https://i.imgur.com/mLJRbds.png) ## 創建完成後,按下SSH ![](https://i.imgur.com/zkfGDx6.png) ## 輸入語法: ``` gsutil ls ``` ![](https://i.imgur.com/xqXMoXj.png) ## 跟一開始創建的案例比較,由於最新創建的vm中,有設定service account,所以是看的到桶子內的東西的 ![](https://i.imgur.com/DpDEJeC.png) ## 示範完後 先刪除 ![](https://i.imgur.com/WRS4L5s.png) 未來想了解更多 關鍵字: * IAP * GCE防火牆設定 ------ # 啟用GAE ## 1. 點App Engine ![](https://i.imgur.com/jwy84ZB.png) ## 2.啟動cloud shell ![](https://i.imgur.com/61lEm2V.png) ## 3. 輸入以下程式碼(下載官方教材)google把程式碼都放在github上) ``` git clone https://github.com/GoogleCloudPlatform/python-docs-samples/ ``` * [GoogleCloudPlatform/python-docs-samples: Code samples used on cloud.google.com](https://github.com/GoogleCloudPlatform/python-docs-samples/) ![](https://i.imgur.com/MV95d6n.png) # 下載完程式碼後,要切換到教材的資料夾 ## 輸入ls ![](https://i.imgur.com/WwE8CPp.png) ## 輸入cd python-docs-samples/ ``` cd python-docs-samples/ ``` ![](https://i.imgur.com/a4btWvb.png) ## 輸入cd appengine/ ``` cd appengine/ ``` ## 輸入cd standard_python3/ ``` cd standard_python3/ ``` ## 輸入cd custom-server/ ``` cd custom-server/ ``` ## 都輸入完後 按開啟編輯器 ![](https://i.imgur.com/KfJVxBr.png) ## 找到customer-server檔案 ![](https://i.imgur.com/kxmyqqw.png) ## 按下 open as workspace ![](https://i.imgur.com/t46XIy1.png) ## 這邊可以查看原始碼,找到.theia資料夾 ![](https://i.imgur.com/Io4pZdd.png) ## 按下 open as workspace ![](https://i.imgur.com/Xia6Ezn.png) ## 打開終端機->輸入gcloud app deploy --appyaml app.yaml:gcloud 部署一個app從yaml檔 ``` gcloud app deploy --appyaml app.yaml ``` ![](https://i.imgur.com/gPGWvZq.png) ## Yes! ![](https://i.imgur.com/2WeJW4M.png) ## 跑完後 將圖中網址複製到網頁上 ![](https://i.imgur.com/Qk6Mh6O.png) ## 就能跑出一個網頁了(gcloud幫你部署成功了!) ![](https://i.imgur.com/f0ua8EB.png) ## 與機器人連結:要更改 * main. py/ * requirements.txt/ ## 開啟編輯器:開啟後往上拉 ![](https://i.imgur.com/81Vzq3B.png) ## ->在requirement.txt檔中輸入line-bot-sdk ![](https://i.imgur.com/BuGBg5K.png) ## file選擇自動儲存:auto-save ![](https://i.imgur.com/K6KJUzX.png) ## main.py 圖中橘框保留,紅框刪除,並在紅框中貼上以下程式碼 ![](https://i.imgur.com/jC7tQoU.png) ``` from flask import Flask, request, abort from linebot import ( LineBotApi, WebhookHandler ) from linebot.exceptions import ( InvalidSignatureError ) from linebot.models import ( MessageEvent, TextMessage, TextSendMessage, ) app = Flask(__name__) line_bot_api = LineBotApi('這邊要改YOUR_CHANNEL_ACCESS_TOKEN') handler = WebhookHandler('這邊要改YOUR_CHANNEL_SECRET') @app.route("/callback", methods=['POST']) def callback(): # get X-Line-Signature header value signature = request.headers['X-Line-Signature'] # get request body as text body = request.get_data(as_text=True) app.logger.info("Request body: " + body) # handle webhook body try: handler.handle(body, signature) except InvalidSignatureError: print("Invalid signature. Please check your channel access token/channel secret.") abort(400) return 'OK' @handler.add(MessageEvent, message=TextMessage) def handle_message(event): line_bot_api.reply_message( event.reply_token, TextSendMessage(text=event.message.text)) ``` * [line/line-bot-sdk-python: LINE Messaging API SDK for Python](https://github.com/line/line-bot-sdk-python) ## 更改自己的channel_access_token&channel_secret ![](https://i.imgur.com/VQuZkRB.png) ## 開啟終端機(確認已完成main.py更新程式碼/requirement.txt輸入line-bot sdk) ![](https://i.imgur.com/G7lLgSg.png) ## 再次部署,輸入以下程式碼 ``` gcloud app deploy --appyaml app.yaml ``` ![](https://i.imgur.com/oVEID6N.png) ## 完成後,找到產生的網址,並加上"/callback"貼回line的webhook url ![](https://i.imgur.com/azCfTQ9.png) ![](https://i.imgur.com/asril4Z.png) ----- 補充 雲原生 cloud native * 專案預設是不能執行任何服務 所以每次都要enable加入東西 member service_account (gmail邀請進入專案) 操作資源只有管理者role的概念 * service_account可以生成key 或是直接配gce_service _account 操作cloud storage就不用key * cloud storage有bucket 調整權限 精細跟統一 預設是不公開 * gce虛擬機 :可以放上程式碼 變成application 如果沒有做額外處理是http 後面學長會教 * gae把程式碼給他去生成https連結 用戶可以直接用 ---- 相關資訊: * [MySQL · Google Cloud Platform(GCP) 學習筆記](https://kejyuntw.gitbooks.io/google-cloud-platform-learning-notes/content/google-cloud-sql/mysql/google-cloud-sql-mysql-README.html) # END

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully