File size: 1,316 Bytes
837fdb6
84ea2c9
837fdb6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84ea2c9
837fdb6
 
 
 
 
 
84ea2c9
837fdb6
 
 
 
 
 
 
 
 
 
84ea2c9
837fdb6
84ea2c9
 
837fdb6
 
 
4619c05
837fdb6
 
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
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')

    #link = 'https://www.youtube.com/watch?v=lCnHfTHkhbE'
    lexrank_switch = True
    html = ''
    images = []
    html, images = su.getSummary(link, lexrank_switch, rpunkt_switch)
    #images = su.getSummaryImage(link, lexrank_switch, rpunkt_switch)
    print(html)

    files = os.listdir('workdir/')
    print('local files: ',files)

    #image_path = 'workdir/lion.jpg'
    #im = Image.open(image_path)
    #images.append(im)
    #with Image.open(open(image_path,'rb')) as im:
    #    images.append(im)
        #images.append(im.rotate(90))
    
    #images[0].save("newlion.png")
 
    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()