Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all test webapp #40

Merged
merged 7 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/app-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: app tests

run-name: ${{ github.actor }}

on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.11"]

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y portaudio19-dev
sudo apt-get install -y ffmpeg
python -m pip install --upgrade pip
python -m pip install pipenv
pipenv shell --fancy --python $(which python)
pipenv install -r requirements.txt

working-directory: web-app

- name: Run tests
run: |
pipenv run pytest --cov=app.py test_app.py
working-directory: web-app/app_tests
6 changes: 6 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ requests = "*"
coverage = "*"
pytest-flask = "*"
pytest-cov = "*"
pytz = "*"
python-dateutil = "*"
build = "*"
gitcommitlogger = "*"

[dev-packages]
black = "*"
pylint = "*"

[requires]
python_version = "3"
179 changes: 177 additions & 2 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 24 additions & 12 deletions web-app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,27 @@
from pymongo import MongoClient
import requests

app = Flask(__name__, template_folder="templates")

app = Flask("project4")
# Connect to MongoDB
client = MongoClient("mongodb://localhost:27017/")
db = client["ml_database"]
collection = db["transcription"]


client = MongoClient("mongodb://mongodb:27017/")
db = client["ml_databse"]
collection = db["transcription"]
@app.route("/test_render_template")
def test_render_template():
"""
Request received for /test_render_template
"""
print("Request received for /test_render_template")
return render_template("root.html")


@app.route("/")
def root_page():
"""
template to render root page
Template to render root page
"""
return render_template("root.html")

Expand All @@ -42,27 +50,31 @@ def display_results():
@app.route("/analyzeData", methods=["POST"])
def analyze_data():
"""
Function to send genreated audio file to the machine learning client
Function to send generated audio file to the machine learning client
"""
try:
if "audio" not in request.files:
return jsonify({"status": "error", "message": "No audio file provided"})

audio_file = request.files["audio"]
ml_client_url = "http://backend:5001/analyzeAudio"
ml_client_url = "http://127.0.0.1:5001/analyzeAudio"
# Use the converted audio file
response = requests.post(
ml_client_url, files={"audio": audio_file}, timeout=100
)
print("sent over")

# pylint: disable=R1705
if response.status_code == 200:
result = response.json()
return jsonify(result)
return (
jsonify({"error": "Failed to send and process audio. Please try again."}),
500,
)

else:
return (
jsonify(
{"error": "Failed to send and process audio. Please try again."}
),
500,
)
except FileNotFoundError as e:
return jsonify({"status": "error", "message": f"File not found: {str(e)}"})

Expand Down
Loading
Loading