user commited on
Commit
a17f414
1 Parent(s): 44a437a

Remove PDF

Browse files
Files changed (2) hide show
  1. Dockerfile +0 -7
  2. main.py +6 -27
Dockerfile CHANGED
@@ -13,21 +13,14 @@ RUN apt-get update && \
13
  apt-get clean && \
14
  rm -rf /var/lib/apt/lists/*
15
 
16
- RUN apt-get install software-properties-common && \
17
- add-apt-repository ppa:rael-gc/rvm && \
18
- apt-get update && \
19
- apt-get install libssl1.0-dev
20
-
21
  # 安裝所需的 Python 套件
22
  RUN pip install --no-cache-dir gradio
23
- RUN pip install --no-cache-dir "aspose.slides"
24
 
25
  # 開放 Gradio 預設的埠
26
  EXPOSE 7860
27
 
28
  # 設置環境變數
29
  ENV GRADIO_SERVER_NAME="0.0.0.0"
30
- ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
31
 
32
  # 設置執行程式的命令
33
  CMD ["python", "main.py"]
 
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"]
main.py CHANGED
@@ -2,10 +2,8 @@ import gradio as gr
2
  import subprocess
3
  import os
4
  from datetime import datetime
5
- import aspose.slides as slides
6
- import aspose.pydrawing as drawing
7
 
8
- def convert_markdown_to_ppt_and_pdf(markdown_file, markdown_text, input_type, template_file=None):
9
  # 根據輸入類型處理 Markdown 檔案或字串
10
  if input_type == "Upload Markdown File":
11
  input_path = markdown_file.name
@@ -18,8 +16,6 @@ def convert_markdown_to_ppt_and_pdf(markdown_file, markdown_text, input_type, te
18
 
19
  # 定義輸出 PPTX 路徑
20
  output_pptx_path = "/tmp/" + os.path.split(input_path)[1].replace(".md", ".pptx")
21
- # 定義輸出 PDF 路徑
22
- output_pdf_path = "/tmp/" + os.path.split(input_path)[1].replace(".md", ".pdf")
23
 
24
  # 將 Markdown 轉換為 PPTX
25
  command_pptx = f"pandoc '{input_path}' -o '{output_pptx_path}'"
@@ -30,27 +26,11 @@ def convert_markdown_to_ppt_and_pdf(markdown_file, markdown_text, input_type, te
30
  try:
31
  subprocess.run(command_pptx, shell=True, check=True)
32
  except subprocess.CalledProcessError as e:
33
- return f"Error: Conversion to PPTX failed. Details: {e}", None
34
  except Exception as e:
35
- return f"Unexpected error occurred during PPTX conversion: {e}", None
36
 
37
- # 使用 LibreOffice 將 PPTX 轉換為 PDF
38
- # os.environ["HOME"] = "/tmp" # 設定 HOME 環境變量到可寫目錄
39
- # command_pdf = f"libreoffice --headless --convert-to pdf '{output_pptx_path}' --outdir /tmp"
40
-
41
- # try:
42
- # subprocess.run(command_pdf, shell=True, check=True)
43
- # except subprocess.CalledProcessError as e:
44
- # return output_pptx_path, f"Error: Conversion to PDF failed. Details: {e}"
45
- # except Exception as e:
46
- # return output_pptx_path, f"Unexpected error occurred during PDF conversion: {e}"
47
-
48
- with slides.Presentation(output_pptx_path) as presentation:
49
- presentation.save(output_pdf_path, slides.export.SaveFormat.PDF)
50
-
51
- output_pdf_path = "/tmp/" + output_pdf_path.split("/")[-1]
52
-
53
- return output_pptx_path, output_pdf_path
54
 
55
  def update_visibility(input_type):
56
  # 根據選擇顯示/隱藏相應的輸入框
@@ -80,12 +60,11 @@ with gr.Blocks() as iface:
80
 
81
  submit_button = gr.Button("Submit")
82
  output_pptx = gr.File(label="Download PPTX")
83
- output_pdf = gr.File(label="Download PDF")
84
 
85
  submit_button.click(
86
- convert_markdown_to_ppt_and_pdf,
87
  inputs=[markdown_file, markdown_text, input_type, template_file],
88
- outputs=[output_pptx, output_pdf]
89
  )
90
 
91
  gr.Examples(
 
2
  import subprocess
3
  import os
4
  from datetime import datetime
 
 
5
 
6
+ def convert_markdown_to_ppt(markdown_file, markdown_text, input_type, template_file=None):
7
  # 根據輸入類型處理 Markdown 檔案或字串
8
  if input_type == "Upload Markdown File":
9
  input_path = markdown_file.name
 
16
 
17
  # 定義輸出 PPTX 路徑
18
  output_pptx_path = "/tmp/" + os.path.split(input_path)[1].replace(".md", ".pptx")
 
 
19
 
20
  # 將 Markdown 轉換為 PPTX
21
  command_pptx = f"pandoc '{input_path}' -o '{output_pptx_path}'"
 
26
  try:
27
  subprocess.run(command_pptx, shell=True, check=True)
28
  except subprocess.CalledProcessError as e:
29
+ return f"Error: Conversion to PPTX failed. Details: {e}"
30
  except Exception as e:
31
+ return f"Unexpected error occurred during PPTX conversion: {e}"
32
 
33
+ return output_pptx_path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  def update_visibility(input_type):
36
  # 根據選擇顯示/隱藏相應的輸入框
 
60
 
61
  submit_button = gr.Button("Submit")
62
  output_pptx = gr.File(label="Download PPTX")
 
63
 
64
  submit_button.click(
65
+ convert_markdown_to_ppt,
66
  inputs=[markdown_file, markdown_text, input_type, template_file],
67
+ outputs=output_pptx
68
  )
69
 
70
  gr.Examples(