KilaruKusuma commited on
Commit
773d3a5
·
verified ·
1 Parent(s): 4641253

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -25
app.py CHANGED
@@ -1,29 +1,25 @@
1
- from flask import Flask, request, jsonify
2
  from transformers import pipeline
3
 
4
- app = Flask(__name__)
5
-
6
- # Load the summarization pipeline
7
  pipe = pipeline("summarization", model="Falconsai/text_summarization")
8
 
9
- @app.route('/')
10
- def home():
11
- return "Text Summarization API is running!"
12
-
13
- @app.route('/summarize', methods=['POST'])
14
- def summarize():
15
- try:
16
- data = request.json
17
- text = data.get("text", "")
18
-
19
- if not text:
20
- return jsonify({"error": "No text provided"}), 400
21
-
22
- summary = pipe(text, max_length=150, min_length=30, do_sample=False)
23
- return jsonify({"summary": summary[0]['summary_text']})
24
-
25
- except Exception as e:
26
- return jsonify({"error": str(e)}), 500
27
-
28
- if __name__ == '__main__':
29
- app.run(debug=True)
 
1
+ import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load the summarization model
 
 
5
  pipe = pipeline("summarization", model="Falconsai/text_summarization")
6
 
7
+ # Define the function to summarize text
8
+ def summarize_text(text):
9
+ if not text.strip():
10
+ return "Please enter some text to summarize."
11
+ summary = pipe(text, max_length=150, min_length=30, do_sample=False)
12
+ return summary[0]['summary_text']
13
+
14
+ # Create Gradio interface
15
+ iface = gr.Interface(
16
+ fn=summarize_text,
17
+ inputs=gr.Textbox(lines=5, placeholder="Enter text to summarize..."),
18
+ outputs="text",
19
+ title="Text Summarization App",
20
+ description="Enter text, and the AI will generate a concise summary.",
21
+ )
22
+
23
+ # Launch the Gradio app
24
+ if __name__ == "__main__":
25
+ iface.launch()