I'm trying to build the GUI in python using Tkinter for an Extractive Summarization program, that takes url and word count as input parameters to generate the summary of text retrieved from Webpage. The following is the code of the summarizer in general:
from gensim.summarization.summarizer import summarize
import requests
from bs4 import BeautifulSoup
from urllib.request import urlopen
def get_text(url):
page = urlopen(url)
soup = BeautifulSoup(page, "lxml")
text = ' '.join(map(lambda p: p.text, soup.find_all('p')))
return soup.title.text, text
number_of_words = 0
url = input('Enter URL - ')
w = int(input('Enter Word Count of Summary - '))
text = get_text(url)
number_of_words2 = len(str(text).split())
#perc = int(input('Enter Ratio Percentage of Summary - ')) # if-else to keep it under 100
#if ((perc<=1) and (perc<0)):
# summary = summarize(str(text), ratio = 0.30)
#else:
#
summary = summarize(str(text), word_count = w)
lines = summary.split()
number_of_words += len(lines)
soup = BeautifulSoup(urlopen(url))
title = soup.title.get_text()
print('\nSummary:\n\n', title)
print(summary)
print('\n \nMetrics - \n')
print('Original text character length - ', len(str(text)))
print('Summarized text character length - ', len(summary))
print('Original text word count - ', number_of_words2)
print('Summarized text word count - ', number_of_words)
This works well seperately, and I also have the build GUI successfully by the code below:-
import tkinter as tk
from tkinter import *
from tkinter import ttk
from tkinter.scrolledtext import *
import tkinter.filedialog
from gensim.summarization.summarizer import summarize
import requests
from bs4 import BeautifulSoup
from urllib.request import urlopen
r = Tk()
r.title('Lumos Summarify')
r.geometry("500x600")
t = Label(r, text = 'Lumos Summarify', font = ("Times New Roman", 20), justify = CENTER).pack()
t2 = Label(r, text = 'Extractive Summarization in NLP using Gensim', font = ("Times New Roman", 14), justify = CENTER).pack()
w = Label(r, text = 'Enter URL - ', font=('Arial 8'), justify = RIGHT).pack(pady=5)
raw_entry=StringVar()
url = Entry(r,textvariable=raw_entry,width=50).pack(pady=5)
w2 = Label(r, text = 'Enter word-count - ', font=('Arial 8')).pack(pady=5)
raw_entry2=IntVar()
word = Entry(r,textvariable=raw_entry2,width=50).pack(pady=5)
def get_text(url):
page = urlopen(url)
soup = BeautifulSoup(page, "lxml")
text = ' '.join(map(lambda p: p.text, soup.find_all('p')))
return soup.title.text, text
def summarize_s():
text = get_text(url)
summary = summarize(str(text), word_count = word)
return summary
button_submit = Button(r, text ="Summarize", command=summarize_s)
button_submit.config(width=20, height=1)
button_submit.pack(pady = 5)
#T = Text(r, height = 30, width = 60)
#T.pack()
#T.insert(tk.END, summary)
tab3_display_text = ScrolledText(r,height=40,width=150)
tab3_display_text.pack(pady=5)
#tab3_display_text.insert(tk.END,summary)
r.mainloop()
The output of the code above comes to be
[]
I can't just integrate them well to work without any errors, as it throws some errors each time I try to do something, and for the same I have commented out a few lines of code.
I want to print the summary and the metrics in the text area below!