Ofiroz91 commited on
Commit
7f10f20
ยท
verified ยท
1 Parent(s): b93e08b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -4
app.py CHANGED
@@ -16,10 +16,16 @@ def summarize_audio_or_video(file_path):
16
  else:
17
  audio_file = file_path
18
 
19
- # ืชืžืœื•ืœ ื”ืื•ื“ื™ื•
20
- transcript = transcriber(audio_file)["text"]
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="ื”ืขืœื” ืงื•ื‘ืฅ ืื•ื“ื™ื• ืื• ื•ื™ื“ืื• ืฉืœ ืžืจืฆื” ื•ืงื‘ืœ ืกื™ื›ื•ื ืงืฆืจ ืฉืœ ื”ืชื•ื›ืŸ."