Spaces:
Runtime error
Runtime error
venky2k1
commited on
Commit
Β·
f77de4a
1
Parent(s):
d3e257b
Deploy project
Browse files- app.py +6 -4
- requirements.txt +4 -4
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
|
2 |
from flask_cors import CORS
|
3 |
import torch
|
4 |
from transformers import RobertaTokenizer, RobertaForSequenceClassification
|
@@ -6,12 +6,13 @@ from transformers import RobertaTokenizer, RobertaForSequenceClassification
|
|
6 |
app = Flask(__name__)
|
7 |
CORS(app)
|
8 |
|
|
|
9 |
tokenizer = RobertaTokenizer.from_pretrained("microsoft/codebert-base")
|
10 |
model = RobertaForSequenceClassification.from_pretrained("microsoft/codebert-base")
|
11 |
|
12 |
@app.route("/")
|
13 |
def home():
|
14 |
-
return "
|
15 |
|
16 |
@app.route("/detect", methods=["POST"])
|
17 |
def detect_bug():
|
@@ -24,8 +25,9 @@ def detect_bug():
|
|
24 |
inputs = tokenizer(code, return_tensors="pt", truncation=True, padding=True)
|
25 |
outputs = model(input_ids=inputs["input_ids"], attention_mask=inputs["attention_mask"])
|
26 |
prediction = torch.argmax(outputs.logits, dim=1).item()
|
27 |
-
|
28 |
-
|
|
|
29 |
|
30 |
except Exception as e:
|
31 |
return jsonify({"error": str(e)}), 500
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
from flask_cors import CORS
|
3 |
import torch
|
4 |
from transformers import RobertaTokenizer, RobertaForSequenceClassification
|
|
|
6 |
app = Flask(__name__)
|
7 |
CORS(app)
|
8 |
|
9 |
+
# Load model and tokenizer
|
10 |
tokenizer = RobertaTokenizer.from_pretrained("microsoft/codebert-base")
|
11 |
model = RobertaForSequenceClassification.from_pretrained("microsoft/codebert-base")
|
12 |
|
13 |
@app.route("/")
|
14 |
def home():
|
15 |
+
return "Bug Detection and Fixing API is running!"
|
16 |
|
17 |
@app.route("/detect", methods=["POST"])
|
18 |
def detect_bug():
|
|
|
25 |
inputs = tokenizer(code, return_tensors="pt", truncation=True, padding=True)
|
26 |
outputs = model(input_ids=inputs["input_ids"], attention_mask=inputs["attention_mask"])
|
27 |
prediction = torch.argmax(outputs.logits, dim=1).item()
|
28 |
+
bug_status = "buggy" if prediction == 1 else "clean"
|
29 |
+
|
30 |
+
return jsonify({"status": bug_status})
|
31 |
|
32 |
except Exception as e:
|
33 |
return jsonify({"error": str(e)}), 500
|
requirements.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
-
transformers
|
2 |
-
torch
|
|
|
|
|
3 |
gradio==4.44.1
|
4 |
-
flask
|
5 |
-
flask-cors
|
|
|
1 |
+
transformers==4.52.4
|
2 |
+
torch==2.7.1
|
3 |
+
flask==3.1.1
|
4 |
+
flask-cors==4.0.0
|
5 |
gradio==4.44.1
|
|
|
|