Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,36 +1,34 @@
|
|
1 |
import gradio as gr
|
2 |
import subprocess
|
3 |
-
import os
|
4 |
|
5 |
-
def
|
6 |
output_pdf = "/tmp/output.pdf"
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
|
21 |
-
|
22 |
if result.returncode != 0:
|
23 |
return f"エラー: {result.stderr.decode()}", None
|
24 |
|
25 |
-
return "
|
26 |
|
27 |
-
# Gradioインターフェース
|
28 |
demo = gr.Interface(
|
29 |
-
fn=
|
30 |
inputs=gr.File(file_types=[".pdf"]),
|
31 |
outputs=[gr.Text(), gr.File()],
|
32 |
-
title="PDF
|
33 |
-
description="PDF
|
34 |
)
|
35 |
|
36 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import subprocess
|
|
|
3 |
|
4 |
+
def rasterize_pdf(input_pdf):
|
5 |
output_pdf = "/tmp/output.pdf"
|
6 |
|
7 |
+
cmd = [
|
8 |
+
"gs",
|
9 |
+
"-o", output_pdf,
|
10 |
+
"-sDEVICE=pdfwrite",
|
11 |
+
"-dFILTERVECTOR",
|
12 |
+
"-dCompatibilityLevel=1.4",
|
13 |
+
"-dPDFSETTINGS=/screen",
|
14 |
+
"-dNOPAUSE",
|
15 |
+
"-dBATCH",
|
16 |
+
"-dQUIET",
|
17 |
+
input_pdf
|
18 |
+
]
|
19 |
|
20 |
+
result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
21 |
if result.returncode != 0:
|
22 |
return f"エラー: {result.stderr.decode()}", None
|
23 |
|
24 |
+
return "ラスタライズ完了", output_pdf
|
25 |
|
|
|
26 |
demo = gr.Interface(
|
27 |
+
fn=rasterize_pdf,
|
28 |
inputs=gr.File(file_types=[".pdf"]),
|
29 |
outputs=[gr.Text(), gr.File()],
|
30 |
+
title="PDFラスタライズ変換(Ghostscript)",
|
31 |
+
description="SVGベクターPDFをビットマップ化PDFに変換し、Audiveris用に軽量化します。"
|
32 |
)
|
33 |
|
34 |
demo.launch()
|