Spaces:
Sleeping
Sleeping
Tolga
commited on
Commit
β’
529cfcc
1
Parent(s):
23e2e3f
Update app.py
Browse files
app.py
CHANGED
@@ -6,9 +6,9 @@ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
|
6 |
import torch
|
7 |
|
8 |
#### Model 1 ####
|
9 |
-
model_name = "snrspeaks/t5-one-line-summary"
|
10 |
-
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
11 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
12 |
|
13 |
#### Model 2 ####
|
14 |
summarizer = pipeline(
|
@@ -31,15 +31,15 @@ params = {
|
|
31 |
|
32 |
#### Run the model 1####
|
33 |
def summarize(text):
|
34 |
-
input_ids = tokenizer.encode("summarize: " + text, return_tensors="pt", add_special_tokens=True)
|
35 |
-
generated_id = model.generate(input_ids=input_ids,num_beams=5,max_length=50,repetition_penalty=2.5,length_penalty=1,early_stopping=True,num_return_sequences=1)
|
36 |
-
pred = tokenizer.decode(generated_id[0], skip_special_tokens=True, clean_up_tokenization_spaces=True)
|
37 |
|
38 |
result = summarizer(text, **params)
|
39 |
pred2 = result[0]['summary_text']
|
40 |
|
41 |
-
output = pred + "\n\n" + pred2
|
42 |
-
return
|
43 |
|
44 |
#### Display summarized text ####
|
45 |
with gr.Blocks() as demo:
|
|
|
6 |
import torch
|
7 |
|
8 |
#### Model 1 ####
|
9 |
+
#model_name = "snrspeaks/t5-one-line-summary"
|
10 |
+
#model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
11 |
+
#tokenizer = AutoTokenizer.from_pretrained(model_name)
|
12 |
|
13 |
#### Model 2 ####
|
14 |
summarizer = pipeline(
|
|
|
31 |
|
32 |
#### Run the model 1####
|
33 |
def summarize(text):
|
34 |
+
#input_ids = tokenizer.encode("summarize: " + text, return_tensors="pt", add_special_tokens=True)
|
35 |
+
#generated_id = model.generate(input_ids=input_ids,num_beams=5,max_length=50,repetition_penalty=2.5,length_penalty=1,early_stopping=True,num_return_sequences=1)
|
36 |
+
#pred = tokenizer.decode(generated_id[0], skip_special_tokens=True, clean_up_tokenization_spaces=True)
|
37 |
|
38 |
result = summarizer(text, **params)
|
39 |
pred2 = result[0]['summary_text']
|
40 |
|
41 |
+
#output = pred + "\n\n" + pred2
|
42 |
+
return pred2
|
43 |
|
44 |
#### Display summarized text ####
|
45 |
with gr.Blocks() as demo:
|