File size: 762 Bytes
6721178
 
 
 
13058bd
8888132
 
149b795
6721178
 
8888132
ffb87bd
6721178
 
 
8888132
6721178
 
 
 
8888132
6721178
8888132
 
 
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
# Hugging FaceのSpaces側のコード
from transformers import AutoModelForCausalLM, AutoTokenizer
from flask import Flask, request, jsonify
import torch

app = Flask(__name__)

model_name = "rinna/youri-7b-chat"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name)

@app.route("/", methods=['POST'])
def chat():
    input_data = request.json
    input_text = input_data['input']

    # 推論処理
    inputs = tokenizer.encode(input_text, return_tensors='pt')
    outputs = model.generate(inputs, max_length=50, num_return_sequences=1)
    response_text = tokenizer.decode(outputs[0], skip_special_tokens=True)

    return jsonify({"output": response_text})

if __name__ == "__main__":
    app.run()