Spaces:
Running
Running
user
commited on
Commit
•
4ad7e37
1
Parent(s):
6ff5f47
Add application file
Browse files- Dockerfile +26 -0
- demo.webp +0 -0
- example.md +26 -0
- main.py +35 -0
- template.pptx +0 -0
Dockerfile
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# 使用 Python 基礎映像
|
2 |
+
FROM python:3.10-slim
|
3 |
+
|
4 |
+
# 設置工作目錄
|
5 |
+
WORKDIR /app
|
6 |
+
|
7 |
+
# 複製當前目錄下的檔案到容器中
|
8 |
+
COPY . /app
|
9 |
+
|
10 |
+
# 更新 apt 並安裝 Pandoc 和其他必要的套件
|
11 |
+
RUN apt-get update && \
|
12 |
+
apt-get install -y pandoc && \
|
13 |
+
apt-get clean && \
|
14 |
+
rm -rf /var/lib/apt/lists/*
|
15 |
+
|
16 |
+
# 安裝所需的 Python 套件
|
17 |
+
RUN pip install --no-cache-dir gradio
|
18 |
+
|
19 |
+
# 開放 Gradio 預設的埠
|
20 |
+
EXPOSE 7860
|
21 |
+
|
22 |
+
# 設置環境變數
|
23 |
+
ENV GRADIO_SERVER_NAME="0.0.0.0"
|
24 |
+
|
25 |
+
# 設置執行程式的命令
|
26 |
+
CMD ["python", "main.py"]
|
demo.webp
ADDED
example.md
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# My Presentation
|
2 |
+
|
3 |
+
## Demo Page
|
4 |
+
|
5 |
+
This is a sample Markdown document for testing conversion to PPT using Pandoc.
|
6 |
+
|
7 |
+
## Introduction
|
8 |
+
|
9 |
+
This document contains elements like headings, lists, and images.
|
10 |
+
|
11 |
+
## List Items
|
12 |
+
|
13 |
+
- 123
|
14 |
+
- 456
|
15 |
+
- 789
|
16 |
+
|
17 |
+
## List Items
|
18 |
+
|
19 |
+
1. 123
|
20 |
+
2. 456
|
21 |
+
3. 789
|
22 |
+
|
23 |
+
## Image Example
|
24 |
+
|
25 |
+
![Demo](demo.webp)
|
26 |
+
|
main.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import subprocess
|
3 |
+
import os
|
4 |
+
|
5 |
+
def convert_markdown_to_ppt(markdown_file, template_file=None):
|
6 |
+
input_path = markdown_file.name
|
7 |
+
output_path = os.path.splitext(input_path)[0] + ".pptx"
|
8 |
+
|
9 |
+
command = f"pandoc {input_path} -o {output_path}"
|
10 |
+
if template_file is not None:
|
11 |
+
template_path = template_file.name
|
12 |
+
command += f" --reference-doc={template_path}"
|
13 |
+
|
14 |
+
subprocess.run(command, shell=True, check=True)
|
15 |
+
|
16 |
+
return output_path
|
17 |
+
|
18 |
+
# 設定範例檔案的路徑
|
19 |
+
examples = [
|
20 |
+
["example.md", None], # 僅上傳 Markdown 檔案
|
21 |
+
["example.md", "template.pptx"] # 同時上傳 Markdown 檔案和模板
|
22 |
+
]
|
23 |
+
|
24 |
+
# 設定 Gradio 介面,加入範例
|
25 |
+
iface = gr.Interface(
|
26 |
+
fn=convert_markdown_to_ppt,
|
27 |
+
inputs=[gr.File(label="Markdown File"), gr.File(label="PPT Template (Optional)")],
|
28 |
+
outputs="file",
|
29 |
+
examples=examples,
|
30 |
+
title="Markdown to PPT Converter",
|
31 |
+
description="上傳一個 Markdown 檔案,並選擇性地上傳 PPT 模板,將其轉換為 PPT 格式並下載。 Upload a Markdown file, and optionally upload a PPT template to convert it into PPT format and download."
|
32 |
+
)
|
33 |
+
|
34 |
+
# 啟動介面
|
35 |
+
iface.launch()
|
template.pptx
ADDED
Binary file (32 kB). View file
|
|