Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -2,13 +2,16 @@ from flask import Flask, request, jsonify
|
|
2 |
import torch
|
3 |
from transformers import RobertaTokenizer
|
4 |
import os
|
5 |
-
|
|
|
6 |
# Initialize Flask app
|
7 |
app = Flask(__name__)
|
8 |
|
9 |
# Load the trained model and tokenizer
|
10 |
tokenizer = RobertaTokenizer.from_pretrained("microsoft/codebert-base")
|
11 |
-
|
|
|
|
|
12 |
|
13 |
# Ensure the model is in evaluation mode
|
14 |
model.eval()
|
@@ -54,5 +57,5 @@ def predict():
|
|
54 |
|
55 |
|
56 |
# Run the Flask app
|
57 |
-
if __name__ == "
|
58 |
app.run(debug=True)
|
|
|
2 |
import torch
|
3 |
from transformers import RobertaTokenizer
|
4 |
import os
|
5 |
+
from transformers import RobertaForSequenceClassification
|
6 |
+
import torch.serialization
|
7 |
# Initialize Flask app
|
8 |
app = Flask(__name__)
|
9 |
|
10 |
# Load the trained model and tokenizer
|
11 |
tokenizer = RobertaTokenizer.from_pretrained("microsoft/codebert-base")
|
12 |
+
torch.serialization.add_safe_globals([RobertaForSequenceClassification])
|
13 |
+
|
14 |
+
model = torch.load("model.pth", map_location=torch.device('cpu'), weights_only=False) # Load the trained model
|
15 |
|
16 |
# Ensure the model is in evaluation mode
|
17 |
model.eval()
|
|
|
57 |
|
58 |
|
59 |
# Run the Flask app
|
60 |
+
if __name__ == "__main__":
|
61 |
app.run(debug=True)
|