imseldrith commited on
Commit
b8c9b58
·
1 Parent(s): 6881dad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -16
app.py CHANGED
@@ -4,25 +4,35 @@ from parrot import Parrot
4
  import torch
5
  parrot = Parrot(model_tag="prithivida/parrot_paraphraser_on_T5")
6
 
 
 
 
 
 
7
  app = Flask(__name__)
8
 
9
- @app.route("/", methods=["GET", "POST"])
10
  def index():
11
- if request.method == "POST":
12
- text = request.form["text"]
13
- library = request.form["library"]
14
-
15
- if library == "transformers":
16
- model = transformers.AutoModelWithLMHead.from_pretrained("gpt2")
17
- paraphrased_text = transformers.generate(model, text)
18
- elif library == "parrot":
19
- paraphrased_text = parrot.augment(input_phrase=text, use_gpu=False)
20
- else:
21
- return "Error: Invalid library selected"
22
-
23
- return render_template("index.html", original_text=text, paraphrased_text=paraphrased_text)
24
-
25
  return render_template("index.html")
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  if __name__ == "__main__":
28
- app.run(host="0.0.0.0",port=7860)
 
4
  import torch
5
  parrot = Parrot(model_tag="prithivida/parrot_paraphraser_on_T5")
6
 
7
+ #from flask import Flask, request, render_template
8
+ #import parrot
9
+ #import transformers
10
+ import time
11
+
12
  app = Flask(__name__)
13
 
14
+ @app.route("/")
15
  def index():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  return render_template("index.html")
17
 
18
+ @app.route("/paraphrase", methods=["POST"])
19
+ def paraphrase():
20
+ text = request.form["text"]
21
+ model = request.form["model"]
22
+
23
+ if model == "parrot":
24
+ start_time = time.time()
25
+ paraphrased_text = parrot.augment(input_phrase=text, use_gpu=False)
26
+ processing_time = time.time() - start_time
27
+
28
+ elif model == "transformers":
29
+ start_time = time.time()
30
+ paraphrased_text = transformers.paraphrase(text)
31
+ processing_time = time.time() - start_time
32
+
33
+ processing_percentage = 100 * processing_time / 30
34
+
35
+ return render_template("paraphrase.html", original_text=text, paraphrased_text=paraphrased_text, processing_percentage=processing_percentage)
36
+
37
  if __name__ == "__main__":
38
+ app.run(host="0.0.0.0",port=7860)