Maram-almasary commited on
Commit
04fc75c
·
verified ·
1 Parent(s): db28b3f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import torch
4
+
5
+
6
+ # Load the BART model for summarization
7
+ summarizer = pipeline("summarization",
8
+ model="facebook/bart-large-cnn")
9
+
10
+ # Function to summarize the input text
11
+ def summarize_text(input_text):
12
+
13
+
14
+ # Ensure the text is not too short for summarization
15
+ if len(input_text.split()) < 10:
16
+ return "Please provide a longer text for summarization."
17
+
18
+ # Summarize the text using BART
19
+ summarized_output = summarizer(input_text,
20
+ min_length=10,
21
+ max_length=100,
22
+ do_sample=False)
23
+ return summarized_output[0]['summary_text']
24
+
25
+ # Create the Gradio interface
26
+ interface = gr.Interface(
27
+ fn=summarize_text, # Function that summarizes the input
28
+
29
+ inputs=gr.Textbox(label="Input Text",
30
+ lines=10,
31
+ placeholder="Enter a long piece of text here..."), # Text input field
32
+
33
+
34
+ outputs=gr.Textbox(label="Summarized Text"), # Output field for the summarized text
35
+
36
+ title="Text Summarizer", # Title of the app
37
+
38
+ description="Enter a text, and this app will summarize it using the BART model. The summary will be between 10 and 100 tokens.", # Description
39
+
40
+ live=False, # Disable live updates while typing
41
+ )
42
+
43
+ # Launch the interface
44
+ interface.launch()