tbdavid2019 commited on
Commit
99788f4
·
1 Parent(s): 915c067

Add application file

Browse files
Files changed (1) hide show
  1. app.py +26 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from markitdown import MarkItDown
3
+ import os
4
+ import shutil
5
+ from uuid import uuid4
6
+
7
+ md = MarkItDown()
8
+
9
+ def convert_file_to_md(file):
10
+ try:
11
+ result = md.convert(file.name)
12
+ content = result.text_content
13
+ except Exception as e:
14
+ content = f"❌ 轉換失敗:{str(e)}"
15
+ return content
16
+
17
+ demo = gr.Interface(
18
+ fn=convert_file_to_md,
19
+ inputs=gr.File(label="上傳支援格式檔案(如 PDF、Word、Excel 等)"),
20
+ outputs=gr.Textbox(label="轉換後的 Markdown 結果", lines=25),
21
+ title="📄 MarkItDown 文件轉 Markdown 線上工具",
22
+ description="上傳你的檔案,我們將自動轉換為 Markdown 格式內容,支援 PDF、Word、Excel、PowerPoint、圖片、音訊等格式。",
23
+ allow_flagging="never" # ← 加這行就不會出現 Flag 按鈕了
24
+ )
25
+
26
+ demo.launch()