Spaces:
Sleeping
Sleeping
Modify request type + take params from JSON body.
Browse files
main.py
CHANGED
|
@@ -29,13 +29,15 @@ 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
|
| 36 |
-
|
| 37 |
-
if not code:
|
| 38 |
-
return jsonify({"error": "Missing 'code'
|
|
|
|
|
|
|
| 39 |
|
| 40 |
# Tokenize input
|
| 41 |
inputs = tokenizer(
|
|
@@ -54,8 +56,7 @@ def predict():
|
|
| 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:
|
|
|
|
| 29 |
def home():
|
| 30 |
return request.url
|
| 31 |
|
| 32 |
+
@app.route("/predict", methods=["POST"])
|
| 33 |
def predict():
|
| 34 |
try:
|
| 35 |
+
# Get code from request body (JSON)
|
| 36 |
+
data = request.get_json()
|
| 37 |
+
if not data or "code" not in data:
|
| 38 |
+
return jsonify({"error": "Missing 'code' in request body"}), 400
|
| 39 |
+
|
| 40 |
+
code = data["code"]
|
| 41 |
|
| 42 |
# Tokenize input
|
| 43 |
inputs = tokenizer(
|
|
|
|
| 56 |
score = torch.sigmoid(outputs.logits).item()
|
| 57 |
|
| 58 |
return jsonify({
|
| 59 |
+
"score": round(score, 4)
|
|
|
|
| 60 |
})
|
| 61 |
|
| 62 |
except Exception as e:
|