File size: 1,285 Bytes
615f98d
1dcd1cd
615f98d
ffab851
571c49b
ffab851
 
 
 
615f98d
1dcd1cd
 
 
 
 
 
ffab851
 
615f98d
ffab851
 
1dcd1cd
 
 
ffab851
 
 
 
1dcd1cd
 
 
 
 
 
ffab851
caf9c68
 
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
import gradio as gr
from epub2txt import epub2txt

class GUI:
    def __init__(self):
        with gr.Blocks() as demo:
            self.out = gr.Markdown().attach_load_event(self.hello, None)
        
        demo.launch()

    def process(self, file):
        ch_list = epub2txt(file, outputlist=True)
        chapter_titles = epub2txt.content_titles
        title = epub2txt.title
        return f"# {title}\n\n" + "\n\n".join([f"## {ct}\n\n{c}" for ct, c in zip(chapter_titles, ch_list)])

    def greet(self, name):
        return "Hello " + name + "!!"

    def hello(self, profile: gr.OAuthProfile | None):
        if profile is None:
            with gr.Blocks(css=".lbtn {float: right;}") as demo:
                with gr.Row():
                    gr.LoginButton(elem_classes="lbtn")
            return (
                '# ePub summarization tool  '
                '<p style="text-align: center;">Login to access the tool.</p>'
            )
        with gr.Blocks(css=".lbtn {float: right;}") as demo:
            with gr.Row():
                gr.LoginButton(elem_classes="lbtn")
                gr.LogoutButton(elem_classes="lbtn")
        inp = gr.File(file_types=['.epub'])
        inp.change(self.process, inp, self.out)
        return self.greet(profile.name)

GUI()