Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,21 +1,21 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from langchain_community.document_loaders import YoutubeLoader
|
| 3 |
-
from langchain.chains.summarize import load_summarize_chain
|
| 4 |
from langchain_core.prompts import ChatPromptTemplate
|
| 5 |
from youtube_transcript_api import NoTranscriptFound
|
|
|
|
| 6 |
|
| 7 |
def load_youtube_video_info(url):
|
| 8 |
# Initialize YouTube loader with preferred language as Portuguese
|
| 9 |
-
loader = YoutubeLoader.from_youtube_url(url, add_video_info=True, language="pt")
|
| 10 |
-
|
| 11 |
try:
|
|
|
|
|
|
|
| 12 |
# Load the video information and transcript
|
| 13 |
result = loader.load()
|
| 14 |
|
| 15 |
if result:
|
| 16 |
# Retrieve metadata information
|
| 17 |
-
author = result[0].metadata
|
| 18 |
-
length = result[0].metadata
|
| 19 |
# Check if transcript is available
|
| 20 |
transcript = result[0].page_content if hasattr(result[0], 'page_content') else "No transcript available."
|
| 21 |
|
|
@@ -25,6 +25,10 @@ def load_youtube_video_info(url):
|
|
| 25 |
info = "No result found."
|
| 26 |
except NoTranscriptFound:
|
| 27 |
info = "Transcript not found for this video."
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
return info
|
| 30 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from langchain_community.document_loaders import YoutubeLoader
|
|
|
|
| 3 |
from langchain_core.prompts import ChatPromptTemplate
|
| 4 |
from youtube_transcript_api import NoTranscriptFound
|
| 5 |
+
from pytube.exceptions import PytubeError
|
| 6 |
|
| 7 |
def load_youtube_video_info(url):
|
| 8 |
# Initialize YouTube loader with preferred language as Portuguese
|
|
|
|
|
|
|
| 9 |
try:
|
| 10 |
+
loader = YoutubeLoader.from_youtube_url(url, add_video_info=True, language="pt")
|
| 11 |
+
|
| 12 |
# Load the video information and transcript
|
| 13 |
result = loader.load()
|
| 14 |
|
| 15 |
if result:
|
| 16 |
# Retrieve metadata information
|
| 17 |
+
author = result[0].metadata.get('author', 'Unknown Author')
|
| 18 |
+
length = result[0].metadata.get('length', 'Unknown Length')
|
| 19 |
# Check if transcript is available
|
| 20 |
transcript = result[0].page_content if hasattr(result[0], 'page_content') else "No transcript available."
|
| 21 |
|
|
|
|
| 25 |
info = "No result found."
|
| 26 |
except NoTranscriptFound:
|
| 27 |
info = "Transcript not found for this video."
|
| 28 |
+
except PytubeError as e:
|
| 29 |
+
info = f"Error loading video information: {str(e)}"
|
| 30 |
+
except Exception as e:
|
| 31 |
+
info = f"An unexpected error occurred: {str(e)}"
|
| 32 |
|
| 33 |
return info
|
| 34 |
|