Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,6 @@ import gradio as gr
|
|
| 2 |
import ebooklib
|
| 3 |
from ebooklib import epub
|
| 4 |
from bs4 import BeautifulSoup
|
| 5 |
-
import re
|
| 6 |
|
| 7 |
def extract_text_from_html(html_content):
|
| 8 |
soup = BeautifulSoup(html_content, 'html.parser')
|
|
@@ -22,10 +21,10 @@ def get_chapters(epub_file):
|
|
| 22 |
|
| 23 |
return chapters
|
| 24 |
|
| 25 |
-
def
|
| 26 |
chapters = get_chapters(epub_file)
|
| 27 |
chapter_list = [f"{title} ({length} characters)" for title, length, _ in chapters]
|
| 28 |
-
return
|
| 29 |
|
| 30 |
def get_chapter_content(epub_file, selected_chapter):
|
| 31 |
chapters = get_chapters(epub_file)
|
|
@@ -39,11 +38,10 @@ def create_interface():
|
|
| 39 |
gr.Markdown("# EPUB Chapter Extractor")
|
| 40 |
with gr.Row():
|
| 41 |
epub_input = gr.File(label="Upload EPUB File")
|
| 42 |
-
chapters_output = gr.Textbox(label="Available Chapters", interactive=False)
|
| 43 |
|
| 44 |
chapter_dropdown = gr.Dropdown(label="Select a chapter", choices=[], interactive=True)
|
| 45 |
|
| 46 |
-
epub_input.upload(
|
| 47 |
|
| 48 |
read_button = gr.Button("Read Chapter")
|
| 49 |
|
|
|
|
| 2 |
import ebooklib
|
| 3 |
from ebooklib import epub
|
| 4 |
from bs4 import BeautifulSoup
|
|
|
|
| 5 |
|
| 6 |
def extract_text_from_html(html_content):
|
| 7 |
soup = BeautifulSoup(html_content, 'html.parser')
|
|
|
|
| 21 |
|
| 22 |
return chapters
|
| 23 |
|
| 24 |
+
def update_dropdown(epub_file):
|
| 25 |
chapters = get_chapters(epub_file)
|
| 26 |
chapter_list = [f"{title} ({length} characters)" for title, length, _ in chapters]
|
| 27 |
+
return gr.Dropdown(choices=chapter_list)
|
| 28 |
|
| 29 |
def get_chapter_content(epub_file, selected_chapter):
|
| 30 |
chapters = get_chapters(epub_file)
|
|
|
|
| 38 |
gr.Markdown("# EPUB Chapter Extractor")
|
| 39 |
with gr.Row():
|
| 40 |
epub_input = gr.File(label="Upload EPUB File")
|
|
|
|
| 41 |
|
| 42 |
chapter_dropdown = gr.Dropdown(label="Select a chapter", choices=[], interactive=True)
|
| 43 |
|
| 44 |
+
epub_input.upload(update_dropdown, epub_input, chapter_dropdown)
|
| 45 |
|
| 46 |
read_button = gr.Button("Read Chapter")
|
| 47 |
|