Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
@@ -1,75 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import os
|
3 |
-
from app.modules.preprocessing import transcribe_audio
|
4 |
-
from app.modules.summarizer import process_transcript_file, generate_meeting_minutes
|
5 |
-
from app.modules.exporter import export_meeting_minutes_to_docx, refine_meeting_minutes
|
6 |
-
from app import config
|
7 |
-
|
8 |
-
def process_audio_to_docx(audio_file: str, api_key_text: str) -> str:
|
9 |
-
"""
|
10 |
-
Nhận file audio và API key, chuyển đổi thành transcript, xử lý transcript để tạo MeetingMinutes,
|
11 |
-
refine MeetingMinutes và xuất ra file DOCX.
|
12 |
-
|
13 |
-
Args:
|
14 |
-
audio_file (str): Đường dẫn tới file audio được tải lên.
|
15 |
-
api_key_text (str): API Key dùng cho OpenAI.
|
16 |
-
|
17 |
-
Returns:
|
18 |
-
str: Đường dẫn file DOCX được tạo ra.
|
19 |
-
"""
|
20 |
-
if not audio_file:
|
21 |
-
raise ValueError("Không có file audio nào được tải lên.")
|
22 |
-
if not api_key_text:
|
23 |
-
raise ValueError("Vui lòng cung cấp OpenAI API Key.")
|
24 |
-
|
25 |
-
os.environ["OPENAI_API_KEY"] = api_key_text
|
26 |
-
|
27 |
-
temp_transcript = "temp_transcript.txt"
|
28 |
-
try:
|
29 |
-
# Bước 1: Chuyển đổi audio thành transcript
|
30 |
-
segments, info = transcribe_audio(
|
31 |
-
input_audio=audio_file,
|
32 |
-
model_size=config.WHISPER_MODEL_SIZE,
|
33 |
-
device=config.WHISPER_DEVICE,
|
34 |
-
compute_type=config.WHISPER_COMPUTE_TYPE,
|
35 |
-
beam_size=config.WHISPER_BEAM_SIZE,
|
36 |
-
vad_filter=config.WHISPER_USE_VAD
|
37 |
-
)
|
38 |
-
|
39 |
-
# Bước 2: Kết hợp transcript thành văn bản
|
40 |
-
transcript_text = "\n".join(seg['text'] for seg in segments)
|
41 |
-
with open(temp_transcript, "w", encoding="utf-8") as f:
|
42 |
-
f.write(transcript_text)
|
43 |
-
|
44 |
-
# Bước 3: Xử lý transcript thành MeetingMinutes
|
45 |
-
meeting_minutes = process_transcript_file(temp_transcript, chunk_size=10, chunk_overlap=2)
|
46 |
-
|
47 |
-
# Bước 4: Refine MeetingMinutes
|
48 |
-
refined_minutes = refine_meeting_minutes(meeting_minutes)
|
49 |
-
|
50 |
-
# Bước 5: Xuất ra DOCX
|
51 |
-
output_docx = "generated_meeting_minutes.docx"
|
52 |
-
export_meeting_minutes_to_docx(refined_minutes, output_docx)
|
53 |
-
|
54 |
-
return output_docx
|
55 |
-
|
56 |
-
except Exception as e:
|
57 |
-
raise Exception(f"Xảy ra lỗi: {str(e)}")
|
58 |
-
finally:
|
59 |
-
if os.path.exists(temp_transcript):
|
60 |
-
os.remove(temp_transcript)
|
61 |
-
|
62 |
-
# Giao diện Gradio cập nhật
|
63 |
-
iface = gr.Interface(
|
64 |
-
fn=process_audio_to_docx,
|
65 |
-
inputs=[
|
66 |
-
gr.Audio(type="filepath", label="Tải lên file audio"),
|
67 |
-
gr.Textbox(lines=1, placeholder="Nhập OpenAI API Key", label="OpenAI API Key", type="text")
|
68 |
-
],
|
69 |
-
outputs=gr.File(label="Tải xuống biên bản họp (.docx)"),
|
70 |
-
title="Meeting Minutes Generator",
|
71 |
-
description="Tải lên file audio và nhập OpenAI API Key để tạo biên bản cuộc họp (DOCX)."
|
72 |
-
)
|
73 |
-
|
74 |
-
if __name__ == "__main__":
|
75 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|