Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
3 |
+
|
4 |
+
tokenizer = AutoTokenizer.from_pretrained("nsi319/legal-pegasus")
|
5 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("nsi319/legal-pegasus")
|
6 |
+
|
7 |
+
def summarise(text):
|
8 |
+
input_tokenized = tokenizer.encode(text, return_tensors='pt',max_length=1024,truncation=True)
|
9 |
+
summary_ids = model.generate(input_tokenized,
|
10 |
+
num_beams=9,
|
11 |
+
no_repeat_ngram_size=3,
|
12 |
+
length_penalty=2.0,
|
13 |
+
min_length=150,
|
14 |
+
max_length=250,
|
15 |
+
early_stopping=True)
|
16 |
+
return [tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=False) for g in summary_ids][0]
|
17 |
+
|
18 |
+
|
19 |
+
|
20 |
+
iface = gr.Interface(fn=summarise, inputs="text", outputs="text")
|
21 |
+
iface.launch()
|