File size: 986 Bytes
a64a86e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from flask import Flask, request, jsonify
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
import os

local_path = "./models/roberta-large"

model_id = "klue/roberta-large"

if os.path.exists(local_path):
    print("πŸ”„ λͺ¨λΈ λ‘œμ»¬μ—μ„œ λ‘œλ“œ 쀑...")
    model = AutoModelForSequenceClassification.from_pretrained(local_path)
    tokenizer = AutoTokenizer.from_pretrained(local_path)
else:
    print("⬇️ λͺ¨λΈ ν—ˆκΉ…νŽ˜μ΄μŠ€μ—μ„œ λ‹€μš΄λ‘œλ“œ 쀑...")
    model = AutoModelForSequenceClassification.from_pretrained(model_id)
    tokenizer = AutoTokenizer.from_pretrained(model_id)
    os.makedirs(local_path, exist_ok=True)
    model.save_pretrained(local_path)
    tokenizer.save_pretrained(local_path)

app = Flask(__name__)


@app.route("/generate", methods=["POST"])
def generate():
    data = request.json
    print(data)
    return jsonify({"result": "success"})


if __name__ == "__main__":
    app.run(host="0.0.0.0", port=7860)