Skip to content

Commit

Permalink
Testing Azure Function
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul committed May 16, 2024
1 parent 921c710 commit 7f8cdea
Show file tree
Hide file tree
Showing 22 changed files with 39 additions and 74 deletions.
99 changes: 32 additions & 67 deletions .github/workflows/main_paulxieptest.yml
Original file line number Diff line number Diff line change
@@ -1,75 +1,40 @@
# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action
# More GitHub Actions for Azure: https://github.com/Azure/actions
# More info on Python, GitHub Actions, and Azure Functions: https://aka.ms/python-webapps-actions

name: Build and deploy Python project to Azure Function App - paulxieptest
name: Deploy Python project to Azure Function App

on:
push:
branches:
- main
workflow_dispatch:
[push]

env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
PYTHON_VERSION: '3.11' # set this to the python version to use (supports 3.6, 3.7, 3.8)
AZURE_FUNCTIONAPP_NAME: 'paulxieptest' # set this to your function app name on Azure
AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your function app project, defaults to the repository root
PYTHON_VERSION: '3.8' # set this to the python version to use (e.g. '3.6', '3.7', '3.8')

jobs:
build:
build-and-deploy:
runs-on: ubuntu-latest
environment: dev
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Python version
uses: actions/setup-python@v1
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Create and start virtual environment
run: |
python -m venv venv
source venv/bin/activate
- name: Install dependencies
run: pip install -r requirements.txt

# Optional: Add step to run tests here

- name: Zip artifact for deployment
run: zip release.zip ./* -r

- name: Upload artifact for deployment job
uses: actions/upload-artifact@v3
with:
name: python-app
path: |
release.zip
!venv/
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-function.outputs.webapp-url }}

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: python-app

- name: Unzip artifact for deployment
run: unzip release.zip

- name: 'Deploy to Azure Functions'
uses: Azure/functions-action@v1
id: deploy-to-function
with:
app-name: 'paulxieptest'
slot-name: 'Production'
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_912DA8427DE14045B5A68CFFAD84F71D }}
scm-do-build-during-deployment: true
enable-oryx-build: true
- name: 'Checkout GitHub Action'
uses: actions/checkout@v3

- name: Setup Python ${{ env.PYTHON_VERSION }} Environment
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: 'Resolve Project Dependencies Using Pip'
shell: bash
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
python -m pip install --upgrade pip
pip install -r requirements.txt --target=".python_packages/lib/site-packages"
popd
- name: 'Run Azure Functions Action'
uses: Azure/functions-action@v1
id: fa
with:
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE }}
scm-do-build-during-deployment: true
enable-oryx-build: true
14 changes: 7 additions & 7 deletions function_app.py → azure/function_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@

flask_app = Flask(__name__)

with open('sentiment_analysis/models/logistic_regression.pkl', 'rb') as f:
with open('models/logistic_regression.pkl', 'rb') as f:
logistic_regression_model = pickle.load(f)
with open('sentiment_analysis/models/naive_bayes.pkl', 'rb') as f:
with open('models/naive_bayes.pkl', 'rb') as f:
naive_bayes_model = pickle.load(f)
with open('sentiment_analysis/models/sklearn_vectorizer.pkl', 'rb') as f:
with open('models/sklearn_vectorizer.pkl', 'rb') as f:
sklearn_vectorizer = pickle.load(f)
lstm_model = tf.keras.models.load_model('sentiment_analysis/models/lstm.h5', compile=False)
lstm_vectorizer = tf.keras.models.load_model('sentiment_analysis/models/tf_vectorizer')
transformers_vectorizer = tf.keras.models.load_model('sentiment_analysis/models/tf_vectorizer_t')
transformers_model = tf.keras.models.load_model('sentiment_analysis/models/transformers', compile=False)
lstm_model = tf.keras.models.load_model('models/lstm.h5', compile=False)
lstm_vectorizer = tf.keras.models.load_model('models/tf_vectorizer')
transformers_vectorizer = tf.keras.models.load_model('models/tf_vectorizer_t')
transformers_model = tf.keras.models.load_model('models/transformers', compile=False)

batch_size = 32

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 7f8cdea

Please sign in to comment.