Spaces:
Sleeping
Sleeping
from flask import Flask, request, render_template | |
import requests | |
import json | |
app = Flask(__name__) | |
def index(): | |
return render_template('index.html') | |
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) | |