Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,7 @@ from langchain.embeddings.huggingface import HuggingFaceEmbeddings
|
|
10 |
from langchain.callbacks.manager import CallbackManagerForLLMRun
|
11 |
from langchain.llms.base import LLM
|
12 |
from langchain.chains import RetrievalQA
|
|
|
13 |
import streamlit as st
|
14 |
from pytube import YouTube
|
15 |
|
@@ -126,6 +127,14 @@ initialize_session_state()
|
|
126 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
127 |
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-l6-v2")
|
128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
# Check if a new YouTube URL is provided
|
130 |
if st.session_state.youtube_url != st.session_state.doneYoutubeurl:
|
131 |
st.session_state.setup_done = False
|
@@ -143,7 +152,7 @@ if st.session_state.youtube_url and not st.session_state.setup_done:
|
|
143 |
retriever.search_kwargs['k'] = 4
|
144 |
with st.status("Running RetrievalQA..."):
|
145 |
llama_instance = LlamaLLM()
|
146 |
-
st.session_state.qa = RetrievalQA.from_chain_type(llm=llama_instance, chain_type="stuff", retriever=retriever)
|
147 |
|
148 |
st.session_state.doneYoutubeurl = st.session_state.youtube_url
|
149 |
st.session_state.setup_done = True # Mark the setup as done for this URL
|
|
|
10 |
from langchain.callbacks.manager import CallbackManagerForLLMRun
|
11 |
from langchain.llms.base import LLM
|
12 |
from langchain.chains import RetrievalQA
|
13 |
+
from langchain.prompts import PromptTemplate
|
14 |
import streamlit as st
|
15 |
from pytube import YouTube
|
16 |
|
|
|
127 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
128 |
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-l6-v2")
|
129 |
|
130 |
+
prompt = PromptTemplate(
|
131 |
+
template="""Given the context about a video. Answer the user in a friendly and precise manner.
|
132 |
+
Context: {context}
|
133 |
+
Human: {question}
|
134 |
+
AI:""",
|
135 |
+
input_variables=["context", "question"]
|
136 |
+
)
|
137 |
+
|
138 |
# Check if a new YouTube URL is provided
|
139 |
if st.session_state.youtube_url != st.session_state.doneYoutubeurl:
|
140 |
st.session_state.setup_done = False
|
|
|
152 |
retriever.search_kwargs['k'] = 4
|
153 |
with st.status("Running RetrievalQA..."):
|
154 |
llama_instance = LlamaLLM()
|
155 |
+
st.session_state.qa = RetrievalQA.from_chain_type(llm=llama_instance, chain_type="stuff", retriever=retriever,return_source_documents=True,chain_type_kwargs={"prompt": prompt})
|
156 |
|
157 |
st.session_state.doneYoutubeurl = st.session_state.youtube_url
|
158 |
st.session_state.setup_done = True # Mark the setup as done for this URL
|