Jimmy0866 commited on
Commit
f2628b8
·
verified ·
1 Parent(s): a9455b1

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -44
app.py DELETED
@@ -1,44 +0,0 @@
1
- import gradio as gr
2
- from summarize import summarize_text
3
- from pdf2text import process_pdf
4
- from aggregate import aggregate_summaries
5
- import logging
6
- import os
7
- from pathlib import Path
8
-
9
- logging.basicConfig(level=logging.INFO)
10
- logger = logging.getLogger(__name__)
11
-
12
- examples_dir = Path("examples")
13
- name_to_path = {f.name: f for f in examples_dir.glob("*.txt") if f.is_file()}
14
- logger.info(f"Loaded {len(name_to_path)} examples")
15
- default_example = next(iter(name_to_path), None)
16
-
17
- with gr.Blocks() as demo:
18
- gr.Markdown("## 文件摘要工具 - 輸入純文字或上傳 PDF")
19
- with gr.Row():
20
- input_textbox = gr.Textbox(label="輸入文件內容", lines=20)
21
- output_textbox = gr.Textbox(label="摘要結果", lines=10)
22
- summarize_button = gr.Button("產生摘要")
23
- upload_pdf = gr.File(label="或上傳 PDF 檔案", type="file")
24
- examples = gr.Examples(
25
- examples=[[name] for name in name_to_path.keys()],
26
- label="範例資料",
27
- inputs=[input_textbox],
28
- )
29
-
30
- def run_summarization(text, pdf_file):
31
- if pdf_file is not None:
32
- text = process_pdf(pdf_file.name)
33
- if text.strip() == "":
34
- return "請輸入文字或上傳有效的 PDF。"
35
- summary = summarize_text(text)
36
- return summary
37
-
38
- summarize_button.click(
39
- run_summarization,
40
- inputs=[input_textbox, upload_pdf],
41
- outputs=[output_textbox],
42
- )
43
-
44
- demo.launch()