Skip to content

Commit 5b6d635

Browse files
committed
added flask api examples
1 parent 69bcf9b commit 5b6d635

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@
33
This repository contains some examples related to the course labs.
44

55
## Lab 02
6-
Find example [here](lab_02) and
6+
Find example [here](lab_02) or open the notebook in Colab pressing <a target="_blank" href="https://colab.research.google.com/github/advanced-computing/lab_examples/blob/main/lab_02/lab_02_example.ipynb">
7+
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/>
8+
</a>
9+
10+
## Lab 04
11+

lab_04/flask_example_1.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from flask import Flask, jsonify, request
2+
import pandas as pd
3+
4+
app = Flask(__name__)
5+
6+
@app.route("/")
7+
def hello_world():
8+
"""Return a friendly HTTP greeting."""
9+
10+
return "<p>Hello, World!</p>"
11+
12+
@app.route("/sum", methods=["GET"])
13+
def sum():
14+
"""Return the sum of two numbers."""
15+
16+
a = request.args.get("a")
17+
b = request.args.get("b")
18+
19+
return jsonify({"sum": int(a) + int(b)})
20+
21+
22+
def factorial(n):
23+
if n == 0:
24+
return 1
25+
else:
26+
return n * factorial(n-1)
27+
28+
@app.route("/factorial", methods=["GET"])
29+
def factorial_route():
30+
"""Return the factorial of a number."""
31+
32+
n = request.args.get("n",10)
33+
r = factorial(int(n))
34+
response = f'{n}! equals {r}'
35+
return response
36+
37+
38+
if __name__ == "__main__":
39+
app.run(debug=True)

requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ ruff
55
pandas
66
numpy
77
plotly
8-
matplotlib
8+
matplotlib
9+
python-dotenv
10+
google-genai

0 commit comments

Comments
 (0)