FarhadMadadzade commited on
Commit
23c3af4
1 Parent(s): 4b85b27

trying to optimize

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -11,10 +11,16 @@ from pydub.silence import split_on_silence
11
  pipe = pipeline("automatic-speech-recognition", model="Artanis1551/whisper_romanian3")
12
 
13
 
14
- def process_video(date):
 
 
 
15
  # Download the video
16
  video_path = download_video(date)
17
 
 
 
 
18
  # Extract audio from the video
19
  audio_path = f"audio_{date}.wav"
20
  AudioFileClip(video_path).write_audiofile(audio_path)
@@ -32,11 +38,12 @@ def process_video(date):
32
  transcription += pipe(audio)["text"] + "\n "
33
  os.remove(f"chunk{i}.wav")
34
 
 
 
 
35
  # Remove the audio file
36
  os.remove(audio_path)
37
 
38
- return video_path, transcription
39
-
40
 
41
  iface = gr.Interface(
42
  fn=process_video,
@@ -45,6 +52,7 @@ iface = gr.Interface(
45
  gr.outputs.Video(),
46
  gr.Textbox(lines=1000, max_lines=1000, interactive=True),
47
  ],
 
48
  title="Romanian Transcription Test",
49
  )
50
 
 
11
  pipe = pipeline("automatic-speech-recognition", model="Artanis1551/whisper_romanian3")
12
 
13
 
14
+ def process_video(date, live):
15
+ # Parse the date to the format yyyymmdd
16
+ date = datetime.datetime.strptime(date, "%Y-%m-%d").strftime("%Y%m%d")
17
+
18
  # Download the video
19
  video_path = download_video(date)
20
 
21
+ # Send the video path to the live output
22
+ live.update(video_path)
23
+
24
  # Extract audio from the video
25
  audio_path = f"audio_{date}.wav"
26
  AudioFileClip(video_path).write_audiofile(audio_path)
 
38
  transcription += pipe(audio)["text"] + "\n "
39
  os.remove(f"chunk{i}.wav")
40
 
41
+ # Update the live output with the current transcription
42
+ live.update(video_path, transcription)
43
+
44
  # Remove the audio file
45
  os.remove(audio_path)
46
 
 
 
47
 
48
  iface = gr.Interface(
49
  fn=process_video,
 
52
  gr.outputs.Video(),
53
  gr.Textbox(lines=1000, max_lines=1000, interactive=True),
54
  ],
55
+ live=True,
56
  title="Romanian Transcription Test",
57
  )
58