BookSumBeta / app.py
npc0's picture
Update app.py
b2f14ff
raw
history blame
1.11 kB
import gradio as gr
from epub2txt import epub2txt
class GUI:
def __init__(self, *args, **kwargs):
with gr.Blocks() as demo:
with gr.Row():
self.out = gr.Markdown(scale=2).attach_load_event(self.hello, None)
gr.LoginButton()
gr.LogoutButton()
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(
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:
return (
'# ePub summarization tool '
'<p style="text-align: center;">Login to access the tool.</p>'
)
return self.greet(profile.name)
GUI()