-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
48 lines (42 loc) · 1.59 KB
/
main.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
from transformers import pipeline
from search import searchIt
from scrape import scrape
import json
from math import floor
from further import furtherSearch
from getImages import getImagesWithDesc
def json_output(query: str, summary:str, relatedArticles:list, keywords:list, imageLinks:list, descriptions:list):
'''
to create a JSON output object
'''
output = {
"input": query,
"summary": summary,
"sources": relatedArticles,
"keywords": keywords,
"imageLinks": imageLinks,
"descriptions": descriptions
}
return json.dumps(output, indent=4)
def main():
query = input("enter the query: ")
article_urls = searchIt(query)
text = scrape(article_urls)[:floor(1024*2.9)]
model = "facebook/bart-large-cnn"
customise = input("wish to customise the model[Y/N]: ").lower()
if customise == "y":
max = input("Max length: ")
min = input("Min Length: ")
summariser = pipeline("summarization", model=model)
summary = summariser(text, max_length=max, min_length=min, do_sample=False)[0]['summary_text']
else:
summariser = pipeline("summarization", model=model)
summary = summariser(text, max_length=250, min_length=50, do_sample=False)[0]['summary_text']
keywords = furtherSearch(text)
images, articleDescriptions = getImagesWithDesc(query)
# the JSON output object here:
output = json_output(query, summary, article_urls, keywords=keywords, imageLinks=images, descriptions=articleDescriptions)
print(output)
return output
if __name__ == "__main__":
main()