-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamService_Summarizer.py
55 lines (41 loc) · 2.28 KB
/
amService_Summarizer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#####################
#### DEPRECATED SERVICE ##########
##### now using ChatGPT instead ########
################################
import json
from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained('facebook/bart-large-cnn')
model = AutoModelForSeq2SeqLM.from_pretrained('facebook/bart-large-cnn')
summarizer = pipeline('summarization', model=model, tokenizer=tokenizer)
###### Call Summarization pipeline and get data ######
def summarization_caller(article_in):
# print(article_in)
default_summary = summarizer(article_in, truncation=True)
# long_summary = summarizer(news_item['text_article'], max_length=330, min_length=100, truncation=False)
# short_summary = summarizer(news_item['text_article'], max_length=50, min_length=10, truncation=False)
# return {'default_summary': default_summary[0]['summary_text'],
# 'long_summary': long_summary[0]['summary_text'],
# 'short_summary': short_summary[0]['summary_text']}
# return default_summary Original, gives a list
return default_summary[0]["summary_text"] #Just text
def summmary_ChatGPT(text):
# Preprocess the text
preprocessed_text = preprocess_text(text)
# Join preprocessed text back into a string
preprocessed_text_str = ' '.join(preprocessed_text)
# Summarize the text
summary = summarize_with_gpt(preprocessed_text_str)
# Perform NER
named_entities = perform_ner(preprocessed_text_str)
## Testing
summary = summarization_caller("""When Sebastian Thrun started working on self-driving cars at Google in 2007,
few people outside of the company took him seriously. “I can tell you very senior
CEOs of major American car companies would shake my hand and turn away because I
wasn’t worth talking to,” said Thrun, now the co-founder and CEO of online higher
education startup Udacity, in an interview with Recode earlier this week.
The Mona Lisa and the Statue of David were on display in the MOMA New York.
COVID-19 is a devastating virus currently ravaging the world.
A little less than a decade later, dozens of self-driving startups have cropped up
while automakers around the world clamor, wallet in hand, to secure their place in
the fast-moving world of fully automated transportation.""")
print("Summary:", summary)