Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -49,8 +49,8 @@ def transcribe_video(youtube_url: str, path: str) -> List[Document]:
|
|
49 |
return [Document(page_content=result[1], metadata=dict(page=1))]
|
50 |
|
51 |
|
52 |
-
def predict(message: str, system_prompt: str =
|
53 |
-
topp: float =
|
54 |
"""
|
55 |
Predict a response using a client.
|
56 |
"""
|
@@ -111,6 +111,12 @@ def sidebar():
|
|
111 |
embed_html,
|
112 |
unsafe_allow_html=True
|
113 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
|
116 |
|
@@ -118,6 +124,9 @@ def sidebar():
|
|
118 |
sidebar()
|
119 |
initialize_session_state()
|
120 |
|
|
|
|
|
|
|
121 |
# Check if a new YouTube URL is provided
|
122 |
if st.session_state.youtube_url != st.session_state.doneYoutubeurl:
|
123 |
st.session_state.setup_done = False
|
@@ -127,10 +136,8 @@ if st.session_state.youtube_url and not st.session_state.setup_done:
|
|
127 |
data = transcribe_video(st.session_state.youtube_url, PATH)
|
128 |
|
129 |
with st.status("Running Embeddings..."):
|
130 |
-
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
131 |
docs = text_splitter.split_documents(data)
|
132 |
|
133 |
-
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-l6-v2")
|
134 |
docsearch = FAISS.from_documents(docs, embeddings)
|
135 |
retriever = docsearch.as_retriever()
|
136 |
retriever.search_kwargs['distance_metric'] = 'cos'
|
@@ -138,8 +145,7 @@ if st.session_state.youtube_url and not st.session_state.setup_done:
|
|
138 |
with st.status("Running RetrievalQA..."):
|
139 |
llama_instance = LlamaLLM()
|
140 |
st.session_state.qa = RetrievalQA.from_chain_type(llm=llama_instance, chain_type="stuff", retriever=retriever)
|
141 |
-
|
142 |
-
|
143 |
st.session_state.doneYoutubeurl = st.session_state.youtube_url
|
144 |
st.session_state.setup_done = True # Mark the setup as done for this URL
|
145 |
|
|
|
49 |
return [Document(page_content=result[1], metadata=dict(page=1))]
|
50 |
|
51 |
|
52 |
+
def predict(message: str, system_prompt: str = system_promptSide, temperature: float = temperatureSide, max_new_tokens: int = max_new_tokensSide,
|
53 |
+
topp: float = ToppSide, repetition_penalty: float = RepetitionpenaltySide) -> Any:
|
54 |
"""
|
55 |
Predict a response using a client.
|
56 |
"""
|
|
|
111 |
embed_html,
|
112 |
unsafe_allow_html=True
|
113 |
)
|
114 |
+
|
115 |
+
system_promptSide = st.text_input("Optional system prompt:")
|
116 |
+
temperatureSide = st.slider("Temperature", min_value=0.0, max_value=1.0, value=0.9, step=0.05)
|
117 |
+
max_new_tokensSide = st.slider("Max new tokens", min_value=0.0, max_value=4096.0, value=4096.0, step=64.0)
|
118 |
+
ToppSide = st.slider("Top-p (nucleus sampling)", min_value=0.0, max_value=1.0, value=0.6, step=0.05)
|
119 |
+
RepetitionpenaltySide = st.slider("Repetition penalty", min_value=0.0, max_value=2.0, value=1.2, step=0.05)
|
120 |
|
121 |
|
122 |
|
|
|
124 |
sidebar()
|
125 |
initialize_session_state()
|
126 |
|
127 |
+
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
|
128 |
+
embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-l6-v2")
|
129 |
+
|
130 |
# Check if a new YouTube URL is provided
|
131 |
if st.session_state.youtube_url != st.session_state.doneYoutubeurl:
|
132 |
st.session_state.setup_done = False
|
|
|
136 |
data = transcribe_video(st.session_state.youtube_url, PATH)
|
137 |
|
138 |
with st.status("Running Embeddings..."):
|
|
|
139 |
docs = text_splitter.split_documents(data)
|
140 |
|
|
|
141 |
docsearch = FAISS.from_documents(docs, embeddings)
|
142 |
retriever = docsearch.as_retriever()
|
143 |
retriever.search_kwargs['distance_metric'] = 'cos'
|
|
|
145 |
with st.status("Running RetrievalQA..."):
|
146 |
llama_instance = LlamaLLM()
|
147 |
st.session_state.qa = RetrievalQA.from_chain_type(llm=llama_instance, chain_type="stuff", retriever=retriever)
|
148 |
+
|
|
|
149 |
st.session_state.doneYoutubeurl = st.session_state.youtube_url
|
150 |
st.session_state.setup_done = True # Mark the setup as done for this URL
|
151 |
|