Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -16,10 +16,16 @@ def summarize_audio_or_video(file_path):
|
|
16 |
else:
|
17 |
audio_file = file_path
|
18 |
|
19 |
-
#
|
20 |
-
|
21 |
|
22 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
summary = summarizer(transcript, max_length=50, min_length=25, do_sample=False)[0]["summary_text"]
|
24 |
|
25 |
# ืืืืงืช ืงืืืฅ ืืืืืื ืืืืืช ืืฆืืจื (ืื ืืื ืืืืื)
|
@@ -38,10 +44,20 @@ def convert_video_to_audio(video_file):
|
|
38 |
video.export(temp_audio, format="wav")
|
39 |
return temp_audio
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
# ืืืืจืช ืืืฉืง Gradio
|
42 |
interface = gr.Interface(
|
43 |
fn=summarize_audio_or_video,
|
44 |
-
inputs=gr.Audio(type="filepath"),
|
45 |
outputs="text",
|
46 |
title="ืืืืจ ืืืืื/ืืืืื ืืกืืืื",
|
47 |
description="ืืขืื ืงืืืฅ ืืืืื ืื ืืืืื ืฉื ืืจืฆื ืืงืื ืกืืืื ืงืฆืจ ืฉื ืืชืืื."
|
|
|
16 |
else:
|
17 |
audio_file = file_path
|
18 |
|
19 |
+
# ืืืืงืช ืืืืืื ืืงืืขืื ืฉื 30 ืฉื ืืืช
|
20 |
+
segments = split_audio(audio_file)
|
21 |
|
22 |
+
# ืชืืืื ืื ืงืืข ืืืฆืืจืคืืช ืืชืืืื ืืกืืคื
|
23 |
+
transcript = ""
|
24 |
+
for segment in segments:
|
25 |
+
segment_text = transcriber(segment, return_timestamps=False)["text"]
|
26 |
+
transcript += " " + segment_text
|
27 |
+
|
28 |
+
# ืกืืืื ืืชืืืื
|
29 |
summary = summarizer(transcript, max_length=50, min_length=25, do_sample=False)[0]["summary_text"]
|
30 |
|
31 |
# ืืืืงืช ืงืืืฅ ืืืืืื ืืืืืช ืืฆืืจื (ืื ืืื ืืืืื)
|
|
|
44 |
video.export(temp_audio, format="wav")
|
45 |
return temp_audio
|
46 |
|
47 |
+
def split_audio(audio_file, segment_length=30 * 1000): # 30 ืฉื ืืืช ืืืืืืฉื ืืืช
|
48 |
+
audio = AudioSegment.from_file(audio_file)
|
49 |
+
segments = []
|
50 |
+
for i in range(0, len(audio), segment_length):
|
51 |
+
segment = audio[i:i + segment_length]
|
52 |
+
temp_segment = tempfile.mktemp(suffix=".wav")
|
53 |
+
segment.export(temp_segment, format="wav")
|
54 |
+
segments.append(temp_segment)
|
55 |
+
return segments
|
56 |
+
|
57 |
# ืืืืจืช ืืืฉืง Gradio
|
58 |
interface = gr.Interface(
|
59 |
fn=summarize_audio_or_video,
|
60 |
+
inputs=gr.Audio(type="filepath"),
|
61 |
outputs="text",
|
62 |
title="ืืืืจ ืืืืื/ืืืืื ืืกืืืื",
|
63 |
description="ืืขืื ืงืืืฅ ืืืืื ืื ืืืืื ืฉื ืืจืฆื ืืงืื ืกืืืื ืงืฆืจ ืฉื ืืชืืื."
|