Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import TextClassificationPipeline, BertForSequenceClassification, AutoTokenizer
|
2 |
+
model_name = 'smilegate-ai/kor_unsmile'
|
3 |
+
model = BertForSequenceClassification.from_pretrained(model_name)
|
4 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
5 |
+
|
6 |
+
pipe = TextClassificationPipeline(
|
7 |
+
model = model,
|
8 |
+
tokenizer = tokenizer,
|
9 |
+
device = -1, # cpu: -1, gpu: gpu number
|
10 |
+
return_all_scores = True,
|
11 |
+
function_to_apply = 'sigmoid'
|
12 |
+
)
|
13 |
+
|
14 |
+
from flask import Flask, jsonify, request
|
15 |
+
|
16 |
+
app = Flask(__name__)
|
17 |
+
|
18 |
+
@app.route('/detect', methods=["POST"])
|
19 |
+
def detect():
|
20 |
+
text = request.json["text"]
|
21 |
+
|
22 |
+
return jsonify(pipe(text))
|
23 |
+
|
24 |
+
if __name__ == "__main__":
|
25 |
+
app.run('0.0.0.0', 5050, False)
|
26 |
+
|