File size: 1,291 Bytes
84c7e84
 
6c50ec3
84c7e84
d4ff6d7
84c7e84
 
091d5c2
 
84c7e84
6c50ec3
84c7e84
 
6c50ec3
84c7e84
 
 
 
 
 
 
 
 
 
 
 
 
091d5c2
b0de0a1
349329f
84c7e84
 
 
 
af8b264
84c7e84
1d49f0d
84c7e84
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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()