File size: 1,021 Bytes
615f98d
1dcd1cd
615f98d
ffab851
970a425
9f8e6cc
8341baf
f5f74ce
9f8e6cc
 
f5f74ce
362dc0e
 
ffab851
615f98d
1dcd1cd
b2f14ff
1dcd1cd
 
f5f74ce
e81588f
9f8e6cc
1dcd1cd
ffab851
 
f5f74ce
 
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
import gradio as gr
from epub2txt import epub2txt

class GUI:
    def __init__(self, *args, **kwargs):
        with gr.Blocks() as demo:
            with gr.Row():
                gr.Markdown(scale=2).attach_load_event(self.hello, None)
                gr.LoginButton()
                gr.LogoutButton()
            self.out = gr.Markdown()
            inp = gr.File(file_types=['.epub'])
            inp.change(self.process, inp, self.out)
        demo.launch()

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

    def hello(self, profile: gr.OAuthProfile | None):
        if profile is None:
            return '# ePub summarization tool\n\nLogin to access the tool.'
        return f"# ePub summarization tool\n\nWelcome {profile.name}!!"

GUI()