Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -144,52 +144,35 @@ else:
|
|
144 |
|
145 |
|
146 |
##########################
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
# Try getting auto-generated transcript
|
180 |
-
transcript_list = YouTubeTranscriptApi.get_transcript(video_id, languages=['en-US', 'en'])
|
181 |
-
transcript = ' '.join([t['text'] for t in transcript_list])
|
182 |
-
except Exception as e:
|
183 |
-
print(f"Transcript error: {str(e)}")
|
184 |
-
# If both fail, return error message
|
185 |
-
return None, "No transcript available for this video. Please try a video with captions enabled."
|
186 |
-
|
187 |
-
return title, transcript
|
188 |
-
|
189 |
-
except Exception as e:
|
190 |
-
if attempt == max_retries - 1:
|
191 |
-
return None, f"Failed to fetch video information after {max_retries} attempts. Error: {str(e)}"
|
192 |
-
time.sleep(1) # Wait before retrying
|
193 |
-
# Launch the interface
|
194 |
-
if __name__ == "__main__":
|
195 |
-
interface.launch()
|
|
|
144 |
|
145 |
|
146 |
##########################
|
147 |
+
from pytube import YouTube
|
148 |
+
|
149 |
+
# Replace with your YouTube video URL
|
150 |
+
video_url = "https://www.youtube.com/watch?v=YOUR_VIDEO_ID"
|
151 |
+
|
152 |
+
# Download audio
|
153 |
+
yt = YouTube(video_url)
|
154 |
+
stream = yt.streams.filter(only_audio=True).first()
|
155 |
+
stream.download(filename="audio.mp4")
|
156 |
+
|
157 |
+
from transformers import pipeline
|
158 |
+
|
159 |
+
# Load the speech-to-text pipeline
|
160 |
+
transcriber = pipeline(model="openai/whisper-large", task="automatic-speech-recognition")
|
161 |
+
|
162 |
+
# Transcribe the audio file
|
163 |
+
result = transcriber("audio.mp4")
|
164 |
+
print(result['text'])
|
165 |
+
|
166 |
+
import gradio as gr
|
167 |
+
|
168 |
+
# Define a function for Gradio interface
|
169 |
+
def transcribe_audio(audio):
|
170 |
+
result = transcriber(audio.name)
|
171 |
+
return result['text']
|
172 |
+
|
173 |
+
# Create a Gradio interface
|
174 |
+
interface = gr.Interface(fn=transcribe_audio, inputs=gr.Audio(), outputs="text")
|
175 |
+
|
176 |
+
# Launch the Gradio interface
|
177 |
+
interface.launch()
|
178 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|