|
import gradio as gr |
|
from PIL import Image |
|
import os |
|
import summarizer as su |
|
import nltk |
|
|
|
|
|
def image_mod(rpunkt_switch, link): |
|
|
|
if len(link)==0: |
|
return 'Error: No link provided', None |
|
|
|
nltk_file = 'nltk_data/tokenizers/punkt.zip' |
|
home_pc = '/Users/hujo/' |
|
home_hf = '/home/user/' |
|
if os.path.exists(home_pc+nltk_file) or os.path.exists(home_hf+nltk_file): |
|
print('nltk punkt file exists in ', nltk_file) |
|
else: |
|
nltk.download('punkt') |
|
|
|
|
|
lexrank_switch = True |
|
html = '' |
|
images = [] |
|
html, images = su.getSummary(link, lexrank_switch, rpunkt_switch) |
|
|
|
print(html) |
|
|
|
files = os.listdir('workdir/') |
|
print('local files: ',files) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print('images',images) |
|
|
|
return html, images |
|
|
|
|
|
demo = gr.Interface(image_mod, |
|
[gr.Checkbox(label='Restore runctuation'), "text"] , ["html", gr.Gallery()], |
|
allow_flagging="never") |
|
|
|
if __name__ == "__main__": |
|
demo.launch() |
|
|