Spaces:
Sleeping
Sleeping
Hamid Omarov
commited on
Commit
·
8eb674c
1
Parent(s):
6770071
Update api.py
Browse files
api.py
CHANGED
|
@@ -1,9 +1,29 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
+
|
| 3 |
+
app = Flask(__name__)
|
| 4 |
+
|
| 5 |
+
# 1. /hello endpoint
|
| 6 |
+
@app.route('/hello', methods=['GET'])
|
| 7 |
+
def hello():
|
| 8 |
+
return jsonify({'message': 'Hello, welcome to the RAG 30-day sprint!'})
|
| 9 |
+
|
| 10 |
+
# 2. /calculate endpoint
|
| 11 |
+
@app.route('/calculate', methods=['GET'])
|
| 12 |
+
def calculate():
|
| 13 |
+
try:
|
| 14 |
+
a = float(request.args.get('a'))
|
| 15 |
+
b = float(request.args.get('b'))
|
| 16 |
+
result = a + b
|
| 17 |
+
return jsonify({'a': a, 'b': b, 'sum': result})
|
| 18 |
+
except (TypeError, ValueError):
|
| 19 |
+
return jsonify({'error': 'Please provide valid numbers using ?a=5&b=10'}), 400
|
| 20 |
+
|
| 21 |
+
# 3. /ai-ready endpoint
|
| 22 |
+
@app.route('/ai-ready', methods=['GET'])
|
| 23 |
+
def ai_ready():
|
| 24 |
+
return jsonify({
|
| 25 |
+
'message': 'You are ready to build AI apps. Keep pushing, learn daily, and ship projects!'
|
| 26 |
+
})
|
| 27 |
+
|
| 28 |
+
if __name__ == '__main__':
|
| 29 |
+
app.run(debug=True)
|