Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,23 @@
|
|
1 |
-
from flask import Flask, request,
|
2 |
-
from transformers import
|
3 |
|
4 |
-
# Initialize Flask app
|
5 |
app = Flask(__name__)
|
6 |
|
7 |
-
# Load the fine-tuned model
|
8 |
-
|
9 |
-
|
10 |
|
11 |
@app.route('/')
|
12 |
-
def
|
13 |
return render_template('index.html')
|
14 |
|
15 |
-
@app.route('/
|
16 |
-
def
|
17 |
-
article = request.form
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
headline = prediction[0]['generated_text']
|
23 |
-
return jsonify({"headline": headline})
|
24 |
-
except Exception as e:
|
25 |
-
return jsonify({"error": str(e)}), 500
|
26 |
|
27 |
-
if __name__ ==
|
28 |
-
app.run(debug=True)
|
|
|
1 |
+
from flask import Flask, request, render_template
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
|
|
|
4 |
app = Flask(__name__)
|
5 |
|
6 |
+
# Load the fine-tuned model and tokenizer
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained("path/to/finetune_model")
|
8 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("path/to/finetune_model")
|
9 |
|
10 |
@app.route('/')
|
11 |
+
def home():
|
12 |
return render_template('index.html')
|
13 |
|
14 |
+
@app.route('/summarize', methods=['POST'])
|
15 |
+
def summarize():
|
16 |
+
article = request.form['article']
|
17 |
+
inputs = tokenizer.encode(article, return_tensors="pt", truncation=True)
|
18 |
+
summary_ids = model.generate(inputs, max_length=50, min_length=15, length_penalty=2.0, num_beams=4, early_stopping=True)
|
19 |
+
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
20 |
+
return render_template('index.html', summary=summary)
|
|
|
|
|
|
|
|
|
21 |
|
22 |
+
if __name__ == '__main__':
|
23 |
+
app.run(debug=True)
|