Modify request type + take params from JSON body.

#2
by Kareem94 - opened
Files changed (1) hide show
  1. main.py +7 -9
main.py CHANGED
@@ -29,13 +29,14 @@ except Exception as e:
29
  def home():
30
  return request.url
31
 
32
- @app.route("/predict")
33
  def predict():
34
  try:
35
- # Get code from URL parameter
36
- code = request.args.get("code")
37
- if not code:
38
- return jsonify({"error": "Missing 'code' URL parameter"}), 400
 
39
 
40
  # Tokenize input
41
  inputs = tokenizer(
@@ -53,10 +54,7 @@ def predict():
53
  # Apply sigmoid and format score
54
  score = torch.sigmoid(outputs.logits).item()
55
 
56
- return jsonify({
57
- "score": round(score, 4),
58
- "given_code": code[:500] + "..." if len(code) > 500 else code
59
- })
60
 
61
  except Exception as e:
62
  return jsonify({"error": str(e)}), 500
 
29
  def home():
30
  return request.url
31
 
32
+ @app.route("/predict", methods=["POST"])
33
  def predict():
34
  try:
35
+ data = request.get_json()
36
+ if not data or "code" not in data:
37
+ return jsonify({"error": "Missing 'code' in request body"}), 400
38
+
39
+ code = data["code"]
40
 
41
  # Tokenize input
42
  inputs = tokenizer(
 
54
  # Apply sigmoid and format score
55
  score = torch.sigmoid(outputs.logits).item()
56
 
57
+ return jsonify(round(score, 4))
 
 
 
58
 
59
  except Exception as e:
60
  return jsonify({"error": str(e)}), 500