Corin1998 commited on
Commit
ff7d898
·
verified ·
1 Parent(s): 43c0148

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -38
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
- summarize_model: str,
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
- theme_rab = safe_hex_to_rgb(theme_hex or "#3B82F6")
24
 
25
  # Read logo (optional)
26
  logo_bytes = None
27
  if logo_file is not None:
28
- logo_bytes = logo_file.read()
29
-
30
- # Step 1-3: NLP pipeline(summary, sections, bullets, tables , chart data)
31
- results = process_text(
 
 
 
 
 
 
 
32
  text=long_text,
33
  use_inference_api=use_inference_api,
34
- summarize_model=summarize_model,
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("%Y%m%d-%H%M%S")
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=theme_rab,
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.ColorPicker(label="テーマカラー", value="#3B82F6")
70
- logo = gr.File(label="ロゴ画像(任意)")
71
  with gr.Row():
72
- add_summary = gr.Checkbox(label="要約スライドを追加", value=True)
73
- add_tables = gr.Checkbox(label="表を検出して追加", value=True)
74
- add_charts = gr.Checkbox(label="チャートを生成して追加", value=True)
75
  with gr.Column(scale=1):
76
- use_inference_api = gr.Checkbox(label="Hugging Face Inference APIを使用", value=False)
77
- summarize_api = gr.Textbox(label="要約モデル名(local or API)", value="sshleifer/distilbart-cnn-12-6")
78
- generator_model = gr.Textbox(label="生成モデル(API推奨,任意)", value="")
79
- max_summary_words = gr.Slider(label="要約の最大単語数", 50, 600, value=200, step=10)
 
80
  generate = gr.Button("PPTXを生成", variant="primary")
81
  output_file = gr.File(label="ダウンロード")
82
-
83
  generate.click(
84
  fn=generate_pptx,
85
- inputs=[
86
- long_text, title, theme_hex, add_summary, add_charts,add_tables,
87
- use_inference_api, summarize_api, generator_model, max_summary_words, summarizer_model,
88
- ],
89
- outputs=output_file
90
  )
91
 
92
  gr.Markdown("""
93
  **Tips**
94
- - 日本語要約には`sonoisa/t5-base-japanese`を推奨('text2text-generation').
95
- - Inference API を使う場合は、 SpaceSecret に `HF_TOKEN` を設定してください。
96
- - チャートは'Label: 123' 形式の行を自動検出して棒グラフを作成します。
97
- """)
98
-
99
  return demo
100
 
 
101
  if __name__ == "__main__":
102
- app = ui()
103
- app.launch()
 
 
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 を使う場合は、SpaceSecrets に `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")))