# app.py import gradio as gr import os from core import process_files def correct_subtitle(api_key, transcript_file, oral_file, batch_size): # 檔案上傳和讀取由 Gradio 處理,不再需要 files.upload() error, new_srt, all_reports = process_files(api_key, transcript_file.name, oral_file.name, batch_size) if error: return error, None, None else: corrected_file_name = "corrected_subtitle.srt" new_srt.save(corrected_file_name, encoding='utf-8') report_text = "\n".join(all_reports) report_file_name = "report.txt" with open(report_file_name, 'w', encoding='utf-8') as f: f.write(report_text) return "完成",corrected_file_name, report_file_name iface = gr.Interface( fn=correct_subtitle, inputs=[ gr.Textbox(lines=1, placeholder="請輸入您的 Google Gemini API 金鑰"), gr.File(label="請上傳逐字稿 (TXT 格式)"), gr.File(label="請上傳字幕稿 (SRT 格式)"), gr.Number(label="請輸入批次數量 (請輸入整數,建議為15~25)") ], outputs=[ gr.Textbox(label="狀態"), gr.File(label="修正後的字幕檔案"), gr.File(label="修改報告") ], title="Subtitle Fixer" ) iface.launch()