RawadAlghamdi commited on
Commit
8458323
·
verified ·
1 Parent(s): 43d8c9a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the summarization pipeline with the facebook/bart-large-cnn model
5
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
6
+
7
+ # Define the summarization function
8
+ def summarize(text):
9
+ # Generate summary with min_length=10 and max_length=100 tokens
10
+ summary = summarizer(text, min_length=10, max_length=100)
11
+ # Extract and return the summarized text
12
+ return summary[0]['summary_text']
13
+
14
+ # Define input and output components with clear labels
15
+ inputs = gr.Textbox(label="Input Text", lines=10)
16
+ outputs = gr.Textbox(label="Summary")
17
+
18
+ # Create the Gradio interface
19
+ iface = gr.Interface(
20
+ fn=summarize,
21
+ inputs=inputs,
22
+ outputs=outputs,
23
+ title="Text Summarizer",
24
+ description="Enter a long piece of text and get a summary using the BART model."
25
+ )
26
+
27
+ # Launch the interface
28
+ iface.launch()