mou3az commited on
Commit
c24f7a6
·
verified ·
1 Parent(s): e06c9d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -48,11 +48,20 @@ def generate_quiz(context):
48
  @app.route("/", methods=["GET", "POST"])
49
  def generate_quiz_page():
50
  if request.method == "POST":
51
- context = request.form.get("context")
 
 
 
 
 
 
 
 
 
52
  response = generate_quiz(context)
53
 
54
- # if request.headers.get('Content-Type') == 'application/json':
55
- # return jsonify(response)
56
 
57
 
58
  quiz_html = f"""
 
48
  @app.route("/", methods=["GET", "POST"])
49
  def generate_quiz_page():
50
  if request.method == "POST":
51
+ if request.content_type == 'application/json':
52
+ data = request.get_json()
53
+ context = data.get("context")
54
+ if context is None:
55
+ return jsonify({"error": "Missing 'context' parameter"}), 400
56
+ else:
57
+ context = request.form.get("context")
58
+ if context is None:
59
+ return jsonify({"error": "Missing 'context' parameter"}), 400
60
+
61
  response = generate_quiz(context)
62
 
63
+ if request.content_type == 'application/json':
64
+ return jsonify(response)
65
 
66
 
67
  quiz_html = f"""