parahase / app.py
imseldrith's picture
Update app.py
0118db1
raw
history blame
758 Bytes
from flask import Flask, request, render_template
import requests
import json
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/paraphrase', methods=['POST'])
def paraphrase():
text = request.form['text']
headers = {
'Content-Type': 'application/json',
}
data = {"text": text}
response = requests.post('https://api.openai.com/v1/engines/paraphrase/jobs', headers=headers, json=data)
if response.status_code == 200:
response_text = response.json()['choices'][0]['text']
return render_template('paraphrase.html', response_text=response_text)
else:
return 'An error occured'
if __name__ == '__main__':
app.run(host="0.0.0.0", port=7860)