Created
April 10, 2024 11:23
-
-
Save Bhavya031/f87dba65a9e893bc13667bc3addaaed9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, jsonify | |
import os | |
app = Flask(__name__) | |
port = int(os.environ.get("PORT", 4000)) | |
@app.route('/sum', methods=['POST']) | |
def sum_numbers(): | |
data = request.get_json() | |
num1 = data['num1'] | |
num2 = data['num2'] | |
try: | |
num1 = float(num1) | |
num2 = float(num2) | |
result = num1 + num2 | |
return jsonify({'result': result}), 200 | |
except ValueError: | |
return jsonify({'error': 'Invalid input, please provide valid numbers'}), 400 | |
if __name__ == '__main__': | |
app.run(debug=True, port=port) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3.12.3 | |
WORKDIR /app | |
COPY requirements.txt . | |
RUN pip install --no-cache-dir -r requirements.txt | |
COPY app.py . | |
CMD ["python", "app.py"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flask |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment