Sibinraj commited on
Commit
6b2f148
·
verified ·
1 Parent(s): 438150a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -16
app.py CHANGED
@@ -2,14 +2,12 @@ import torch
2
  import gradio as gr
3
  from transformers import pipeline
4
  from transformers import T5ForConditionalGeneration, T5Tokenizer
5
- model_path='Sibinraj/T5-finetuned-dialogue_sumxx'
 
6
  model = T5ForConditionalGeneration.from_pretrained(model_path)
7
  tokenizer = T5Tokenizer.from_pretrained(model_path)
8
 
9
-
10
-
11
- def summarize_text(text,max_length):
12
- print(max_length)
13
  # Preprocess the text
14
  inputs = tokenizer.encode(
15
  "summarize: " + text,
@@ -19,27 +17,30 @@ def summarize_text(text,max_length):
19
  padding='max_length'
20
  )
21
 
22
- # Validate max_length
23
- # if not isinstance(max_length, int) or max_length <= 0:
24
- # max_length = 50
25
-
26
  # Generate the summary
27
  summary_ids = model.generate(
28
  inputs,
29
- max_length=max_length+2,
30
  min_length=max_length,
31
  num_beams=5,
32
  )
33
- print(summary_ids)
34
 
35
- # Decode and return the summary
36
- return tokenizer.decode(summary_ids[0], skip_special_tokens=True)
 
 
 
 
 
 
 
37
 
38
  interface = gr.Interface(
39
  fn=summarize_text,
40
  inputs=[
41
  gr.Textbox(lines=10, placeholder='Enter Text Here...', label='Input text'),
42
- gr.Slider(minimum=10, maximum=150, step=1, label='Max Length')
 
43
  ],
44
  outputs=gr.Textbox(label='Summarized Text'),
45
  title='Text Summarizer using T5-finetuned-dialogue_sumxx',
@@ -50,5 +51,3 @@ interface = gr.Interface(
50
  )
51
 
52
  interface.launch()
53
-
54
-
 
2
  import gradio as gr
3
  from transformers import pipeline
4
  from transformers import T5ForConditionalGeneration, T5Tokenizer
5
+
6
+ model_path = 'Sibinraj/T5-finetuned-dialogue_sumxx'
7
  model = T5ForConditionalGeneration.from_pretrained(model_path)
8
  tokenizer = T5Tokenizer.from_pretrained(model_path)
9
 
10
+ def summarize_text(text, max_length, show_length):
 
 
 
11
  # Preprocess the text
12
  inputs = tokenizer.encode(
13
  "summarize: " + text,
 
17
  padding='max_length'
18
  )
19
 
 
 
 
 
20
  # Generate the summary
21
  summary_ids = model.generate(
22
  inputs,
23
+ max_length=max_length + 2,
24
  min_length=max_length,
25
  num_beams=5,
26
  )
 
27
 
28
+ # Decode the summary
29
+ summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
30
+
31
+ # If show_length is True, append the length of the summary
32
+ if show_length:
33
+ summary_length = len(summary.split())
34
+ summary = f"{summary}\n\n(Summary length: {summary_length} words)"
35
+
36
+ return summary
37
 
38
  interface = gr.Interface(
39
  fn=summarize_text,
40
  inputs=[
41
  gr.Textbox(lines=10, placeholder='Enter Text Here...', label='Input text'),
42
+ gr.Slider(minimum=10, maximum=150, step=1, label='Max Length'),
43
+ gr.Checkbox(label='Show summary length')
44
  ],
45
  outputs=gr.Textbox(label='Summarized Text'),
46
  title='Text Summarizer using T5-finetuned-dialogue_sumxx',
 
51
  )
52
 
53
  interface.launch()