Skip to content

Commit

Permalink
Merge pull request #5 from somethingsoftware/workflow
Browse files Browse the repository at this point in the history
Add a github workflow
  • Loading branch information
profilelag authored Jun 25, 2024
2 parents e4491e4 + ea55b67 commit 0cea74c
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Python application

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: write

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
sudo python -m pip install --upgrade pip
sudo pip install flake8
if [ -f requirements.txt ]; then sudo pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Start server
run: |
sudo python main.py &
- name: Wait for server to be up
run: |
for i in {1..30}; do
if curl -s http://localhost:8080 > /dev/null; then
echo "Server is up!"
break
fi
echo "Waiting for server to be up..."
sleep 2
done
- name: Send test request
run: |
OUT=$(cat example_image.json | curl -X POST http://localhost:8080/classify -H "Content-Type: application/json" -d @-)
echo $OUT
if echo $OUT | grep '"success": true'; then
echo "passed"
else
exit 1
fi
1 change: 1 addition & 0 deletions example_image.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
print("ResNet50 model loaded.")

hostName = os.getenv("HOSTNAME") or "localhost"
serverPort = int(os.getenv("PORT")) or 8080
serverPort = os.getenv("PORT") or 8080
serverPort = int(serverPort)
imagesPath = os.getenv("IMAGES_PATH") or ""

if(not imagesPath == "" and not os.path.exists("imagesPath")):
Expand Down Expand Up @@ -131,4 +132,4 @@ def error_json(server, code, msg):
pass

webServer.server_close()
print("Server stopped.")
print("Server stopped.")
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
load-dotenv==0.1.0
pillow==10.3.0
tensorflow==2.16.1

0 comments on commit 0cea74c

Please sign in to comment.