Spaces:
Runtime error
Runtime error
app
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, render_template, request, jsonify
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
app = Flask(__name__)
|
5 |
+
|
6 |
+
# Load the Hugging Face summarization model
|
7 |
+
summarizer = pipeline("summarization", model="Ramji/bart-cn-large-medical-summary")
|
8 |
+
|
9 |
+
# Route to display the home page
|
10 |
+
@app.route('/')
|
11 |
+
def home():
|
12 |
+
return render_template('index.html')
|
13 |
+
|
14 |
+
# Route to handle the summarization request
|
15 |
+
@app.route('/summarize', methods=['POST'])
|
16 |
+
def summarize():
|
17 |
+
data = request.get_json() # Get the data from the client-side request
|
18 |
+
text = data.get("text")
|
19 |
+
if text:
|
20 |
+
# Perform summarization
|
21 |
+
summary = summarizer(text)
|
22 |
+
return jsonify({"summary": summary[0]['summary_text']})
|
23 |
+
else:
|
24 |
+
return jsonify({"error": "No text provided"}), 400
|
25 |
+
|
26 |
+
if __name__ == '__main__':
|
27 |
+
app.run(debug=True)
|