Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
-
from
|
|
|
|
|
|
|
| 2 |
import markdown
|
| 3 |
from pptx import Presentation
|
| 4 |
from pptx.util import Inches, Pt
|
|
@@ -41,53 +43,24 @@ def markdown_to_pptx(md_text):
|
|
| 41 |
prs.save(output)
|
| 42 |
return output.getvalue()
|
| 43 |
|
| 44 |
-
@ui.page('/')
|
| 45 |
def pdf_compressor():
|
| 46 |
-
|
| 47 |
-
md_text = ""
|
| 48 |
-
if input_method.value == "Upload Markdown File":
|
| 49 |
-
if not file_upload.value:
|
| 50 |
-
output_label.set_text("No file uploaded.")
|
| 51 |
-
output_label.props.remove('hide')
|
| 52 |
-
return
|
| 53 |
-
md_text = await file_upload.value[0].read()
|
| 54 |
-
md_text = md_text.decode('utf-8')
|
| 55 |
-
else:
|
| 56 |
-
md_text = text_area.value
|
| 57 |
-
if not md_text:
|
| 58 |
-
output_label.set_text("No markdown content provided.")
|
| 59 |
-
output_label.props.remove('hide')
|
| 60 |
-
return
|
| 61 |
-
|
| 62 |
-
pptx_output = markdown_to_pptx(md_text)
|
| 63 |
-
ui.download("output.pptx", content=pptx_output)
|
| 64 |
-
output_label.set_text("PPTX file generated and ready for download.")
|
| 65 |
-
output_label.props.remove('hide')
|
| 66 |
-
|
| 67 |
-
ui.label("Choose Input Method")
|
| 68 |
-
input_method = ui.radio(options=["Upload Markdown File", "Paste Markdown Text"]).props('inline')
|
| 69 |
-
file_upload = ui.upload(label="Upload Markdown File", on_upload=lambda e: None).props('hide')
|
| 70 |
-
text_area = ui.textarea("Paste Markdown Text", placeholder="Enter or paste your markdown text here").props('hide')
|
| 71 |
-
convert_button = ui.button("Convert to PPTX", on_click=convert_to_pptx).props('hide')
|
| 72 |
-
output_label = ui.label().props('hide')
|
| 73 |
-
|
| 74 |
-
def show_upload():
|
| 75 |
-
file_upload.props.remove('hide')
|
| 76 |
-
text_area.props('hide')
|
| 77 |
-
convert_button.props.remove('hide')
|
| 78 |
-
|
| 79 |
-
def show_textarea():
|
| 80 |
-
file_upload.props('hide')
|
| 81 |
-
text_area.props.remove('hide')
|
| 82 |
-
convert_button.props.remove('hide')
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
| 87 |
else:
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
-
|
|
|
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
|
|
|
| 1 |
+
from pywebio.input import file_upload, textarea, radio
|
| 2 |
+
from pywebio.output import put_file, put_text
|
| 3 |
+
from pywebio import start_server
|
| 4 |
import markdown
|
| 5 |
from pptx import Presentation
|
| 6 |
from pptx.util import Inches, Pt
|
|
|
|
| 43 |
prs.save(output)
|
| 44 |
return output.getvalue()
|
| 45 |
|
|
|
|
| 46 |
def pdf_compressor():
|
| 47 |
+
input_method = radio("Choose Input Method", options=['Upload Markdown File', 'Paste Markdown Text'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
+
if input_method == 'Upload Markdown File':
|
| 50 |
+
file = file_upload("Upload Markdown File", accept=".md")
|
| 51 |
+
if file:
|
| 52 |
+
md_text = file['content'].decode('utf-8')
|
| 53 |
else:
|
| 54 |
+
put_text("No file uploaded.")
|
| 55 |
+
return
|
| 56 |
+
else:
|
| 57 |
+
md_text = textarea("Paste Markdown Text", placeholder="Enter or paste your markdown text here", help_text="You can paste your markdown text here")
|
| 58 |
+
if not md_text:
|
| 59 |
+
put_text("No markdown content provided.")
|
| 60 |
+
return
|
| 61 |
|
| 62 |
+
pptx_output = markdown_to_pptx(md_text)
|
| 63 |
+
put_file('output.pptx', content=pptx_output)
|
| 64 |
|
| 65 |
+
if __name__ == '__main__':
|
| 66 |
+
start_server(pdf_compressor, host='0.0.0.0', port=7860, debug=True)
|