diff --git a/web-app/app.py b/web-app/app.py index 639092c..2fb87b3 100644 --- a/web-app/app.py +++ b/web-app/app.py @@ -1,21 +1,36 @@ -from flask import Flask, render_template, request, redirect, url_for, make_response, session +from flask import Flask, render_template, request, jsonify import os -from pymongo import MongoClient -import pymongo -import datetime -from bson.objectid import ObjectId -import sys +import subprocess app = Flask('project4') +app.config['UPLOAD_FOLDER'] = 'uploads' +os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True) + @app.route('/') def RootPage(): return render_template('root.html') -@app.route('/anaylzeData', methods=['POST']) -def anaylzeData(): - return +@app.route('/analyzeData', methods=['POST']) +def analyzeData(): + try: + if 'audio' not in request.files: + return jsonify({"status": "error", "message": "No audio file provided"}) + + audio_file = request.files['audio'] + audio_path = os.path.join(app.config['UPLOAD_FOLDER'], 'user_audio.wav') + audio_file.save(audio_path) + + + print("Audio file saved at:", audio_path) + result = subprocess.run(["C:\\Users\\Andrew - User\\AppData\\Local\\Microsoft\\WindowsApps\\python.exe", "E:\\4-containerized-app-exercise-rizzballs\\machine-learning-client\\machine_learning_client.py", audio_path], capture_output=True, text=True) + + + return jsonify({"status": "success"}) + + except Exception as e: + return jsonify({"status": "error", "message": str(e)}) if __name__ == "__main__": PORT = os.getenv('PORT', 5000) - app.run(debug=True,port=PORT) + app.run(debug=True, port=PORT) diff --git a/web-app/templates/root.html b/web-app/templates/root.html index cc8c780..f3e1ac4 100644 --- a/web-app/templates/root.html +++ b/web-app/templates/root.html @@ -7,64 +7,64 @@
- {% extends 'base.html' %} {% block Base %} + {% extends 'base.html' %} + {% block Base %} - {% endblock %} - - -