-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
27 lines (21 loc) · 802 Bytes
/
app.py
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
from flask import Flask, render_template, request
from transformers import pipeline
app = Flask(__name__)
generator = pipeline('text-generation', model = 'gpt2')
global_results = []
@app.route("/")
def index():
return render_template('index.html')
@app.route("/restart", methods=["POST"])
def restart():
global global_results
global_results = []
return render_template("index.html", results=global_results)
@app.route("/get_writing", methods=["POST"])
def get_writing():
global global_results
if request.method == "POST":
response = request.form.get("response")
result = generator(response, max_length=50, num_return_sequences=1)[0]
global_results.append(result["generated_text"])
return render_template("index.html", results=global_results)