Spaces:
Runtime error
Runtime error
Upload tool
Browse files- app.py +7 -0
- requirements.txt +2 -0
- tool.py +37 -0
app.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import launch_gradio_demo
|
| 2 |
+
from typing import Optional
|
| 3 |
+
from tool import YouTubeTranscriptExtractor
|
| 4 |
+
|
| 5 |
+
tool = YouTubeTranscriptExtractor()
|
| 6 |
+
|
| 7 |
+
launch_gradio_demo(tool)
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
smolagents
|
| 2 |
+
pytubefix
|
tool.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents.tools import Tool
|
| 2 |
+
import pytubefix
|
| 3 |
+
|
| 4 |
+
class YouTubeTranscriptExtractor(Tool):
|
| 5 |
+
description = "Extracts the transcript from a YouTube video."
|
| 6 |
+
name = "youtube_transcript_extractor"
|
| 7 |
+
inputs = {'video_url': {'type': 'string', 'description': 'The URL of the YouTube video.'}}
|
| 8 |
+
output_type = "string"
|
| 9 |
+
|
| 10 |
+
def forward(self, video_url: str) -> str:
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
from pytubefix import YouTube
|
| 14 |
+
# Create a YouTube object
|
| 15 |
+
yt = YouTube(video_url)
|
| 16 |
+
lang='en'
|
| 17 |
+
|
| 18 |
+
# Get the video transcript
|
| 19 |
+
if lang in yt.captions:
|
| 20 |
+
transcript = yt.captions['en'].generate_srt_captions()
|
| 21 |
+
|
| 22 |
+
else:
|
| 23 |
+
transcript = yt.captions.all()[0].generate_srt_captions()
|
| 24 |
+
lang=yt.captions.all()[0].code
|
| 25 |
+
|
| 26 |
+
return lang + "transcript : " + transcript
|
| 27 |
+
# return transcript
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
except Exception as e:
|
| 31 |
+
|
| 32 |
+
return f"An unexpected error occurred: {str(e)}"
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def __init__(self, *args, **kwargs):
|
| 36 |
+
self.is_initialized = False
|
| 37 |
+
|