Spaces:
Configuration error
Configuration error
| from langchain_core.tools import BaseTool | |
| from video_question_answer import VideoQuestionAnswer | |
| from pydantic import BaseModel, Field | |
| from typing import Type | |
| import os | |
| from youtube_video_downloader import YoutubeVideoDownloader | |
| class YoutubeVideoQuestionAnswerToolArgs(BaseModel): | |
| url: str = Field(description="The url of the youtube video") | |
| question: str = Field(description="The question to answer") | |
| class YoutubeVideoQuestionAnswerTool(BaseTool): | |
| name: str = "youtube_video_question_answer" | |
| description: str = "Answer the question based on the youtube video." | |
| args_schema: Type[BaseModel] = YoutubeVideoQuestionAnswerToolArgs | |
| def _run(self, url: str, question: str) -> str: | |
| if url is None: | |
| return "Error: Video not found." | |
| # Answer the question | |
| answer = VideoQuestionAnswer().answer(url, question) | |
| return answer | |
| '''def _run(self, url: str, question: str) -> str: | |
| if url is None: | |
| return "Error: Video not found." | |
| # Download the video | |
| video_path = YoutubeVideoDownloader().download_video(url) | |
| # Answer the question | |
| answer = VideoQuestionAnswer().answer(video_path, question) | |
| # Delete the video | |
| os.remove(video_path) | |
| return answer''' |