wt002 commited on
Commit
1ced237
·
verified ·
1 Parent(s): 9c685c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -103,14 +103,16 @@ def python_execution(code: str) -> str:
103
  except Exception as e:
104
  return f"Error: {str(e)}"
105
 
 
106
  from langchain_core.tools import BaseTool
107
  from youtube_transcript_api import YouTubeTranscriptApi
108
 
109
  class VideoTranscriptionTool(BaseTool):
110
- name = "transcript_video"
111
- description = "Fetch text transcript from YouTube videos using URL or ID. Optionally include timestamps."
112
 
113
- def _run(self, url: str, include_timestamps: bool = False) -> str:
 
114
  video_id = None
115
  if "youtube.com/watch?v=" in url:
116
  video_id = url.split("v=")[1].split("&")[0]
@@ -118,7 +120,7 @@ class VideoTranscriptionTool(BaseTool):
118
  video_id = url.split("youtu.be/")[1].split("?")[0]
119
  elif len(url.strip()) == 11 and not ("http://" in url or "https://" in url):
120
  video_id = url.strip()
121
-
122
  if not video_id:
123
  return f"Invalid or unsupported YouTube URL/ID: {url}"
124
 
@@ -138,7 +140,7 @@ class VideoTranscriptionTool(BaseTool):
138
  return f"Error fetching transcript: {str(e)}"
139
 
140
  def _arun(self, *args, **kwargs):
141
- raise NotImplementedError("This tool does not support async yet.")
142
 
143
 
144
 
 
103
  except Exception as e:
104
  return f"Error: {str(e)}"
105
 
106
+ from typing import Optional
107
  from langchain_core.tools import BaseTool
108
  from youtube_transcript_api import YouTubeTranscriptApi
109
 
110
  class VideoTranscriptionTool(BaseTool):
111
+ name: str = "transcript_video"
112
+ description: str = "Fetch text transcript from YouTube videos using URL or ID. Optionally include timestamps."
113
 
114
+ def _run(self, url: str, include_timestamps: Optional[bool] = False) -> str:
115
+ # Extract video ID
116
  video_id = None
117
  if "youtube.com/watch?v=" in url:
118
  video_id = url.split("v=")[1].split("&")[0]
 
120
  video_id = url.split("youtu.be/")[1].split("?")[0]
121
  elif len(url.strip()) == 11 and not ("http://" in url or "https://" in url):
122
  video_id = url.strip()
123
+
124
  if not video_id:
125
  return f"Invalid or unsupported YouTube URL/ID: {url}"
126
 
 
140
  return f"Error fetching transcript: {str(e)}"
141
 
142
  def _arun(self, *args, **kwargs):
143
+ raise NotImplementedError("Async not supported for this tool.")
144
 
145
 
146