Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,15 +3,10 @@ import subprocess
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
# Supported input and output formats for Calibre
|
| 6 |
-
input_formats = ["
|
| 7 |
output_formats = ["AZW3", "EPUB", "DOCX", "FB2", "HTMLZ", "OEB", "LIT", "LRF", "MOBI", "PDB", "PMLZ", "RB", "PDF", "RTF", "SNB", "TCR", "TXT", "TXTZ", "ZIP"]
|
| 8 |
|
| 9 |
def convert_ebook(input_file, output_format):
|
| 10 |
-
# Get file extension and validate it's a supported input format
|
| 11 |
-
input_extension = os.path.splitext(input_file.name)[1].replace('.', '').upper()
|
| 12 |
-
if input_extension not in input_formats:
|
| 13 |
-
return None, "Unsupported input format. Please upload a valid file."
|
| 14 |
-
|
| 15 |
output_file = os.path.splitext(input_file.name)[0] + "." + output_format.lower()
|
| 16 |
|
| 17 |
# Execute Calibre ebook-convert command
|
|
@@ -25,10 +20,10 @@ def convert_ebook(input_file, output_format):
|
|
| 25 |
return output_file, "Conversion successful! You can download your file below."
|
| 26 |
|
| 27 |
with gr.Blocks() as gui:
|
| 28 |
-
gr.Markdown("## Ebook Converter\nThis interface uses Calibre to convert ebooks. [Calibre GitHub](https://github.com/kovidgoyal/calibre) | [Calibre Website](https://calibre-ebook.com)")
|
| 29 |
|
| 30 |
-
# File upload
|
| 31 |
-
input_file = gr.File(label="Select Ebook File")
|
| 32 |
|
| 33 |
# Dropdown for output format
|
| 34 |
output_format = gr.Dropdown(choices=output_formats, label="Choose Output Format")
|
|
@@ -42,7 +37,7 @@ with gr.Blocks() as gui:
|
|
| 42 |
# Output file download
|
| 43 |
output_file = gr.File(label="Converted Ebook", interactive=False)
|
| 44 |
|
| 45 |
-
# Convert and display file for download or show
|
| 46 |
convert_button.click(fn=convert_ebook, inputs=[input_file, output_format], outputs=[output_file, status_message])
|
| 47 |
|
| 48 |
# Launch the Gradio GUI
|
|
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
# Supported input and output formats for Calibre
|
| 6 |
+
input_formats = ["azw", "azw3", "azw4", "cbz", "cbr", "cb7", "cbc", "chm", "djvu", "docx", "epub", "fb2", "fbz", "html", "htmlz", "lit", "lrf", "mobi", "odt", "pdf", "prc", "pdb", "pml", "rb", "rtf", "snb", "tcr", "txt", "txtz"]
|
| 7 |
output_formats = ["AZW3", "EPUB", "DOCX", "FB2", "HTMLZ", "OEB", "LIT", "LRF", "MOBI", "PDB", "PMLZ", "RB", "PDF", "RTF", "SNB", "TCR", "TXT", "TXTZ", "ZIP"]
|
| 8 |
|
| 9 |
def convert_ebook(input_file, output_format):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
output_file = os.path.splitext(input_file.name)[0] + "." + output_format.lower()
|
| 11 |
|
| 12 |
# Execute Calibre ebook-convert command
|
|
|
|
| 20 |
return output_file, "Conversion successful! You can download your file below."
|
| 21 |
|
| 22 |
with gr.Blocks() as gui:
|
| 23 |
+
gr.Markdown("## Ebook Converter\nThis interface uses Calibre to convert ebooks. Supported input formats: AZW, AZW3, AZW4, CBZ, CBR, CB7, CBC, CHM, DJVU, DOCX, EPUB, FB2, FBZ, HTML, HTMLZ, LIT, LRF, MOBI, ODT, PDF, PRC, PDB, PML, RB, RTF, SNB, TCR, TXT, TXTZ.\n\n[Calibre GitHub](https://github.com/kovidgoyal/calibre) | [Calibre Website](https://calibre-ebook.com)")
|
| 24 |
|
| 25 |
+
# File upload (only accepts valid input formats)
|
| 26 |
+
input_file = gr.File(label="Select Ebook File", file_types=input_formats)
|
| 27 |
|
| 28 |
# Dropdown for output format
|
| 29 |
output_format = gr.Dropdown(choices=output_formats, label="Choose Output Format")
|
|
|
|
| 37 |
# Output file download
|
| 38 |
output_file = gr.File(label="Converted Ebook", interactive=False)
|
| 39 |
|
| 40 |
+
# Convert and display file for download or show success message
|
| 41 |
convert_button.click(fn=convert_ebook, inputs=[input_file, output_format], outputs=[output_file, status_message])
|
| 42 |
|
| 43 |
# Launch the Gradio GUI
|