filipzawadka commited on
Commit
e7244b3
1 Parent(s): 6ff007d
Files changed (3) hide show
  1. app.py +55 -20
  2. sejm_audio.mp3 +0 -0
  3. wget-log +0 -0
app.py CHANGED
@@ -1,13 +1,9 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
- import numpy as np
4
  import requests
5
  import subprocess
6
  import os
7
  import urllib.parse
8
- from moviepy.editor import *
9
- from ffmpy import FFmpeg
10
- import time
11
 
12
  term = 9
13
 
@@ -102,32 +98,71 @@ def extract_audio(video_path, audio_path):
102
  print("Audio extracted successfully.")
103
  else:
104
  print("Error extracting audio.")
105
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  # 600000,10000
107
 
108
  def transcribe(num1,num2):
109
 
 
 
110
  videos = get_sejm_videos(term)
111
  print(videos[0]['videoLink'])
112
 
113
- if download_video(offset_time(videos[0]['videoLink'],num1,num2), "./video.mov"):
114
- time.sleep(2)
115
- extract_audio("./video.mov", "./audio.mp3")
116
- # Load your MP4 file
117
 
118
- #ff = FFmpeg(
119
- # inputs={'./video.mp4': None},
120
- # outputs={'./audio.mp3': None}
121
- #)
122
- #ff.run()
123
- #video = VideoFileClip("./video.mp4")
124
 
125
- ## Extract the audio from the video
126
- #audio = video.audio
127
 
128
- ## Write the audio to an MP3 file
129
- #audio.write_audiofile("./audio.mp3")
130
- return transcriber("./audio.mp3")["text"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
 
132
 
133
  demo = gr.Interface(
 
1
  import gradio as gr
2
  from transformers import pipeline
 
3
  import requests
4
  import subprocess
5
  import os
6
  import urllib.parse
 
 
 
7
 
8
  term = 9
9
 
 
98
  print("Audio extracted successfully.")
99
  else:
100
  print("Error extracting audio.")
101
+
102
+ def download_and_extract_audio(video_link, start_time, end_time, audio_output):
103
+ video_path = "temp_video.mp4"
104
+
105
+ # Downloading video
106
+ response = requests.get(video_link)
107
+ if response.status_code == 200:
108
+ with open(video_path, 'wb') as file:
109
+ file.write(response.content)
110
+ else:
111
+ print(f"Error downloading video: {response.status_code}")
112
+ return
113
+
114
+ # Extracting audio
115
+ command = [
116
+ 'ffmpeg', '-i', video_path, '-ss', start_time, '-to', end_time,
117
+ '-q:a', '0', '-map', 'a', audio_output, '-y'
118
+ ]
119
+ subprocess.run(command)
120
+
121
+ # Clean up downloaded video
122
+ if os.path.exists(video_path):
123
+ os.remove(video_path)
124
+
125
+ if os.path.exists(audio_output):
126
+ print("Audio extracted successfully.")
127
+ else:
128
+ print("Error extracting audio.")
129
+
130
  # 600000,10000
131
 
132
  def transcribe(num1,num2):
133
 
134
+ num1,num2 = int(num1),int(num2)
135
+
136
  videos = get_sejm_videos(term)
137
  print(videos[0]['videoLink'])
138
 
139
+ start_time = "00:00:00" # Start time of the segment
140
+ end_time = "01:00:00" # End time of the segment
141
+ audio_output = "sejm_audio.mp3"
 
142
 
143
+ print(offset_time(videos[0]['videoLink'],num1,num2))
 
 
 
 
 
144
 
145
+ download_and_extract_audio(offset_time(videos[0]['videoLink'],num1,num2), start_time, end_time, audio_output)
 
146
 
147
+ return transcriber(audio_output)["text"]
148
+
149
+ # if download_video(offset_time(videos[0]['videoLink'],num1,num2), "./video.mov"):
150
+ # extract_audio("./video.mov", "./audio.mp3")
151
+ # # Load your MP4 file
152
+ #
153
+ # #ff = FFmpeg(
154
+ # # inputs={'./video.mp4': None},
155
+ # # outputs={'./audio.mp3': None}
156
+ # #)
157
+ # #ff.run()
158
+ # #video = VideoFileClip("./video.mp4")
159
+ #
160
+ # ## Extract the audio from the video
161
+ # #audio = video.audio
162
+ #
163
+ # ## Write the audio to an MP3 file
164
+ # #audio.write_audiofile("./audio.mp3")
165
+ # return transcriber(audio_output)["text"]
166
 
167
 
168
  demo = gr.Interface(
sejm_audio.mp3 ADDED
Binary file (238 kB). View file
 
wget-log CHANGED
The diff for this file is too large to render. See raw diff