Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -21,14 +21,14 @@ async def create_youtube_transcription(youtube_url: str) -> List[langchain_core.
|
|
21 |
"""
|
22 |
try:
|
23 |
loader = YoutubeLoader.from_youtube_url(
|
24 |
-
youtube_url, add_video_info=
|
25 |
) # we can also pass an array of youtube urls to load multiple videos at once!
|
26 |
youtube_docs = loader.load() # this loads the transcript
|
27 |
return youtube_docs
|
28 |
except Exception as e:
|
29 |
-
await cl.Message(content=f"failed to load youtube video: {e}").send() # display the error if we failed to load the youtube video
|
30 |
|
31 |
-
def create_text_splitter(docs: List[langchain_core.documents.Document]):
|
32 |
"""
|
33 |
Create a text splitter from a list of documents
|
34 |
More Info: ument_transformers/recursive_text_splitter/
|
@@ -102,13 +102,13 @@ async def start():
|
|
102 |
# more on ask user message: https://docs.chainlit.io/api-reference/ask/ask-for-input
|
103 |
await cl.Message(content=f"youtube link: {youtube_link}").send() # display and double check to make sure the link is correct
|
104 |
youtube_docs = await create_youtube_transcription(youtube_link['content']) # create the youtube transcription
|
|
|
|
|
105 |
split_docs = create_text_splitter(youtube_docs) # split the documents into chunks
|
106 |
vector_db = create_faiss_vector_store(split_docs) # create the vector db
|
107 |
bm25 = create_bm25_retreiver(split_docs) # create the BM25 retreiver
|
108 |
ensemble_retriever = await create_ensemble_retriever(vector_db, bm25) # create the ensemble retriever
|
109 |
cl.user_session.set("ensemble_retriever", ensemble_retriever) # store the ensemble retriever in the user session for our on message function
|
110 |
-
transcription = youtube_docs[0].page_content # get the transcription of the first document
|
111 |
-
await cl.Message(content=f"youtube docs: {transcription}").send() # display the transcription of the first document to show that we have the correct data
|
112 |
except Exception as e:
|
113 |
await cl.Message(content=f"failed to load model: {e}").send() # display the error if we failed to load the model
|
114 |
|
|
|
21 |
"""
|
22 |
try:
|
23 |
loader = YoutubeLoader.from_youtube_url(
|
24 |
+
youtube_url, add_video_info=False
|
25 |
) # we can also pass an array of youtube urls to load multiple videos at once!
|
26 |
youtube_docs = loader.load() # this loads the transcript
|
27 |
return youtube_docs
|
28 |
except Exception as e:
|
29 |
+
await cl.Message(content=f"failed to load youtube video: {e} Please refresh the page").send() # display the error if we failed to load the youtube video
|
30 |
|
31 |
+
async def create_text_splitter(docs: List[langchain_core.documents.Document]):
|
32 |
"""
|
33 |
Create a text splitter from a list of documents
|
34 |
More Info: ument_transformers/recursive_text_splitter/
|
|
|
102 |
# more on ask user message: https://docs.chainlit.io/api-reference/ask/ask-for-input
|
103 |
await cl.Message(content=f"youtube link: {youtube_link}").send() # display and double check to make sure the link is correct
|
104 |
youtube_docs = await create_youtube_transcription(youtube_link['content']) # create the youtube transcription
|
105 |
+
transcription = youtube_docs[0].page_content # get the transcription of the first document
|
106 |
+
await cl.Message(content=f"youtube docs: {transcription}").send() # display the transcription of the first document to show that we have the correct data
|
107 |
split_docs = create_text_splitter(youtube_docs) # split the documents into chunks
|
108 |
vector_db = create_faiss_vector_store(split_docs) # create the vector db
|
109 |
bm25 = create_bm25_retreiver(split_docs) # create the BM25 retreiver
|
110 |
ensemble_retriever = await create_ensemble_retriever(vector_db, bm25) # create the ensemble retriever
|
111 |
cl.user_session.set("ensemble_retriever", ensemble_retriever) # store the ensemble retriever in the user session for our on message function
|
|
|
|
|
112 |
except Exception as e:
|
113 |
await cl.Message(content=f"failed to load model: {e}").send() # display the error if we failed to load the model
|
114 |
|