Spaces:
Sleeping
Sleeping
File size: 885 Bytes
cfab274 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
from flask import Flask, request, jsonify
from transformers import MT5ForConditionalGeneration, T5Tokenizer
import torch
app = Flask(__name__)
model = MT5ForConditionalGeneration.from_pretrained('iliemihai/mt5-base-romanian-diacritics')
tokenizer = T5Tokenizer.from_pretrained('iliemihai/mt5-base-romanian-diacritics', legacy=False)
@app.route('/generate', methods=['POST'])
def generate_text():
input_text = request.get_json()['input_text']
if input_text is None:
return jsonify({'error': 'No input text provided'})
inputs = tokenizer(input_text, max_length=256, truncation=True, return_tensors="pt")
outputs = model.generate(input_ids=inputs["input_ids"], attention_mask=inputs["attention_mask"])
output = tokenizer.decode(outputs[0], skip_special_tokens=True)
return jsonify({'output': output})
if __name__ == '__main__':
app.run(debug=False) |