Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import io
|
| 3 |
import time
|
| 4 |
import gradio as gr
|
| 5 |
from modules.text_processing import process_text
|
|
@@ -8,30 +8,40 @@ from modules.utils import safe_hex_to_rgb, ensure_tmpdir
|
|
| 8 |
|
| 9 |
APP_NAME = "Auto-PPT Generator"
|
| 10 |
|
|
|
|
| 11 |
def generate_pptx(long_text: str,
|
| 12 |
title: str,
|
| 13 |
theme_hex: str,
|
|
|
|
| 14 |
add_summary: bool,
|
|
|
|
| 15 |
add_charts: bool,
|
| 16 |
use_inference_api: bool,
|
| 17 |
-
|
| 18 |
generator_model: str,
|
| 19 |
-
max_summary_words: int
|
| 20 |
if not long_text or not long_text.strip():
|
| 21 |
raise gr.Error("入力テキストが空です。長文を貼り付けてください。")
|
| 22 |
-
|
| 23 |
-
|
| 24 |
|
| 25 |
# Read logo (optional)
|
| 26 |
logo_bytes = None
|
| 27 |
if logo_file is not None:
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
text=long_text,
|
| 33 |
use_inference_api=use_inference_api,
|
| 34 |
-
|
| 35 |
generator_model=generator_model,
|
| 36 |
want_summary=add_summary,
|
| 37 |
want_tables=add_tables,
|
|
@@ -41,13 +51,13 @@ def generate_pptx(long_text: str,
|
|
| 41 |
|
| 42 |
# Step 4: Build PPTX
|
| 43 |
ensure_tmpdir()
|
| 44 |
-
timestamp = time.strftime(
|
| 45 |
out_path = f"/tmp/auto_ppt_{timestamp}.pptx"
|
| 46 |
|
| 47 |
build_presentation(
|
| 48 |
output_path=out_path,
|
| 49 |
-
title=title or "Auto-PPT"
|
| 50 |
-
theme_rgb=
|
| 51 |
logo_bytes=logo_bytes,
|
| 52 |
executive_summary=result.get("summary"),
|
| 53 |
sections=result.get("sections", []),
|
|
@@ -59,45 +69,46 @@ def generate_pptx(long_text: str,
|
|
| 59 |
# Return file path for download
|
| 60 |
return out_path
|
| 61 |
|
|
|
|
| 62 |
def ui():
|
| 63 |
with gr.Blocks(title=APP_NAME) as demo:
|
| 64 |
-
gr.Markdown(f"# {APP_NAME}\n長文→要約→セクション分割→箇条書き/表/図→**PPTX
|
| 65 |
with gr.Row():
|
| 66 |
with gr.Column(scale=2):
|
| 67 |
-
long_text = gr.Textbox(label="長文テキスト(貼り付け)", lines=20, placeholder="
|
| 68 |
title = gr.Textbox(label="タイトル", value="自動生成スライド")
|
| 69 |
-
theme_hex = gr.
|
| 70 |
-
logo = gr.File(label="
|
| 71 |
with gr.Row():
|
| 72 |
-
add_summary = gr.Checkbox(label="要約スライドを追加"
|
| 73 |
-
add_tables = gr.Checkbox(label="
|
| 74 |
-
add_charts = gr.Checkbox(label="チャートを生成して追加"
|
| 75 |
with gr.Column(scale=1):
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
|
|
|
| 80 |
generate = gr.Button("PPTXを生成", variant="primary")
|
| 81 |
output_file = gr.File(label="ダウンロード")
|
| 82 |
-
|
| 83 |
generate.click(
|
| 84 |
fn=generate_pptx,
|
| 85 |
-
inputs=[
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
],
|
| 89 |
-
outputs=output_file
|
| 90 |
)
|
| 91 |
|
| 92 |
gr.Markdown("""
|
| 93 |
**Tips**
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
return demo
|
| 100 |
|
|
|
|
| 101 |
if __name__ == "__main__":
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import io
|
| 3 |
import time
|
| 4 |
import gradio as gr
|
| 5 |
from modules.text_processing import process_text
|
|
|
|
| 8 |
|
| 9 |
APP_NAME = "Auto-PPT Generator"
|
| 10 |
|
| 11 |
+
|
| 12 |
def generate_pptx(long_text: str,
|
| 13 |
title: str,
|
| 14 |
theme_hex: str,
|
| 15 |
+
logo_file,
|
| 16 |
add_summary: bool,
|
| 17 |
+
add_tables: bool,
|
| 18 |
add_charts: bool,
|
| 19 |
use_inference_api: bool,
|
| 20 |
+
summarizer_model: str,
|
| 21 |
generator_model: str,
|
| 22 |
+
max_summary_words: int):
|
| 23 |
if not long_text or not long_text.strip():
|
| 24 |
raise gr.Error("入力テキストが空です。長文を貼り付けてください。")
|
| 25 |
+
|
| 26 |
+
theme_rgb = safe_hex_to_rgb(theme_hex or "#3B82F6")
|
| 27 |
|
| 28 |
# Read logo (optional)
|
| 29 |
logo_bytes = None
|
| 30 |
if logo_file is not None:
|
| 31 |
+
try:
|
| 32 |
+
if hasattr(logo_file, "read"):
|
| 33 |
+
logo_bytes = logo_file.read()
|
| 34 |
+
elif hasattr(logo_file, "name") and logo_file.name:
|
| 35 |
+
with open(logo_file.name, "rb") as f:
|
| 36 |
+
logo_bytes = f.read()
|
| 37 |
+
except Exception:
|
| 38 |
+
logo_bytes = None
|
| 39 |
+
|
| 40 |
+
# Step 1–3: NLP pipeline (summary, sections, bullets, tables, chart data)
|
| 41 |
+
result = process_text(
|
| 42 |
text=long_text,
|
| 43 |
use_inference_api=use_inference_api,
|
| 44 |
+
summarizer_model=summarizer_model,
|
| 45 |
generator_model=generator_model,
|
| 46 |
want_summary=add_summary,
|
| 47 |
want_tables=add_tables,
|
|
|
|
| 51 |
|
| 52 |
# Step 4: Build PPTX
|
| 53 |
ensure_tmpdir()
|
| 54 |
+
timestamp = time.strftime('%Y%m%d-%H%M%S')
|
| 55 |
out_path = f"/tmp/auto_ppt_{timestamp}.pptx"
|
| 56 |
|
| 57 |
build_presentation(
|
| 58 |
output_path=out_path,
|
| 59 |
+
title=(title or "Auto-PPT"),
|
| 60 |
+
theme_rgb=theme_rgb,
|
| 61 |
logo_bytes=logo_bytes,
|
| 62 |
executive_summary=result.get("summary"),
|
| 63 |
sections=result.get("sections", []),
|
|
|
|
| 69 |
# Return file path for download
|
| 70 |
return out_path
|
| 71 |
|
| 72 |
+
|
| 73 |
def ui():
|
| 74 |
with gr.Blocks(title=APP_NAME) as demo:
|
| 75 |
+
gr.Markdown(f"# {APP_NAME}\n長文→要約→セクション分割→箇条書き/表/図→**PPTX出力** まで自動化")
|
| 76 |
with gr.Row():
|
| 77 |
with gr.Column(scale=2):
|
| 78 |
+
long_text = gr.Textbox(label="長文テキスト (貼り付け)", lines=20, placeholder="ここに文章を貼り付け…")
|
| 79 |
title = gr.Textbox(label="タイトル", value="自動生成スライド")
|
| 80 |
+
theme_hex = gr.Textbox(label="ブランドカラー HEX", value="#3465A4")
|
| 81 |
+
logo = gr.File(label="ロゴ (任意, PNG/JPG)")
|
| 82 |
with gr.Row():
|
| 83 |
+
add_summary = gr.Checkbox(value=True, label="要約スライドを追加")
|
| 84 |
+
add_tables = gr.Checkbox(value=True, label="表を抽出して追加")
|
| 85 |
+
add_charts = gr.Checkbox(value=True, label="チャートを生成して追加")
|
| 86 |
with gr.Column(scale=1):
|
| 87 |
+
gr.Markdown("### モデル設定")
|
| 88 |
+
use_inference_api = gr.Checkbox(value=False, label="Hugging Face Inference API を使用")
|
| 89 |
+
summarizer_model = gr.Textbox(label="要約モデル (local or API)", value="sshleifer/distilbart-cnn-12-6")
|
| 90 |
+
generator_model = gr.Textbox(label="生成モデル (API推奨, 任意)", value="")
|
| 91 |
+
max_summary_words = gr.Slider(50, 600, value=200, step=10, label="要約の最大語数(目安)")
|
| 92 |
generate = gr.Button("PPTXを生成", variant="primary")
|
| 93 |
output_file = gr.File(label="ダウンロード")
|
| 94 |
+
|
| 95 |
generate.click(
|
| 96 |
fn=generate_pptx,
|
| 97 |
+
inputs=[long_text, title, theme_hex, logo, add_summary, add_tables, add_charts,
|
| 98 |
+
use_inference_api, summarizer_model, generator_model, max_summary_words],
|
| 99 |
+
outputs=[output_file],
|
|
|
|
|
|
|
| 100 |
)
|
| 101 |
|
| 102 |
gr.Markdown("""
|
| 103 |
**Tips**
|
| 104 |
+
- 日本語要約には `sonoisa/t5-base-japanese` を推奨(`text2text-generation`)。
|
| 105 |
+
- Inference API を使う場合は、Space の Secrets に `HF_TOKEN` を設定してください。
|
| 106 |
+
- チャートは `Label: 123` 形式の行を自動検出して棒グラフを作成します。
|
| 107 |
+
""")
|
|
|
|
| 108 |
return demo
|
| 109 |
|
| 110 |
+
|
| 111 |
if __name__ == "__main__":
|
| 112 |
+
demo = ui()
|
| 113 |
+
# Spaces は自動でバインドされますが、ローカル互換のため指定可能
|
| 114 |
+
demo.queue().launch(server_name="0.0.0.0", server_port=int(os.getenv("PORT", "7860")))
|