hihi222 commited on
Commit
32b7bc8
·
1 Parent(s): 059040a

added changes

Browse files
Files changed (2) hide show
  1. app.py +36 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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,2 @@
 
 
 
1
+ transformers
2
+ torch