Snigs98 commited on
Commit
5833b44
·
verified ·
1 Parent(s): efa6987

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the summarization model
5
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
6
+
7
+ def generate_summary(text):
8
+ input_length = len(text.split())
9
+ max_length = min(200, input_length + 20)
10
+ min_length = min(50, max_length // 2)
11
+
12
+ summary = summarizer(text, max_length=max_length, min_length=min_length, do_sample=True, temperature=0.7)
13
+ return summary[0]['summary_text']
14
+
15
+ # Define the Gradio interface
16
+ iface = gr.Interface(
17
+ fn=generate_summary,
18
+ inputs=gr.Textbox(lines=5, placeholder="Enter text here..."),
19
+ outputs=gr.Textbox(label="Summary"),
20
+ title="Text Summarization with Transformers",
21
+ description="Enter a text passage, and the model will generate a summarized version."
22
+ )
23
+
24
+ # Launch the GUI
25
+ iface.launch()