Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -17,7 +17,7 @@ app = Flask(__name__)
|
|
| 17 |
tokenizer = RobertaTokenizer.from_pretrained("microsoft/codebert-base")
|
| 18 |
torch.serialization.add_safe_globals([RobertaForSequenceClassification])
|
| 19 |
|
| 20 |
-
model = torch.load("
|
| 21 |
|
| 22 |
# Ensure the model is in evaluation mode
|
| 23 |
model.eval()
|
|
@@ -34,7 +34,7 @@ def predict():
|
|
| 34 |
print("Received code:", request.get_json()["code"])
|
| 35 |
code = request.get_json()["code"]
|
| 36 |
# Load saved weights and config
|
| 37 |
-
checkpoint = torch.load("
|
| 38 |
config = RobertaConfig.from_dict(checkpoint['config'])
|
| 39 |
|
| 40 |
# Rebuild the model with correct architecture
|
|
|
|
| 17 |
tokenizer = RobertaTokenizer.from_pretrained("microsoft/codebert-base")
|
| 18 |
torch.serialization.add_safe_globals([RobertaForSequenceClassification])
|
| 19 |
|
| 20 |
+
model = torch.load("codebert_readability_scorer.pth", map_location=torch.device('cpu'), weights_only=False) # Load the trained model
|
| 21 |
|
| 22 |
# Ensure the model is in evaluation mode
|
| 23 |
model.eval()
|
|
|
|
| 34 |
print("Received code:", request.get_json()["code"])
|
| 35 |
code = request.get_json()["code"]
|
| 36 |
# Load saved weights and config
|
| 37 |
+
checkpoint = torch.load("codebert_readability_scorer.pth")
|
| 38 |
config = RobertaConfig.from_dict(checkpoint['config'])
|
| 39 |
|
| 40 |
# Rebuild the model with correct architecture
|