Muhammad Anas Akhtar commited on
Commit
0a1f192
·
verified ·
1 Parent(s): 07601d8

File Updated

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import gradio as gr
3
+ from transformers import pipeline
4
+
5
+ # Initialize the summarization pipeline
6
+ Text_summary = pipeline("summarization", model="facebook/bart-large-cnn", torch_dtype=torch.bfloat16)
7
+
8
+ # Define a function to estimate token count from word count
9
+ def estimate_tokens(word_count):
10
+ # Approximate tokens as 1.5 times the word count
11
+ return int(word_count * 1.5)
12
+
13
+ # Define the summarization function
14
+ def summary(input, word_count):
15
+ # Convert word count to token count
16
+ max_length = estimate_tokens(word_count)
17
+ min_length = max(10, max_length // 2) # Set a reasonable minimum length
18
+ output = Text_summary(input, max_length=max_length, min_length=min_length)
19
+ return output[0]['summary_text']
20
+
21
+ # Close any existing Gradio instances
22
+ gr.close_all()
23
+
24
+ # Set up the Gradio interface
25
+ Demo = gr.Interface(
26
+ fn=summary,
27
+ inputs=[
28
+ gr.Textbox(label="Input Text To Summarize", lines=20),
29
+ gr.Slider(
30
+ label="Summary Length (Words Approx.)",
31
+ minimum=50, maximum=300, step=10, value=130
32
+ )
33
+ ],
34
+ outputs=[gr.Textbox(label="Summarized Text", lines=4)],
35
+ title="Text_Summarize_App",
36
+ description="THIS APPLICATION WILL BE USED TO SUMMARIZE THE TEXT"
37
+ )
38
+
39
+ # Launch the app with a public link
40
+ Demo.launch(share=True)