Spaces:
Running
Running
File size: 867 Bytes
d4399fb 996d266 d4399fb 15040ef d4399fb 63c6162 |
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 |
from flask import Flask, request
from transformers import GPT2Tokenizer, GPT2LMHeadModel
app = Flask(__name__)
# Load the GPT-2 model and tokenizer
tokenizer = GPT2Tokenizer.from_pretrained('gpt2')
model = GPT2LMHeadModel.from_pretrained('gpt2')
app.route('/paraphrase', methods=['POST'])
def paraphrase():
# Get the input text from the request
input_text = request.form.get('input_text')
# Encode the input text using the tokenizer
input_ids = tokenizer.encode(input_text, return_tensors='pt')
# Generate the paraphrased text using the model
output = model.generate(input_ids, max_length=1024, top_k=5, top_p=0.95, num_return_sequences=1)
output_text = tokenizer.decode(output[0], skip_special_tokens=True)
# Return the paraphrased text
return output_text
if __name__ == '__main__':
app.run(host="0.0.0.0", port=7860)
|