hihi222 commited on
Commit
226442e
·
1 Parent(s): 3f4a22a
Files changed (2) hide show
  1. app.py +31 -2
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,7 +1,36 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  def greet(name):
4
  return "Hello " + name + "!!"
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ import re
5
+
6
+ pipe = pipeline("summarization", model="kkasiviswanath/bart_summarizer_deploy_v1")
7
+
8
+ def summarize_email(email_body, pipe):
9
+ # Tokenize the input text
10
+ input_tokens = pipe.tokenizer(email_body, return_tensors='pt', truncation=False)
11
+ input_length = input_tokens['input_ids'].shape[1]
12
+
13
+ # Adjust max_length to be a certain percentage of the input length
14
+ adjusted_max_length = max(3, int(input_length * 0.6)) # Ensure a minimum length
15
+ # Generate summary with dynamic max_length
16
+ gen_kwargs = {
17
+ "length_penalty": 2.0,
18
+ "num_beams": 5,
19
+ "max_length": adjusted_max_length,
20
+ "min_length": 3
21
+ }
22
+
23
+ summary = pipe(email_body, **gen_kwargs)[0]['summary_text']
24
+ return summary
25
+
26
+ # Generate summaries for the test dataset
27
+ def generate_summary(text):
28
+ email_body = re.sub(r'\s+', ' ', re.sub(r'[^\w\s]', '', text).strip())
29
+ summary = summarize_email(email_body, pipe)
30
+ return summary
31
 
32
  def greet(name):
33
  return "Hello " + name + "!!"
34
 
35
+ demo = gr.Interface(fn=generate_summary, inputs="text", outputs="text")
36
+ demo.launch(share=True)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ transformers