Arjav commited on
Commit
deeac04
1 Parent(s): f01dcf0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -1
app.py CHANGED
@@ -1 +1,38 @@
1
- import gradio as gr
2
  tokenizer = PegasusTokenizer.from_pretrained('nsi319/legal-pegasus')
3
  model = PegasusForConditionalGeneration.from_pretrained(
4
  "arjav/TOS-Pegasus")
5
  input_tokenized = tokenizer.encode(
6
  Terms, return_tensors='pt', max_length=1024, truncation=True)
7
  summary_ids = model.generate(input_tokenized,
8
  num_beams=9,
9
  no_repeat_ngram_size=3,
10
  length_penalty=2.0,
11
  min_length=50,
12
  max_length=150,
13
  early_stopping=True)
14
  summary = [tokenizer.decode(g, skip_special_tokens=True,
15
  clean_up_tokenization_spaces=False) for g in summary_ids][0]
16
  return summary
17
  inputs=gr.Textbox(
18
  label="Terms of Service", lines=2, placeholder="Enter Terms of Service"),
19
  outputs=gr.Textbox(label="Summary"),
20
  description=description,
21
  title=title,
22
  examples=[['account termination policy youtube will terminate a user s access to the service if under appropriate circumstances the user is determined to be a repeat infringer. youtube reserves the right to decide whether content violates these terms of service for reasons other than copyright infringement such as but not limited to pornography obscenity or excessive length. youtube may at any time without prior notice and in its sole discretion remove such content and or terminate a user s account for submitting such material in violation of these terms of service.']],
23
  allow_flagging='never'
24
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  tokenizer = PegasusTokenizer.from_pretrained('nsi319/legal-pegasus')
2
  model = PegasusForConditionalGeneration.from_pretrained(
3
  "arjav/TOS-Pegasus")
4
  input_tokenized = tokenizer.encode(
5
  Terms, return_tensors='pt', max_length=1024, truncation=True)
6
  summary_ids = model.generate(input_tokenized,
7
  num_beams=9,
8
  no_repeat_ngram_size=3,
9
  length_penalty=2.0,
10
  min_length=50,
11
  max_length=150,
12
  early_stopping=True)
13
  summary = [tokenizer.decode(g, skip_special_tokens=True,
14
  clean_up_tokenization_spaces=False) for g in summary_ids][0]
15
  return summary
16
  inputs=gr.Textbox(
17
  label="Terms of Service", lines=2, placeholder="Enter Terms of Service"),
18
  outputs=gr.Textbox(label="Summary"),
19
  description=description,
20
  title=title,
21
  examples=[['account termination policy youtube will terminate a user s access to the service if under appropriate circumstances the user is determined to be a repeat infringer. youtube reserves the right to decide whether content violates these terms of service for reasons other than copyright infringement such as but not limited to pornography obscenity or excessive length. youtube may at any time without prior notice and in its sole discretion remove such content and or terminate a user s account for submitting such material in violation of these terms of service.']],
22
  allow_flagging='never'
23
  )
24
+ import gradio as gr
25
+ import torch
26
+ from transformers import PegasusTokenizer, PegasusForConditionalGeneration
27
+
28
+
29
+ def summarize(Terms):
30
+ tokenizer = PegasusTokenizer.from_pretrained('nsi319/legal-pegasus')
31
+ model = PegasusForConditionalGeneration.from_pretrained(
32
+ "arjav/TOS-Pegasus")
33
+ input_tokenized = tokenizer.encode(
34
+ Terms, return_tensors='pt', max_length=1024, truncation=True)
35
+ summary_ids = model.generate(input_tokenized,
36
+ num_beams=9,
37
+ no_repeat_ngram_size=3,
38
+ length_penalty=2.0,
39
+ min_length=50,
40
+ max_length=150,
41
+ early_stopping=True)
42
+ summary = [tokenizer.decode(g, skip_special_tokens=True,
43
+ clean_up_tokenization_spaces=False) for g in summary_ids][0]
44
+
45
+ return summary
46
+
47
+
48
+ description = "Enter a Terms of Service document to summarize"
49
+ title = "Terms of Service Summarization"
50
+ interface = gr.Interface(fn=summarize,
51
+ inputs=gr.Textbox(
52
+ label="Terms of Service", lines=2, placeholder="Enter Terms of Service"),
53
+ outputs=gr.Textbox(label="Summary"),
54
+ description=description,
55
+ title=title,
56
+ examples=[['account termination policy youtube will terminate a user s access to the service if under appropriate circumstances the user is determined to be a repeat infringer. youtube reserves the right to decide whether content violates these terms of service for reasons other than copyright infringement such as but not limited to pornography obscenity or excessive length. youtube may at any time without prior notice and in its sole discretion remove such content and or terminate a user s account for submitting such material in violation of these terms of service.']],
57
+ allow_flagging='never'
58
+ )
59
+
60
+
61
+ interface.launch(share=True)