Commit ·
134c83d
1
Parent(s): 04323ec
Add Auto-Play feature for continuous document reading
Browse files
app.py
CHANGED
|
@@ -98,6 +98,7 @@ with gr.Blocks(title="Tamil Comic & Manga Reader AI") as demo:
|
|
| 98 |
with gr.Column(scale=3, min_width=300):
|
| 99 |
comic_upload = gr.File(label="Upload (PDF/EPUB)", file_types=[".pdf", ".epub"], height=80)
|
| 100 |
voice_style_comic = gr.Dropdown(choices=VOICE_STYLES, value=VOICE_STYLES[0], label="Voice")
|
|
|
|
| 101 |
read_page_btn = gr.Button("🔊 Read This Page", variant="primary")
|
| 102 |
|
| 103 |
comic_text = gr.Textbox(label="Original", lines=3)
|
|
@@ -140,6 +141,29 @@ with gr.Blocks(title="Tamil Comic & Manga Reader AI") as demo:
|
|
| 140 |
outputs=[comic_text, comic_tamil, comic_audio]
|
| 141 |
)
|
| 142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
# Standard Logic (Text Only)
|
| 144 |
submit_std.click(
|
| 145 |
process_standard_pipeline,
|
|
|
|
| 98 |
with gr.Column(scale=3, min_width=300):
|
| 99 |
comic_upload = gr.File(label="Upload (PDF/EPUB)", file_types=[".pdf", ".epub"], height=80)
|
| 100 |
voice_style_comic = gr.Dropdown(choices=VOICE_STYLES, value=VOICE_STYLES[0], label="Voice")
|
| 101 |
+
auto_play = gr.Checkbox(label="🔄 Auto-Play Next Page", value=False)
|
| 102 |
read_page_btn = gr.Button("🔊 Read This Page", variant="primary")
|
| 103 |
|
| 104 |
comic_text = gr.Textbox(label="Original", lines=3)
|
|
|
|
| 141 |
outputs=[comic_text, comic_tamil, comic_audio]
|
| 142 |
)
|
| 143 |
|
| 144 |
+
# --- Auto-Play Logic ---
|
| 145 |
+
def handle_auto_play(is_enabled, pdf, page, voice):
|
| 146 |
+
if not is_enabled or not pdf:
|
| 147 |
+
return gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update()
|
| 148 |
+
|
| 149 |
+
# 1. Go to next page
|
| 150 |
+
new_page = page + 1
|
| 151 |
+
img, status, p_num = load_comic_page(pdf, new_page)
|
| 152 |
+
|
| 153 |
+
if not img: # End of book
|
| 154 |
+
return gr.update(), status, p_num, gr.update(), gr.update(), gr.update()
|
| 155 |
+
|
| 156 |
+
# 2. Process the new page
|
| 157 |
+
txt, tam, aud = process_comic_page(img, voice)
|
| 158 |
+
return img, status, p_num, txt, tam, aud
|
| 159 |
+
|
| 160 |
+
# When audio ends, if auto_play is on, trigger next page
|
| 161 |
+
comic_audio.end(
|
| 162 |
+
handle_auto_play,
|
| 163 |
+
inputs=[auto_play, comic_pdf_path, current_page, voice_style_comic],
|
| 164 |
+
outputs=[comic_display, page_status, current_page, comic_text, comic_tamil, comic_audio]
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
# Standard Logic (Text Only)
|
| 168 |
submit_std.click(
|
| 169 |
process_standard_pipeline,
|