user
Add application file
4ad7e37
raw
history blame
1.19 kB
import gradio as gr
import subprocess
import os
def convert_markdown_to_ppt(markdown_file, template_file=None):
input_path = markdown_file.name
output_path = os.path.splitext(input_path)[0] + ".pptx"
command = f"pandoc {input_path} -o {output_path}"
if template_file is not None:
template_path = template_file.name
command += f" --reference-doc={template_path}"
subprocess.run(command, shell=True, check=True)
return output_path
# 設定範例檔案的路徑
examples = [
["example.md", None], # 僅上傳 Markdown 檔案
["example.md", "template.pptx"] # 同時上傳 Markdown 檔案和模板
]
# 設定 Gradio 介面,加入範例
iface = gr.Interface(
fn=convert_markdown_to_ppt,
inputs=[gr.File(label="Markdown File"), gr.File(label="PPT Template (Optional)")],
outputs="file",
examples=examples,
title="Markdown to PPT Converter",
description="上傳一個 Markdown 檔案,並選擇性地上傳 PPT 模板,將其轉換為 PPT 格式並下載。 Upload a Markdown file, and optionally upload a PPT template to convert it into PPT format and download."
)
# 啟動介面
iface.launch()